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 (
    2022, 2023, 2024, 2025, 2026, 2027, 2028, 
    2029, 2030, 2031, 2032, 2033, 2034, 
    2035, 2036, 2037, 2038, 5668, 5669, 
    5670, 5671, 5672, 5673, 5674, 5675, 
    5676, 5677, 5678, 5679, 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
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00263

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "68.54"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.66"
      },
      "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.94",
            "index_condition": "(`gaseus`.`cscart_products_categories`.`product_id` in (2022,2023,2024,2025,2026,2027,2028,2029,2030,2031,2032,2033,2034,2035,2036,2037,2038,5668,5669,5670,5671,5672,5673,5674,5675,5676,5677,5678,5679,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))",
            "cost_info": {
              "read_cost": "44.00",
              "eval_cost": "0.17",
              "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.42",
              "eval_cost": "0.17",
              "prefix_cost": "66.88",
              "data_read_per_join": "26"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
447 308M
448 308M
449 308M
1467 308M
1468 308M
1469 308M
1470 308M
1471 308M
1479 308M
1480 308M
1481 308M
1482 308M
1483 308M
2022 308M
2023 308M
2024 308M
2025 308M
2026 308M
2027 308M
2028 308M
2029 308M
2030 308M
2031 308M
2032 308M
2033 308M
2034 308M
2035 308M
2036 308M
2037 308M
2038 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
5668 308M
5669 308M
5670 308M
5671 308M
5672 308M
5673 308M
5674 308M
5675 308M
5676 308M
5677 308M
5678 308M
5679 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