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 = 7165 
WHERE 
  cscart_products_categories.product_id IN (
    100258, 100259, 100260, 100261, 100262, 
    100263, 100264, 100265, 100266, 100267, 
    100268, 100269, 100270, 100271, 100272, 
    100273, 100274, 100275, 100276, 100277, 
    100278, 100279, 100280, 100281, 100282, 
    100283, 100284, 100285, 100286, 100287, 
    100288, 100289, 100290, 100291, 100296, 
    100297, 100298, 100299, 100300, 100301, 
    100302, 100303, 100304, 100305, 100306, 
    100307, 100308, 100309, 100310, 100311, 
    100312, 100313, 100314, 100315, 100316, 
    100317, 100318, 100319, 100320, 100327, 
    100328, 100329, 100330, 100331, 100332, 
    100333, 100334, 100335, 100336, 100337, 
    100338, 100339, 100340, 100341, 100342, 
    100343, 100344, 100345, 100346, 100347, 
    100348, 100349, 100350, 100351, 100352, 
    100353, 100354, 100355, 100356, 100357, 
    100359, 100360, 100438, 100439, 100440, 
    100441
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00511

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "86.69"
    },
    "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": 96,
            "rows_produced_per_join": 96,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "9.89",
              "eval_cost": "9.60",
              "prefix_cost": "19.49",
              "data_read_per_join": "1K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`nuie_scalesta_net`.`cscart_products_categories`.`product_id` in (100258,100259,100260,100261,100262,100263,100264,100265,100266,100267,100268,100269,100270,100271,100272,100273,100274,100275,100276,100277,100278,100279,100280,100281,100282,100283,100284,100285,100286,100287,100288,100289,100290,100291,100296,100297,100298,100299,100300,100301,100302,100303,100304,100305,100306,100307,100308,100309,100310,100311,100312,100313,100314,100315,100316,100317,100318,100319,100320,100327,100328,100329,100330,100331,100332,100333,100334,100335,100336,100337,100338,100339,100340,100341,100342,100343,100344,100345,100346,100347,100348,100349,100350,100351,100352,100353,100354,100355,100356,100357,100359,100360,100438,100439,100440,100441))"
          }
        },
        {
          "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": 96,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "24.00",
              "eval_cost": "9.60",
              "prefix_cost": "53.09",
              "data_read_per_join": "1K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        },
        {
          "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": 4,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "24.00",
              "eval_cost": "0.48",
              "prefix_cost": "86.69",
              "data_read_per_join": "12K"
            },
            "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')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
100258 7177M
100259 7177M
100260 7168M
100261 7168M
100262 7168M
100263 7168M
100264 7168M
100265 7168M
100266 7168M
100267 7168M
100268 7168M
100269 7168M
100270 7168M
100271 7168M
100272 7168M
100273 7168M
100274 7168M
100275 7168M
100276 7168M
100277 7168M
100278 7168M
100279 7168M
100280 7168M
100281 7168M
100282 7168M
100283 7168M
100284 7168M
100285 7168M
100286 7168M
100287 7168M
100288 7168M
100289 7168M
100290 7168M
100291 7168M
100296 7168M
100297 7168M
100298 7172M
100299 7168M
100300 7172M
100301 7168M
100302 7168M
100303 7174M
100304 7174M
100305 7174M
100306 7174M
100307 7174M
100308 7174M
100309 7168M
100310 7168M
100311 7175M
100312 7168M
100313 7175M
100314 7168M
100315 7175M
100316 7168M
100317 7168M
100318 7175M
100319 7168M
100320 7175M
100327 7168M
100328 7177M
100329 7177M
100330 7177M
100331 7168M
100332 7168M
100333 7168M
100334 7168M
100335 7177M
100336 7177M
100337 7168M
100338 7173M
100339 7173M
100340 7173M
100341 7168M
100342 7168M
100343 7173M
100344 7168M
100345 7173M
100346 7173M
100347 7168M
100348 7179M
100349 7168M
100350 7179M
100351 7168M
100352 7168M
100353 7168M
100354 7168M
100355 7168M
100356 7168M
100357 7176M
100359 7176M
100360 7176M
100438 7177M
100439 7177M
100440 7177M
100441 7177M