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 (
    5680, 5681, 5682, 5683, 5684, 5685, 5686, 
    5687, 5688, 5689, 5690, 5691, 5692, 
    5693, 5694, 5695, 5696, 5697, 5698, 
    5699, 5700, 5701, 5702, 5703, 5704, 
    5705, 5706, 5707, 5708, 5709, 5710, 
    5711, 5712, 5713, 5714, 5715, 5716, 
    5717, 5718, 5719, 5720, 5721, 1479, 
    1480, 1481, 1482, 1483, 5188, 5189, 
    5190, 5191, 5192, 5193, 1467, 1468, 
    1469, 1470, 1471, 5176, 5177, 5178, 
    5179, 5180, 5181, 447, 448, 449, 450, 
    451, 452, 453, 454, 455, 1932, 1933, 
    1934, 1935, 1936, 1937, 1938, 1939, 
    1940, 1941, 1942, 1943, 1944, 1945, 
    1946, 1947, 1948, 1949, 1950, 1951, 
    1952, 1953, 1954
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00304

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "68.50"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.63"
      },
      "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.93",
            "index_condition": "(`gaseus`.`cscart_products_categories`.`product_id` in (5680,5681,5682,5683,5684,5685,5686,5687,5688,5689,5690,5691,5692,5693,5694,5695,5696,5697,5698,5699,5700,5701,5702,5703,5704,5705,5706,5707,5708,5709,5710,5711,5712,5713,5714,5715,5716,5717,5718,5719,5720,5721,1479,1480,1481,1482,1483,5188,5189,5190,5191,5192,5193,1467,1468,1469,1470,1471,5176,5177,5178,5179,5180,5181,447,448,449,450,451,452,453,454,455,1932,1933,1934,1935,1936,1937,1938,1939,1940,1941,1942,1943,1944,1945,1946,1947,1948,1949,1950,1951,1952,1953,1954))",
            "cost_info": {
              "read_cost": "44.00",
              "eval_cost": "0.16",
              "prefix_cost": "66.30",
              "data_read_per_join": "26"
            },
            "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.41",
              "eval_cost": "0.16",
              "prefix_cost": "66.87",
              "data_read_per_join": "26"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
447 308M
448 308M
449 308M
450 308M
451 308M
452 308M
453 308M
454 308M
455 308M
1467 308M
1468 308M
1469 308M
1470 308M
1471 308M
1479 308M
1480 308M
1481 308M
1482 308M
1483 308M
1932 308M
1933 308M
1934 308M
1935 308M
1936 308M
1937 308M
1938 308M
1939 308M
1940 308M
1941 308M
1942 308M
1943 308M
1944 308M
1945 308M
1946 308M
1947 308M
1948 308M
1949 308M
1950 308M
1951 308M
1952 308M
1953 308M
1954 308M
5176 308M
5177 308M
5178 308M
5179 308M
5180 308M
5181 308M
5188 308M
5189 308M
5190 308M
5191 308M
5192 308M
5193 308M
5680 308M
5681 308M
5682 308M
5683 308M
5684 308M
5685 308M
5686 308M
5687 308M
5688 308M
5689 308M
5690 308M
5691 308M
5692 308M
5693 308M
5694 308M
5695 308M
5696 308M
5697 308M
5698 308M
5699 308M
5700 308M
5701 308M
5702 308M
5703 308M
5704 308M
5705 308M
5706 308M
5707 308M
5708 308M
5709 308M
5710 308M
5711 308M
5712 308M
5713 308M
5714 308M
5715 308M
5716 308M
5717 308M
5718 308M
5719 308M
5720 308M
5721 308M