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 (
    5623, 5624, 5625, 5626, 5627, 5628, 5629, 
    5630, 5631, 5632, 5633, 5634, 5635, 
    5636, 5637, 5638, 5639, 5640, 5641, 
    5642, 5643, 5644, 5645, 5646, 5647, 
    5648, 5649, 5650, 5651, 5652, 5653, 
    5654, 5655, 5656, 5657, 5658, 5659, 
    5660, 5661, 5662, 5663, 5664, 5665, 
    5666, 5667, 3137, 1473, 1474, 1475, 
    1476, 1477, 5182, 5183, 5184, 5185, 
    5186, 5187, 1461, 1462, 1463, 1464, 
    1465, 5170, 5171, 5172, 5173, 5174, 
    5175, 1878, 1879, 1880, 1881, 1882, 
    1883, 1884, 1885, 1886, 1887, 1888, 
    1889, 1890, 1891, 1892, 1893, 1894, 
    1895, 1896, 1897, 1898, 1899, 1900, 
    1901, 1902, 1903, 1904, 1905
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00354

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "61.36"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.91"
      },
      "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": 1,
            "filtered": "1.25",
            "index_condition": "(`test2_gaseus`.`cscart_products_categories`.`product_id` in (5623,5624,5625,5626,5627,5628,5629,5630,5631,5632,5633,5634,5635,5636,5637,5638,5639,5640,5641,5642,5643,5644,5645,5646,5647,5648,5649,5650,5651,5652,5653,5654,5655,5656,5657,5658,5659,5660,5661,5662,5663,5664,5665,5666,5667,3137,1473,1474,1475,1476,1477,5182,5183,5184,5185,5186,5187,1461,1462,1463,1464,1465,5170,5171,5172,5173,5174,5175,1878,1879,1880,1881,1882,1883,1884,1885,1886,1887,1888,1889,1890,1891,1892,1893,1894,1895,1896,1897,1898,1899,1900,1901,1902,1903,1904,1905))",
            "cost_info": {
              "read_cost": "38.18",
              "eval_cost": "0.19",
              "prefix_cost": "58.78",
              "data_read_per_join": "30"
            },
            "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": 1,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "0.48",
              "eval_cost": "0.19",
              "prefix_cost": "59.45",
              "data_read_per_join": "30"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
1461 308M
1462 308M
1463 308M
1464 308M
1465 308M
1473 308M
1474 308M
1475 308M
1476 308M
1477 308M
1878 308M
1879 308M
1880 308M
1881 308M
1882 308M
1883 308M
1884 308M
1885 308M
1886 308M
1887 308M
1888 308M
1889 308M
1890 308M
1891 308M
1892 308M
1893 308M
1894 308M
1895 308M
1896 308M
1897 308M
1898 308M
1899 308M
1900 308M
1901 308M
1902 308M
1903 308M
1904 308M
1905 308M
3137 308M
5170 308M
5171 308M
5172 308M
5173 308M
5174 308M
5175 308M
5182 308M
5183 308M
5184 308M
5185 308M
5186 308M
5187 308M
5623 308M
5624 308M
5625 308M
5626 308M
5627 308M
5628 308M
5629 308M
5630 308M
5631 308M
5632 308M
5633 308M
5634 308M
5635 308M
5636 308M
5637 308M
5638 308M
5639 308M
5640 308M
5641 308M
5642 308M
5643 308M
5644 308M
5645 308M
5646 308M
5647 308M
5648 308M
5649 308M
5650 308M
5651 308M
5652 308M
5653 308M
5654 308M
5655 308M
5656 308M
5657 308M
5658 308M
5659 308M
5660 308M
5661 308M
5662 308M
5663 308M
5664 308M
5665 308M
5666 308M
5667 308M