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 = 7170 
WHERE 
  cscart_products_categories.product_id IN (
    101239, 101240, 101241, 101242, 101243, 
    101244, 101245, 101246, 101247, 101248, 
    101249, 101250, 101251, 101252, 101253, 
    101254, 101255, 101256, 101257, 101258, 
    101259, 101260, 101261, 101262, 101263, 
    101264, 101265, 101266, 101267, 101268, 
    101269, 101270, 101271, 101272, 101273, 
    101274, 101275, 101276, 101277, 101278, 
    101279, 101280, 101281, 101282, 101283, 
    101284, 101285, 101286, 101287, 101288, 
    101289, 101290, 101291, 101292, 101293, 
    101294, 101295, 101296, 101297, 101298, 
    101299, 101300, 101301, 101302, 101303, 
    101304, 101305, 101306, 101307, 101308, 
    101309, 101310, 101311, 101312, 101313, 
    101314, 101315, 101316, 101317, 101318, 
    101319, 101320, 101321, 101322, 101323, 
    101324, 101325, 101326, 101327, 101328, 
    101329, 101330, 101331, 101332, 101333, 
    101334
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00227

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "54.77"
    },
    "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": 96,
            "rows_produced_per_join": 96,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "9.89",
              "eval_cost": "9.60",
              "prefix_cost": "19.49",
              "data_read_per_join": "1K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`nuie_scalesta_net`.`cscart_products_categories`.`product_id` in (101239,101240,101241,101242,101243,101244,101245,101246,101247,101248,101249,101250,101251,101252,101253,101254,101255,101256,101257,101258,101259,101260,101261,101262,101263,101264,101265,101266,101267,101268,101269,101270,101271,101272,101273,101274,101275,101276,101277,101278,101279,101280,101281,101282,101283,101284,101285,101286,101287,101288,101289,101290,101291,101292,101293,101294,101295,101296,101297,101298,101299,101300,101301,101302,101303,101304,101305,101306,101307,101308,101309,101310,101311,101312,101313,101314,101315,101316,101317,101318,101319,101320,101321,101322,101323,101324,101325,101326,101327,101328,101329,101330,101331,101332,101333,101334))"
          }
        },
        {
          "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": 4,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "24.00",
              "eval_cost": "0.48",
              "prefix_cost": "53.09",
              "data_read_per_join": "12K"
            },
            "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": 4,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "1.20",
              "eval_cost": "0.48",
              "prefix_cost": "54.77",
              "data_read_per_join": "76"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
101239 7200M
101240 7200M
101241 7200M
101242 7200M
101243 7200M
101244 7200M
101245 7200M
101246 7200M
101247 7200M
101248 7200M
101249 7200M
101250 7200M
101251 7200M
101252 7200M
101253 7200M
101254 7200M
101255 7200M
101256 7200M
101257 7200M
101258 7200M
101259 7200M
101260 7200M
101261 7200M
101262 7200M
101263 7200M
101264 7200M
101265 7200M
101266 7200M
101267 7200M
101268 7200M
101269 7200M
101270 7200M
101271 7200M
101272 7200M
101273 7200M
101274 7200M
101275 7200M
101276 7200M
101277 7200M
101278 7200M
101279 7200M
101280 7200M
101281 7200M
101282 7200M
101283 7200M
101284 7200M
101285 7200M
101286 7200M
101287 7200M
101288 7200M
101289 7200M
101290 7200M
101291 7200M
101292 7200M
101293 7200M
101294 7200M
101295 7200M
101296 7200M
101297 7200M
101298 7200M
101299 7200M
101300 7200M
101301 7200M
101302 7200M
101303 7200M
101304 7200M
101305 7200M
101306 7200M
101307 7200M
101308 7200M
101309 7200M
101310 7200M
101311 7200M
101312 7200M
101313 7200M
101314 7200M
101315 7200M
101316 7200M
101317 7200M
101318 7200M
101319 7200M
101320 7200M
101321 7200M
101322 7200M
101323 7200M
101324 7200M
101325 7200M
101326 7200M
101327 7200M
101328 7200M
101329 7200M
101330 7200M
101331 7200M
101332 7200M
101333 7200M
101334 7200M