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 (
    85496, 85341, 85343, 89755, 89757, 91131, 
    91132, 91135, 91136, 91138, 91139, 
    91140, 91217, 91218, 91221, 91222, 
    91224, 91225, 91226, 91272, 91273, 
    91276, 91277, 91279, 91280, 91281, 
    89497, 89498, 89505, 89506, 89513, 
    89514, 89521, 89522, 91162, 91163, 
    91166, 91167, 91169, 91170, 91171, 
    89203, 89216, 89229, 86481, 86483, 
    86757, 86759, 82614, 82616, 83417, 
    83419, 85072, 85074, 85158, 85160, 
    85204, 85206, 85250, 85252, 83030, 
    83032, 83587, 83589, 90866, 90868, 
    90945, 90947, 85112, 85114, 86619, 
    86621, 86688, 86690, 83041, 83043, 
    90877, 90879, 90956, 90958, 86492, 
    86494, 86768, 86770, 85306, 85308, 
    85403, 85405, 85454, 85456, 85505, 
    85507, 91114, 91116, 91120, 91122
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00156

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 (85496,85341,85343,89755,89757,91131,91132,91135,91136,91138,91139,91140,91217,91218,91221,91222,91224,91225,91226,91272,91273,91276,91277,91279,91280,91281,89497,89498,89505,89506,89513,89514,89521,89522,91162,91163,91166,91167,91169,91170,91171,89203,89216,89229,86481,86483,86757,86759,82614,82616,83417,83419,85072,85074,85158,85160,85204,85206,85250,85252,83030,83032,83587,83589,90866,90868,90945,90947,85112,85114,86619,86621,86688,86690,83041,83043,90877,90879,90956,90958,86492,86494,86768,86770,85306,85308,85403,85405,85454,85456,85505,85507,91114,91116,91120,91122))"
          }
        },
        {
          "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
82614 7170,7171M 0
82616 7170,7171M 0
83030 7170,7171M 0
83032 7170,7171M 0
83041 7170,7171M 0
83043 7170,7171M 0
83417 7170,7171M 0
83419 7170,7171M 0
83587 7170,7171M 0
83589 7170,7171M 0
85072 7170,7171M 0
85074 7170,7171M 0
85112 7170,7171M 0
85114 7170,7171M 0
85158 7170,7171M 0
85160 7170,7171M 0
85204 7170,7171M 0
85206 7170,7171M 0
85250 7170,7171M 0
85252 7170,7171M 0
85306 7170,7171M 0
85308 7170,7171M 0
85341 7170,7171M 0
85343 7170,7171M 0
85403 7170,7171M 0
85405 7170,7171M 0
85454 7170,7171M 0
85456 7170,7171M 0
85496 7170,7171M 0
85505 7170,7171M 0
85507 7170,7171M 0
86481 7170,7171M 0
86483 7170,7171M 0
86492 7170,7171M 0
86494 7170,7171M 0
86619 7170,7171M 0
86621 7170,7171M 0
86688 7170,7171M 0
86690 7170,7171M 0
86757 7170,7171M 0
86759 7170,7171M 0
86768 7170,7171M 0
86770 7170,7171M 0
89203 7170,7171M 0
89216 7170,7171M 0
89229 7170,7171M 0
89497 7170,7171M 0
89498 7170,7171M 0
89505 7170,7171M 0
89506 7170,7171M 0
89513 7170,7171M 0
89514 7170,7171M 0
89521 7170,7171M 0
89522 7170,7171M 0
89755 7170,7171M 0
89757 7170,7171M 0
90866 7171,7170M 0
90868 7171,7170M 0
90877 7171,7170M 0
90879 7171,7170M 0
90945 7171,7170M 0
90947 7171,7170M 0
90956 7171,7170M 0
90958 7171,7170M 0
91114 7171,7170M 0
91116 7171,7170M 0
91120 7171,7170M 0
91122 7171,7170M 0
91131 7171,7170M 0
91132 7171,7170M 0
91135 7171,7170M 0
91136 7171,7170M 0
91138 7171,7170M 0
91139 7171,7170M 0
91140 7171,7170M 0
91162 7171,7170M 0
91163 7171,7170M 0
91166 7171,7170M 0
91167 7171,7170M 0
91169 7171,7170M 0
91170 7171,7170M 0
91171 7171,7170M 0
91217 7171,7170M 0
91218 7171,7170M 0
91221 7171,7170M 0
91222 7171,7170M 0
91224 7171,7170M 0
91225 7171,7170M 0
91226 7171,7170M 0
91272 7171,7170M 0
91273 7171,7170M 0
91276 7171,7170M 0
91277 7171,7170M 0
91279 7171,7170M 0
91280 7171,7170M 0
91281 7171,7170M 0