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 = 7148 
WHERE 
  cscart_products_categories.product_id IN (
    94708, 94750, 94751, 94752, 94753, 94754, 
    94755, 94756, 94757, 94758, 94759, 
    94760, 94761, 94762, 94763, 94764, 
    94765, 94816, 94822, 94839, 94840, 
    94841, 94844, 94845, 94846, 94847, 
    94848, 94950, 94951, 94952, 94953, 
    94954, 94955, 94958, 95310, 95311, 
    95314, 95317, 95319, 95320, 95361, 
    95362, 95363, 95364, 95365, 95366, 
    95367, 95368
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00155

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "61.02"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "link_type",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 107,
            "rows_produced_per_join": 107,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "11.00",
              "eval_cost": "10.70",
              "prefix_cost": "21.70",
              "data_read_per_join": "1K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`nuie_scalesta_net`.`cscart_products_categories`.`product_id` in (94708,94750,94751,94752,94753,94754,94755,94756,94757,94758,94759,94760,94761,94762,94763,94764,94765,94816,94822,94839,94840,94841,94844,94845,94846,94847,94848,94950,94951,94952,94953,94954,94955,94958,95310,95311,95314,95317,95319,95320,95361,95362,95363,95364,95365,95366,95367,95368))"
          }
        },
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "nuie_scalesta_net.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 5,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "26.75",
              "eval_cost": "0.54",
              "prefix_cost": "59.15",
              "data_read_per_join": "13K"
            },
            "used_columns": [
              "category_id",
              "usergroup_ids",
              "status",
              "storefront_id"
            ],
            "attached_condition": "((`nuie_scalesta_net`.`cscart_categories`.`storefront_id` in (0,1)) and ((`nuie_scalesta_net`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`nuie_scalesta_net`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`nuie_scalesta_net`.`cscart_categories`.`usergroup_ids`))) and (`nuie_scalesta_net`.`cscart_categories`.`status` in ('A','H')))"
          }
        },
        {
          "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",
              "nuie_scalesta_net.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 5,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "1.34",
              "eval_cost": "0.54",
              "prefix_cost": "61.02",
              "data_read_per_join": "85"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
94708 7303,7161M
94750 7313,7338,7219M
94751 7341,7342,7343,7157M
94752 7341,7342,7343,7157M
94753 7341,7342,7343,7157M
94754 7341,7342,7343,7157M
94755 7341,7342,7343,7157M
94756 7341,7342,7343,7157M
94757 7341,7342,7343,7157M
94758 7341,7342,7343,7157M
94759 7313,7338,7219M
94760 7313,7338,7219M
94761 7313,7338,7219M
94762 7341,7342,7343,7157M
94763 7313,7338,7219M
94764 7341,7342,7343,7157M
94765 7313,7338,7219M
94816 7313,7338,7219M
94822 7263M
94839 7265,7247M
94840 7265,7247M
94841 7265,7247M
94844 7263M
94845 7263M
94846 7263M
94847 7263M
94848 7263M
94950 7313,7338,7219M
94951 7313,7338,7219M
94952 7263M
94953 7263M
94954 7263M
94955 7263M
94958 7183,7283,7167M
95310 7263M
95311 7263M
95314 7194M
95317 7263M
95319 7265,7247M
95320 7263M
95361 7263M
95362 7263M
95363 7263M
95364 7263M
95365 7265,7247M
95366 7265,7247M
95367 7265,7247M
95368 7265,7247M