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 (
    87325, 87336, 87337, 87348, 87349, 86482, 
    86484, 86758, 86760, 83582, 83583, 
    83584, 83585, 86479, 86755, 91118, 
    91119, 91204, 91205, 91259, 91260, 
    82615, 82617, 82625, 82626, 83418, 
    83420, 83490, 83491, 86651, 86720, 
    87300, 87301, 82612, 83411, 91149, 
    91150, 86480, 86756, 85073, 85159, 
    85205, 85251, 82613, 83416, 83031, 
    83033, 83588, 83590, 90867, 90869, 
    90946, 90948, 82623, 83488, 85070, 
    85156, 85202, 85248, 85113, 83233, 
    83234, 83028, 83581, 90864, 90943, 
    82843, 82916, 82989, 83473, 83481, 
    85110, 85071, 85157, 85203, 85249, 
    83029, 83227, 83232, 83586, 90865, 
    90944, 85111, 86620, 86622, 86689, 
    86691, 83042, 83044, 90878, 90880, 
    90957, 90959, 84810, 84811, 84828
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00260

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 (87325,87336,87337,87348,87349,86482,86484,86758,86760,83582,83583,83584,83585,86479,86755,91118,91119,91204,91205,91259,91260,82615,82617,82625,82626,83418,83420,83490,83491,86651,86720,87300,87301,82612,83411,91149,91150,86480,86756,85073,85159,85205,85251,82613,83416,83031,83033,83588,83590,90867,90869,90946,90948,82623,83488,85070,85156,85202,85248,85113,83233,83234,83028,83581,90864,90943,82843,82916,82989,83473,83481,85110,85071,85157,85203,85249,83029,83227,83232,83586,90865,90944,85111,86620,86622,86689,86691,83042,83044,90878,90880,90957,90959,84810,84811,84828))"
          }
        },
        {
          "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
82612 7170,7171M 0
82613 7170,7171M 0
82615 7170,7171M 0
82617 7170,7171M 0
82623 7170,7171M 0
82625 7170,7171M 0
82626 7170,7171M 0
82843 7170,7171M 0
82916 7170,7171M 0
82989 7170,7171M 0
83028 7170,7171M 0
83029 7170,7171M 0
83031 7170,7171M 0
83033 7170,7171M 0
83042 7170,7171M 0
83044 7170,7171M 0
83227 7170,7171M 0
83232 7170,7171M 0
83233 7170,7171M 0
83234 7170,7171M 0
83411 7170,7171M 0
83416 7170,7171M 0
83418 7170,7171M 0
83420 7170,7171M 0
83473 7170,7171M 0
83481 7170,7171M 0
83488 7170,7171M 0
83490 7170,7171M 0
83491 7170,7171M 0
83581 7170,7171M 0
83582 7170,7171M 0
83583 7170,7171M 0
83584 7170,7171M 0
83585 7170,7171M 0
83586 7170,7171M 0
83588 7170,7171M 0
83590 7170,7171M 0
84810 7170,7171M 0
84811 7170,7171M 0
84828 7170,7171M 0
85070 7170,7171M 0
85071 7170,7171M 0
85073 7170,7171M 0
85110 7170,7171M 0
85111 7170,7171M 0
85113 7170,7171M 0
85156 7170,7171M 0
85157 7170,7171M 0
85159 7170,7171M 0
85202 7170,7171M 0
85203 7170,7171M 0
85205 7170,7171M 0
85248 7170,7171M 0
85249 7170,7171M 0
85251 7170,7171M 0
86479 7170,7171M 0
86480 7170,7171M 0
86482 7170,7171M 0
86484 7170,7171M 0
86620 7170,7171M 0
86622 7170,7171M 0
86651 7170,7171M 0
86689 7170,7171M 0
86691 7170,7171M 0
86720 7170,7171M 0
86755 7170,7171M 0
86756 7170,7171M 0
86758 7170,7171M 0
86760 7170,7171M 0
87300 7170,7171M 0
87301 7170,7171M 0
87325 7170,7171M 0
87336 7170,7171M 0
87337 7170,7171M 0
87348 7170,7171M 0
87349 7170,7171M 0
90864 7171,7170M 0
90865 7171,7170M 0
90867 7171,7170M 0
90869 7171,7170M 0
90878 7171,7170M 0
90880 7171,7170M 0
90943 7171,7170M 0
90944 7171,7170M 0
90946 7171,7170M 0
90948 7171,7170M 0
90957 7171,7170M 0
90959 7171,7170M 0
91118 7171,7170M 0
91119 7171,7170M 0
91149 7171,7170M 0
91150 7171,7170M 0
91204 7171,7170M 0
91205 7171,7170M 0
91259 7171,7170M 0
91260 7171,7170M 0