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 = 271 
WHERE 
  cscart_products_categories.product_id IN (
    231, 232, 264, 265, 266, 267, 268, 269, 
    270, 318, 319, 320, 321, 322, 323, 3961, 
    3962, 3963, 3964, 3965, 3966, 3967, 
    4006, 4007, 4008, 4009, 4010, 4011, 
    4012, 4066, 4067, 4068, 4069, 4070, 
    4071, 4072, 4073, 4074, 4075, 4076, 
    4077, 4078, 4079, 4110, 4111, 4112, 
    4113, 4114, 4115, 4116, 4149, 4150, 
    4151, 4152, 4153, 4154, 4155, 4202, 
    4203, 4204, 4205, 4206, 4207, 4208, 
    3109, 3123, 6671, 6676, 6684, 5, 6, 7, 
    8, 9, 10, 11, 57, 58, 59, 60, 61, 62, 63, 
    111, 112, 113, 114, 115, 116, 117, 210, 
    211, 212, 213, 214, 215
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00251

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "68.39"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.55"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 40,
            "rows_produced_per_join": 1,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "4.54",
              "eval_cost": "0.16",
              "prefix_cost": "4.70",
              "data_read_per_join": "6K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`gaseus`.`cscart_categories`.`storefront_id` in (0,1)) and ((`gaseus`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`gaseus`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`gaseus`.`cscart_categories`.`usergroup_ids`))) and (`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": [
              "gaseus.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 110,
            "rows_produced_per_join": 1,
            "filtered": "0.88",
            "index_condition": "(`gaseus`.`cscart_products_categories`.`product_id` in (231,232,264,265,266,267,268,269,270,318,319,320,321,322,323,3961,3962,3963,3964,3965,3966,3967,4006,4007,4008,4009,4010,4011,4012,4066,4067,4068,4069,4070,4071,4072,4073,4074,4075,4076,4077,4078,4079,4110,4111,4112,4113,4114,4115,4116,4149,4150,4151,4152,4153,4154,4155,4202,4203,4204,4205,4206,4207,4208,3109,3123,6671,6676,6684,5,6,7,8,9,10,11,57,58,59,60,61,62,63,111,112,113,114,115,116,117,210,211,212,213,214,215))",
            "cost_info": {
              "read_cost": "44.00",
              "eval_cost": "0.15",
              "prefix_cost": "66.30",
              "data_read_per_join": "24"
            },
            "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",
              "gaseus.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 1,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "0.39",
              "eval_cost": "0.15",
              "prefix_cost": "66.84",
              "data_read_per_join": "24"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
5 273M
6 273M
7 273M
8 273M
9 273M
10 273M
11 273M
57 273M
58 273M
59 273M
60 273M
61 273M
62 273M
63 273M
111 273M
112 273M
113 273M
114 273M
115 273M
116 273M
117 273M
210 273M
211 273M
212 273M
213 273M
214 273M
215 273M
231 273M
232 273M
264 273M
265 273M
266 273M
267 273M
268 273M
269 273M
270 273M
318 273M
319 273M
320 273M
321 273M
322 273M
323 273M
3109 273M
3123 273M
3961 273M
3962 273M
3963 273M
3964 273M
3965 273M
3966 273M
3967 273M
4006 273M
4007 273M
4008 273M
4009 273M
4010 273M
4011 273M
4012 273M
4066 273M
4067 273M
4068 273M
4069 273M
4070 273M
4071 273M
4072 273M
4073 273M
4074 273M
4075 273M
4076 273M
4077 273M
4078 273M
4079 273M
4110 273M
4111 273M
4112 273M
4113 273M
4114 273M
4115 273M
4116 273M
4149 273M
4150 273M
4151 273M
4152 273M
4153 273M
4154 273M
4155 273M
4202 273M
4203 273M
4204 273M
4205 273M
4206 273M
4207 273M
4208 273M
6671 273M
6676 273M
6684 273M