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 = 7211 
WHERE 
  cscart_products_categories.product_id IN (
    87640, 87876, 88506, 88507, 88510, 87987, 
    90828, 87632, 88561, 87637, 90827, 
    87938, 87941, 87997, 88026, 87781, 
    87882, 87988, 88047, 88048, 88050, 
    88051, 88052, 88053, 88054, 87990, 
    87961, 87875, 87937, 87950, 87959, 
    88798, 90826, 87952, 88004, 87998, 
    88000, 87881, 88031, 87948, 88702, 
    88749, 87945, 87942, 87964, 88029, 
    88018, 88021
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00187

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "78.06"
    },
    "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": 137,
            "rows_produced_per_join": 137,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "14.01",
              "eval_cost": "13.70",
              "prefix_cost": "27.71",
              "data_read_per_join": "2K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`nuie_scalesta_net`.`cscart_products_categories`.`product_id` in (87640,87876,88506,88507,88510,87987,90828,87632,88561,87637,90827,87938,87941,87997,88026,87781,87882,87988,88047,88048,88050,88051,88052,88053,88054,87990,87961,87875,87937,87950,87959,88798,90826,87952,88004,87998,88000,87881,88031,87948,88702,88749,87945,87942,87964,88029,88018,88021))"
          }
        },
        {
          "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": 6,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "34.25",
              "eval_cost": "0.69",
              "prefix_cost": "75.66",
              "data_read_per_join": "17K"
            },
            "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": 6,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "1.71",
              "eval_cost": "0.69",
              "prefix_cost": "78.06",
              "data_read_per_join": "109"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
87632 7210,7211,7214M 0
87637 7210,7211,7214M 0
87640 7210,7211,7214M 0
87781 7210,7211,7321M 0
87875 7241,7309,7346,7208M
87876 7241,7309,7346,7208M
87881 7241,7309,7346,7208M
87882 7241,7309,7346,7208M
87937 7345,7347,7259M
87938 7320,7260M
87941 7320,7260M
87942 7320,7260M
87945 7320,7260M
87948 7345,7347,7259M
87950 7345,7347,7259M
87952 7345,7347,7259M
87959 7320,7260M
87961 7320,7260M
87964 7320,7260M
87987 7345,7347,7259M
87988 7320,7260M
87990 7320,7260M
87997 7345,7347,7259M
87998 7320,7260M
88000 7320,7260M
88004 7345,7347,7259M
88018 7320,7260M
88021 7320,7260M
88026 7345,7347,7259M
88029 7345,7347,7259M
88031 7320,7260M
88047 7345,7347,7259M
88048 7345,7347,7259M
88050 7345,7347,7259M
88051 7345,7347,7259M
88052 7320,7260M
88053 7320,7260M
88054 7320,7260M
88506 7241,7309,7346,7208M
88507 7241,7309,7346,7208M
88510 7241,7309,7346,7208M
88561 7210,7211,7214M 0
88702 7210,7211,7282M 0
88749 7210,7211,7282M 0
88798 7210,7211,7282M 0
90826 7241,7309,7346,7208M
90827 7241,7309,7346,7208M
90828 7241,7309,7346,7208M