SELECT 
  cscart_products_categories.product_id, 
  GROUP_CONCAT(
    IF(
      cscart_products_categories.link_type = "M", 
      CONCAT(
        cscart_products_categories.category_id, 
        "M"
      ), 
      cscart_products_categories.category_id
    )
  ) AS category_ids, 
  product_position_source.position AS position 
FROM 
  cscart_products_categories 
  INNER JOIN cscart_categories ON cscart_categories.category_id = cscart_products_categories.category_id 
  AND cscart_categories.storefront_id IN (0, 1) 
  AND (
    cscart_categories.usergroup_ids = '' 
    OR FIND_IN_SET(
      0, cscart_categories.usergroup_ids
    ) 
    OR FIND_IN_SET(
      1, cscart_categories.usergroup_ids
    )
  ) 
  AND cscart_categories.status IN ('A', 'H') 
  LEFT JOIN cscart_products_categories AS product_position_source ON cscart_products_categories.product_id = product_position_source.product_id 
  AND product_position_source.category_id = 267 
WHERE 
  cscart_products_categories.product_id IN (
    13176, 13162, 13169, 13232, 13225, 13190, 
    13183, 13239, 13204, 13197, 13246, 
    13218, 13211, 13253, 13302, 13303, 
    13308, 13309, 13306, 13307, 13310, 
    13311, 13312, 13313, 13304, 13305, 
    13319, 6962, 6966, 6967, 6965, 6963, 
    6952, 6953, 6947, 6959, 3425, 6958, 
    6960, 6968, 6961, 6964, 6957, 6956, 
    6954, 6955, 6948, 6950, 6949, 13298, 
    13299, 13300, 13301, 13124, 13125, 
    13126, 13098, 13105, 13112, 13118, 
    13064, 13071, 13078, 13085, 13091, 
    13314, 13316, 13315, 13317, 13318, 
    12956, 12958, 13014, 13028, 13040, 
    13052, 12960, 12974, 12988, 13000, 
    12926, 12942
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00341

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "62.42"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "2.69"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 46,
            "rows_produced_per_join": 1,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "5.15",
              "eval_cost": "0.18",
              "prefix_cost": "5.33",
              "data_read_per_join": "7K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`test2_gaseus`.`cscart_categories`.`storefront_id` in (0,1)) and ((`test2_gaseus`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`test2_gaseus`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`test2_gaseus`.`cscart_categories`.`usergroup_ids`))) and (`test2_gaseus`.`cscart_categories`.`status` in ('A','H')))"
          }
        },
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "test2_gaseus.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 83,
            "rows_produced_per_join": 2,
            "filtered": "1.76",
            "index_condition": "(`test2_gaseus`.`cscart_products_categories`.`product_id` in (13176,13162,13169,13232,13225,13190,13183,13239,13204,13197,13246,13218,13211,13253,13302,13303,13308,13309,13306,13307,13310,13311,13312,13313,13304,13305,13319,6962,6966,6967,6965,6963,6952,6953,6947,6959,3425,6958,6960,6968,6961,6964,6957,6956,6954,6955,6948,6950,6949,13298,13299,13300,13301,13124,13125,13126,13098,13105,13112,13118,13064,13071,13078,13085,13091,13314,13316,13315,13317,13318,12956,12958,13014,13028,13040,13052,12960,12974,12988,13000,12926,12942))",
            "cost_info": {
              "read_cost": "38.18",
              "eval_cost": "0.27",
              "prefix_cost": "58.78",
              "data_read_per_join": "43"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        },
        {
          "table": {
            "table_name": "product_position_source",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id",
              "product_id"
            ],
            "key_length": "6",
            "ref": [
              "const",
              "test2_gaseus.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 2,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "0.67",
              "eval_cost": "0.27",
              "prefix_cost": "59.73",
              "data_read_per_join": "43"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
3425 282,267,284M,312 0
6947 292M,282,267 0
6948 282,272M,267 0
6949 282,272M,267 0
6950 282,272M,267 0
6952 282,267,301M 0
6953 282,267,301M 0
6954 282,267,301M 0
6955 282,267,301M 0
6956 282,267,301M 0
6957 282,267,301M 0
6958 282,267,284M,312 0
6959 282,267,284M,312 0
6960 282,267,284M,312 0
6961 283,282M,267 0
6962 283,282M,267 0
6963 283,282M,267 0
6964 283,282M,267 0
6965 283,282M,267 0
6966 283,282M,267 0
6967 283,282M,267 0
6968 283M,282,267 0
12926 312M
12942 312M
12956 312M
12958 312M
12960 312M
12974 312M
12988 312M
13000 312M
13014 312M
13028 312M
13040 312M
13052 312M
13064 312M
13071 312M
13078 312M
13085 312M
13091 312M
13098 312M
13105 312M
13112 312M
13118 312M
13124 312M
13125 312M
13126 312M
13162 325M
13169 325M
13176 325M
13183 325M
13190 325M
13197 325M
13204 325M
13211 325M
13218 325M
13225 325M
13232 325M
13239 325M
13246 325M
13253 325M
13298 270M
13299 270M
13300 270M
13301 270M
13302 270M
13303 270M
13304 270M
13305 270M
13306 270M
13307 270M
13308 270M
13309 270M
13310 270M
13311 270M
13312 270M
13313 270M
13314 270M
13315 270M
13316 270M
13317 270M
13318 270M
13319 270M