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 = 7171 
WHERE 
  cscart_products_categories.product_id IN (
    85212, 85258, 85120, 87310, 87311, 87322, 
    87323, 87334, 87335, 87346, 87347, 
    86144, 86145, 86167, 86168, 86660, 
    86661, 86729, 86730, 87298, 87299, 
    83070, 83623, 90906, 90985, 85081, 
    85167, 85213, 85259, 86142, 86165, 
    86658, 86727, 85854, 85855, 85864, 
    85865, 85121, 89077, 85317, 85318, 
    85414, 85415, 85465, 85466, 85516, 
    85517, 82852, 82853, 82925, 82926, 
    82998, 82999, 83514, 83515, 83522, 
    83523, 85844, 85845, 85363, 85364, 
    86143, 86166, 86659, 86728, 89069, 
    84337, 85315, 85412, 85463, 85514, 
    82850, 82923, 82996, 83512, 83520, 
    83596, 83597, 83598, 83599, 85361, 
    86180, 86182, 86203, 86205, 86504, 
    86506, 86780, 86782, 89822, 89823, 
    89874, 89875, 89946, 89947, 91512
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00360

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "109.29"
    },
    "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": 192,
            "rows_produced_per_join": 192,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "19.53",
              "eval_cost": "19.20",
              "prefix_cost": "38.73",
              "data_read_per_join": "3K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`nuie_scalesta_net`.`cscart_products_categories`.`product_id` in (85212,85258,85120,87310,87311,87322,87323,87334,87335,87346,87347,86144,86145,86167,86168,86660,86661,86729,86730,87298,87299,83070,83623,90906,90985,85081,85167,85213,85259,86142,86165,86658,86727,85854,85855,85864,85865,85121,89077,85317,85318,85414,85415,85465,85466,85516,85517,82852,82853,82925,82926,82998,82999,83514,83515,83522,83523,85844,85845,85363,85364,86143,86166,86659,86728,89069,84337,85315,85412,85463,85514,82850,82923,82996,83512,83520,83596,83597,83598,83599,85361,86180,86182,86203,86205,86504,86506,86780,86782,89822,89823,89874,89875,89946,89947,91512))"
          }
        },
        {
          "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": 9,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "48.00",
              "eval_cost": "0.96",
              "prefix_cost": "105.93",
              "data_read_per_join": "25K"
            },
            "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": 9,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "2.40",
              "eval_cost": "0.96",
              "prefix_cost": "109.29",
              "data_read_per_join": "153"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
82850 7170,7171M 0
82852 7170,7171M 0
82853 7170,7171M 0
82923 7170,7171M 0
82925 7170,7171M 0
82926 7170,7171M 0
82996 7170,7171M 0
82998 7170,7171M 0
82999 7170,7171M 0
83070 7170,7171M 0
83512 7170,7171M 0
83514 7170,7171M 0
83515 7170,7171M 0
83520 7170,7171M 0
83522 7170,7171M 0
83523 7170,7171M 0
83596 7170,7171M 0
83597 7170,7171M 0
83598 7170,7171M 0
83599 7170,7171M 0
83623 7170,7171M 0
84337 7170,7171M 0
85081 7170,7171M 0
85120 7170,7171M 0
85121 7170,7171M 0
85167 7170,7171M 0
85212 7170,7171M 0
85213 7170,7171M 0
85258 7170,7171M 0
85259 7170,7171M 0
85315 7170,7171M 0
85317 7170,7171M 0
85318 7170,7171M 0
85361 7170,7171M 0
85363 7170,7171M 0
85364 7170,7171M 0
85412 7170,7171M 0
85414 7170,7171M 0
85415 7170,7171M 0
85463 7170,7171M 0
85465 7170,7171M 0
85466 7170,7171M 0
85514 7170,7171M 0
85516 7170,7171M 0
85517 7170,7171M 0
85844 7170,7171M 0
85845 7170,7171M 0
85854 7170,7171M 0
85855 7170,7171M 0
85864 7170,7171M 0
85865 7170,7171M 0
86142 7170,7171M 0
86143 7170,7171M 0
86144 7170,7171M 0
86145 7170,7171M 0
86165 7170,7171M 0
86166 7170,7171M 0
86167 7170,7171M 0
86168 7170,7171M 0
86180 7170,7171M 0
86182 7170,7171M 0
86203 7170,7171M 0
86205 7170,7171M 0
86504 7170,7171M 0
86506 7170,7171M 0
86658 7170,7171M 0
86659 7170,7171M 0
86660 7170,7171M 0
86661 7170,7171M 0
86727 7170,7171M 0
86728 7170,7171M 0
86729 7170,7171M 0
86730 7170,7171M 0
86780 7170,7171M 0
86782 7170,7171M 0
87298 7170,7171M 0
87299 7170,7171M 0
87310 7170,7171M 0
87311 7170,7171M 0
87322 7170,7171M 0
87323 7170,7171M 0
87334 7170,7171M 0
87335 7170,7171M 0
87346 7170,7171M 0
87347 7170,7171M 0
89069 7170,7171M 0
89077 7170,7171M 0
89822 7170,7171M 0
89823 7170,7171M 0
89874 7170,7171M 0
89875 7170,7171M 0
89946 7170,7171M 0
89947 7170,7171M 0
90906 7171,7170M 0
90985 7171,7170M 0
91512 7171,7170M 0