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 = 308 
WHERE 
  cscart_products_categories.product_id IN (
    1965, 1966, 1967, 1968, 1969, 1970, 1971, 
    1972, 1973, 1974, 1975, 1976, 1977, 
    1978, 1979, 1980, 1981, 1982, 1983, 
    1984, 4253, 4254, 4255, 4256, 4257, 
    4258, 4259, 4260, 4261, 5614, 5615, 
    5616, 5617, 5618, 5619, 5620, 5621, 
    5622, 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
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00247

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 (1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,4253,4254,4255,4256,4257,4258,4259,4260,4261,5614,5615,5616,5617,5618,5619,5620,5621,5622,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))",
            "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
1461 308M 0
1473 308M 0
1474 308M 0
1475 308M 0
1476 308M 0
1477 308M 0
1965 308M 0
1966 308M 0
1967 308M 0
1968 308M 0
1969 308M 0
1970 308M 0
1971 308M 0
1972 308M 0
1973 308M 0
1974 308M 0
1975 308M 0
1976 308M 0
1977 308M 0
1978 308M 0
1979 308M 0
1980 308M 0
1981 308M 0
1982 308M 0
1983 308M 0
1984 308M 0
3137 308M 0
4253 308M 0
4254 308M 0
4255 308M 0
4256 308M 0
4257 308M 0
4258 308M 0
4259 308M 0
4260 308M 0
4261 308M 0
5182 308M 0
5183 308M 0
5184 308M 0
5185 308M 0
5186 308M 0
5187 308M 0
5614 308M 0
5615 308M 0
5616 308M 0
5617 308M 0
5618 308M 0
5619 308M 0
5620 308M 0
5621 308M 0
5622 308M 0
5623 308M 0
5624 308M 0
5625 308M 0
5626 308M 0
5627 308M 0
5628 308M 0
5629 308M 0
5630 308M 0
5631 308M 0
5632 308M 0
5633 308M 0
5634 308M 0
5635 308M 0
5636 308M 0
5637 308M 0
5638 308M 0
5639 308M 0
5640 308M 0
5641 308M 0
5642 308M 0
5643 308M 0
5644 308M 0
5645 308M 0
5646 308M 0
5647 308M 0
5648 308M 0
5649 308M 0
5650 308M 0
5651 308M 0
5652 308M 0
5653 308M 0
5654 308M 0
5655 308M 0
5656 308M 0
5657 308M 0
5658 308M 0
5659 308M 0
5660 308M 0
5661 308M 0
5662 308M 0
5663 308M 0
5664 308M 0
5665 308M 0
5666 308M 0
5667 308M 0