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 = 7182 
WHERE 
  cscart_products_categories.product_id IN (
    86856, 85583, 82561, 90268, 90264, 90266, 
    90273, 91311, 91313, 91315, 90267, 
    90274, 85649, 85650, 85651, 91312, 
    91314, 91316, 90263, 90270, 90269, 
    90275, 90265, 93356, 93357, 93358, 
    94117, 94958, 95683, 95702, 95703, 
    96841, 96918, 96919, 96998, 98482, 
    98538, 98539, 98540, 98541, 98542, 
    98543, 98544, 98545, 98546, 98547, 
    98548, 98549, 98758, 100971, 100972, 
    100973, 100974, 100975, 100976, 100977, 
    100978, 100982, 100983, 100984, 100988, 
    101102, 101103, 101104, 101628, 101629, 
    101630, 101631, 101632, 101633, 101678, 
    101679, 101680, 101681, 101740, 101741, 
    101742, 101743, 101854, 101855, 101856, 
    101857, 101858, 101859, 101860, 101861, 
    101862, 101863, 101864, 101865, 101866, 
    101867, 101868, 101869, 101870, 101871
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00277

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "163.80"
    },
    "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": 288,
            "rows_produced_per_join": 288,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "29.17",
              "eval_cost": "28.80",
              "prefix_cost": "57.97",
              "data_read_per_join": "4K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`nuie_scalesta_net`.`cscart_products_categories`.`product_id` in (86856,85583,82561,90268,90264,90266,90273,91311,91313,91315,90267,90274,85649,85650,85651,91312,91314,91316,90263,90270,90269,90275,90265,93356,93357,93358,94117,94958,95683,95702,95703,96841,96918,96919,96998,98482,98538,98539,98540,98541,98542,98543,98544,98545,98546,98547,98548,98549,98758,100971,100972,100973,100974,100975,100976,100977,100978,100982,100983,100984,100988,101102,101103,101104,101628,101629,101630,101631,101632,101633,101678,101679,101680,101681,101740,101741,101742,101743,101854,101855,101856,101857,101858,101859,101860,101861,101862,101863,101864,101865,101866,101867,101868,101869,101870,101871))"
          }
        },
        {
          "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": 14,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "72.00",
              "eval_cost": "1.44",
              "prefix_cost": "158.77",
              "data_read_per_join": "37K"
            },
            "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": 14,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "3.60",
              "eval_cost": "1.44",
              "prefix_cost": "163.81",
              "data_read_per_join": "230"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
82561 7183,7283,7167M
85583 7182,7300,7149M 0
85649 7183,7283,7167M
85650 7183,7283,7167M
85651 7183,7283,7167M
86856 7182,7300,7149M 0
90263 7183,7283,7167M
90264 7183,7283,7167M
90265 7183,7283,7167M
90266 7183,7283,7167M
90267 7183,7283,7167M
90268 7183,7283,7167M
90269 7183,7283,7167M
90270 7183,7283,7167M
90273 7183,7283,7167M
90274 7183,7283,7167M
90275 7183,7283,7167M
91311 7183,7283,7167M
91312 7183,7283,7167M
91313 7183,7283,7167M
91314 7183,7283,7167M
91315 7183,7283,7167M
91316 7183,7283,7167M
93356 7183,7283,7167M
93357 7183,7283,7167M
93358 7183,7283,7167M
94117 7183,7283,7167M
94958 7183,7283,7167M
95683 7183,7283,7167M
95702 7183,7283,7167M
95703 7183,7283,7167M
96841 7183,7283,7167M
96918 7183,7283,7167M
96919 7183,7283,7167M
96998 7183,7283,7167M
98482 7182,7300,7149M 0
98538 7183,7283,7167M
98539 7183,7283,7167M
98540 7183,7283,7167M
98541 7183,7283,7167M
98542 7183,7283,7167M
98543 7183,7283,7167M
98544 7183,7283,7167M
98545 7183,7283,7167M
98546 7183,7283,7167M
98547 7183,7283,7167M
98548 7183,7283,7167M
98549 7183,7283,7167M
98758 7182,7300,7149M 0
100971 7183,7283,7167M
100972 7183,7283,7167M
100973 7183,7283,7167M
100974 7183,7283,7167M
100975 7183,7283,7167M
100976 7183,7283,7167M
100977 7183,7283,7167M
100978 7183,7283,7167M
100982 7183,7283,7167M
100983 7183,7283,7167M
100984 7183,7283,7167M
100988 7183,7283,7167M
101102 7183,7283,7167M
101103 7183,7283,7167M
101104 7183,7283,7167M
101628 7183,7283,7167M
101629 7183,7283,7167M
101630 7183,7283,7167M
101631 7183,7283,7167M
101632 7183,7283,7167M
101633 7183,7283,7167M
101678 7183,7283,7167M
101679 7183,7283,7167M
101680 7183,7283,7167M
101681 7183,7283,7167M
101740 7183,7283,7167M
101741 7183,7283,7167M
101742 7183,7283,7167M
101743 7183,7283,7167M
101854 7183,7283,7167M
101855 7183,7283,7167M
101856 7183,7283,7167M
101857 7183,7283,7167M
101858 7183,7283,7167M
101859 7183,7283,7167M
101860 7183,7283,7167M
101861 7183,7283,7167M
101862 7183,7283,7167M
101863 7183,7283,7167M
101864 7183,7283,7167M
101865 7183,7283,7167M
101866 7183,7283,7167M
101867 7183,7283,7167M
101868 7183,7283,7167M
101869 7183,7283,7167M
101870 7183,7283,7167M
101871 7183,7283,7167M