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 (
    86936, 86937, 86938, 86939, 86940, 86941, 
    86942, 86997, 86998, 86999, 87000, 
    87001, 87002, 87003, 87058, 87059, 
    87060, 87061, 87062, 87063, 87064, 
    87116, 87117, 87118, 87119, 87120, 
    87121, 87122, 86930, 86931, 86932, 
    86933, 86934, 86935, 86991, 86992, 
    86993, 86994, 86995, 86996, 87052, 
    87053, 87054, 87055, 87056, 87057, 
    87110, 87111, 87112, 87113, 87114, 
    87115, 86957, 86958, 86959, 86960, 
    86961, 86962, 87018, 87019, 87020, 
    87021, 87022, 87023, 87079, 87080, 
    87081, 87082, 87083, 87084, 87130, 
    87131, 87132, 87133, 87134, 87135, 
    86950, 86951, 86952, 86953, 86954, 
    86955, 86956, 87011, 87012, 87013, 
    87014, 87015, 87016, 87017, 87072, 
    87073, 87074, 87075, 87076, 87077
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00436

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 (86936,86937,86938,86939,86940,86941,86942,86997,86998,86999,87000,87001,87002,87003,87058,87059,87060,87061,87062,87063,87064,87116,87117,87118,87119,87120,87121,87122,86930,86931,86932,86933,86934,86935,86991,86992,86993,86994,86995,86996,87052,87053,87054,87055,87056,87057,87110,87111,87112,87113,87114,87115,86957,86958,86959,86960,86961,86962,87018,87019,87020,87021,87022,87023,87079,87080,87081,87082,87083,87084,87130,87131,87132,87133,87134,87135,86950,86951,86952,86953,86954,86955,86956,87011,87012,87013,87014,87015,87016,87017,87072,87073,87074,87075,87076,87077))"
          }
        },
        {
          "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
86930 7170,7191M 0
86931 7170,7191M 0
86932 7170,7191M 0
86933 7170,7191M 0
86934 7170,7191M 0
86935 7170,7191M 0
86936 7170,7191M 0
86937 7170,7191M 0
86938 7170,7191M 0
86939 7170,7191M 0
86940 7170,7191M 0
86941 7170,7191M 0
86942 7170,7191M 0
86950 7170,7191M 0
86951 7170,7191M 0
86952 7170,7191M 0
86953 7170,7191M 0
86954 7170,7191M 0
86955 7170,7191M 0
86956 7170,7191M 0
86957 7170,7191M 0
86958 7170,7191M 0
86959 7170,7191M 0
86960 7170,7191M 0
86961 7170,7191M 0
86962 7170,7191M 0
86991 7170,7191M 0
86992 7170,7191M 0
86993 7170,7191M 0
86994 7170,7191M 0
86995 7170,7191M 0
86996 7170,7191M 0
86997 7170,7191M 0
86998 7170,7191M 0
86999 7170,7191M 0
87000 7170,7191M 0
87001 7170,7191M 0
87002 7170,7191M 0
87003 7170,7191M 0
87011 7170,7191M 0
87012 7170,7191M 0
87013 7170,7191M 0
87014 7170,7191M 0
87015 7170,7191M 0
87016 7170,7191M 0
87017 7170,7191M 0
87018 7170,7191M 0
87019 7170,7191M 0
87020 7170,7191M 0
87021 7170,7191M 0
87022 7170,7191M 0
87023 7170,7191M 0
87052 7170,7191M 0
87053 7170,7191M 0
87054 7170,7191M 0
87055 7170,7191M 0
87056 7170,7191M 0
87057 7170,7191M 0
87058 7170,7191M 0
87059 7170,7191M 0
87060 7170,7191M 0
87061 7170,7191M 0
87062 7170,7191M 0
87063 7170,7191M 0
87064 7170,7191M 0
87072 7170,7191M 0
87073 7170,7191M 0
87074 7170,7191M 0
87075 7170,7191M 0
87076 7170,7191M 0
87077 7170,7191M 0
87079 7170,7191M 0
87080 7170,7191M 0
87081 7170,7191M 0
87082 7170,7191M 0
87083 7170,7191M 0
87084 7170,7191M 0
87110 7170,7191M 0
87111 7170,7191M 0
87112 7170,7191M 0
87113 7170,7191M 0
87114 7170,7191M 0
87115 7170,7191M 0
87116 7170,7191M 0
87117 7170,7191M 0
87118 7170,7191M 0
87119 7170,7191M 0
87120 7170,7191M 0
87121 7170,7191M 0
87122 7170,7191M 0
87130 7170,7191M 0
87131 7170,7191M 0
87132 7170,7191M 0
87133 7170,7191M 0
87134 7170,7191M 0
87135 7170,7191M 0