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 = 266 
WHERE 
  cscart_products_categories.product_id IN (
    3612, 3613, 3614, 3615, 4224, 4225, 4226, 
    4227, 4228, 4229, 4230, 5079, 5080, 
    5081, 5082, 5083, 5084, 5085, 5086, 
    5087, 5088, 5089, 5090, 5091, 5092, 
    5093, 5094, 5095, 5096, 5097, 5098, 
    5099, 5100, 5101, 5102, 5103, 5104, 
    5105, 5106, 2760, 2761, 2762, 2763, 
    2764, 6348, 6349, 6350, 6351, 2756, 
    2757, 2758, 2759, 6343, 6344, 6345, 
    6346, 6347, 2818, 2819, 2820, 2821, 
    2822, 6404, 6405, 6406, 6407, 2933, 
    2934, 2935, 2936, 6517, 6518, 6519, 
    6520, 6521, 2510, 2511, 2512, 2513, 
    3837, 3838, 3839, 6109, 6110, 2277, 
    2278, 2279, 2280, 2327, 2328, 2329, 
    2330, 2394, 2395, 2396, 2397
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00272

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "68.46"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.60"
      },
      "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.91",
            "index_condition": "(`gaseus`.`cscart_products_categories`.`product_id` in (3612,3613,3614,3615,4224,4225,4226,4227,4228,4229,4230,5079,5080,5081,5082,5083,5084,5085,5086,5087,5088,5089,5090,5091,5092,5093,5094,5095,5096,5097,5098,5099,5100,5101,5102,5103,5104,5105,5106,2760,2761,2762,2763,2764,6348,6349,6350,6351,2756,2757,2758,2759,6343,6344,6345,6346,6347,2818,2819,2820,2821,2822,6404,6405,6406,6407,2933,2934,2935,2936,6517,6518,6519,6520,6521,2510,2511,2512,2513,3837,3838,3839,6109,6110,2277,2278,2279,2280,2327,2328,2329,2330,2394,2395,2396,2397))",
            "cost_info": {
              "read_cost": "44.00",
              "eval_cost": "0.16",
              "prefix_cost": "66.30",
              "data_read_per_join": "25"
            },
            "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.40",
              "eval_cost": "0.16",
              "prefix_cost": "66.86",
              "data_read_per_join": "25"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
2277 308M
2278 308M
2279 308M
2280 308M
2327 308M
2328 308M
2329 308M
2330 308M
2394 308M
2395 308M
2396 308M
2397 308M
2510 308M
2511 308M
2512 308M
2513 308M
2756 308M
2757 308M
2758 308M
2759 308M
2760 308M
2761 308M
2762 308M
2763 308M
2764 308M
2818 308M
2819 308M
2820 308M
2821 308M
2822 308M
2933 308M
2934 308M
2935 308M
2936 308M
3612 273M
3613 273M
3614 273M
3615 273M
3837 308M
3838 308M
3839 308M
4224 273M
4225 273M
4226 273M
4227 273M
4228 273M
4229 273M
4230 273M
5079 273M
5080 273M
5081 273M
5082 273M
5083 273M
5084 273M
5085 273M
5086 273M
5087 273M
5088 273M
5089 273M
5090 273M
5091 273M
5092 273M
5093 273M
5094 273M
5095 273M
5096 273M
5097 273M
5098 273M
5099 273M
5100 273M
5101 273M
5102 273M
5103 273M
5104 273M
5105 273M
5106 273M
6109 308M
6110 308M
6343 308M
6344 308M
6345 308M
6346 308M
6347 308M
6348 308M
6349 308M
6350 308M
6351 308M
6404 308M
6405 308M
6406 308M
6407 308M
6517 308M
6518 308M
6519 308M
6520 308M
6521 308M