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 = 7254 
WHERE 
  cscart_products_categories.product_id IN (
    97348, 97349, 97350, 97351, 97352, 97353, 
    97354, 97355, 97356, 97357, 97358, 
    97359, 97360, 97361, 97362, 97363, 
    97364, 97365, 97366, 97367, 97368, 
    97369, 97370, 97371, 97372, 97373, 
    97374, 97375, 97376, 97377, 97378, 
    97379, 97380, 97381, 97382, 97383, 
    97384, 97385, 97386, 97387, 97388, 
    97389, 97390, 97391, 97392, 97393, 
    97394, 97395, 97396, 97397, 97398, 
    97399, 97400, 97401, 97402, 97403, 
    97404, 97405, 97406, 97407, 97408, 
    97409, 97410, 97411, 97412, 97413, 
    97414, 97415, 97416, 97417, 97418, 
    97419, 97420, 97421, 97422, 97423, 
    97424, 97425, 97506, 97507, 97508, 
    97509, 97510, 97511, 97512, 97513, 
    97514, 97515, 97516, 97517, 97518, 
    97519, 97520, 97521, 97522, 97523
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00163

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "54.77"
    },
    "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 (97348,97349,97350,97351,97352,97353,97354,97355,97356,97357,97358,97359,97360,97361,97362,97363,97364,97365,97366,97367,97368,97369,97370,97371,97372,97373,97374,97375,97376,97377,97378,97379,97380,97381,97382,97383,97384,97385,97386,97387,97388,97389,97390,97391,97392,97393,97394,97395,97396,97397,97398,97399,97400,97401,97402,97403,97404,97405,97406,97407,97408,97409,97410,97411,97412,97413,97414,97415,97416,97417,97418,97419,97420,97421,97422,97423,97424,97425,97506,97507,97508,97509,97510,97511,97512,97513,97514,97515,97516,97517,97518,97519,97520,97521,97522,97523))"
          }
        },
        {
          "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": "53.09",
              "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')))"
          }
        },
        {
          "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": 4,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "1.20",
              "eval_cost": "0.48",
              "prefix_cost": "54.77",
              "data_read_per_join": "76"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
97348 7254M 0
97349 7254M 0
97350 7254M 0
97351 7254M 0
97352 7254M 0
97353 7254M 0
97354 7254M 0
97355 7254M 0
97356 7254M 0
97357 7254M 0
97358 7254M 0
97359 7254M 0
97360 7254M 0
97361 7254M 0
97362 7254M 0
97363 7254M 0
97364 7254M 0
97365 7254M 0
97366 7254M 0
97367 7254M 0
97368 7254M 0
97369 7254M 0
97370 7254M 0
97371 7254M 0
97372 7254M 0
97373 7254M 0
97374 7254M 0
97375 7254M 0
97376 7254M 0
97377 7254M 0
97378 7254M 0
97379 7254M 0
97380 7254M 0
97381 7254M 0
97382 7254M 0
97383 7254M 0
97384 7254M 0
97385 7254M 0
97386 7254M 0
97387 7254M 0
97388 7254M 0
97389 7254M 0
97390 7254M 0
97391 7254M 0
97392 7254M 0
97393 7254M 0
97394 7254M 0
97395 7254M 0
97396 7254M 0
97397 7254M 0
97398 7254M 0
97399 7254M 0
97400 7254M 0
97401 7254M 0
97402 7254M 0
97403 7254M 0
97404 7254M 0
97405 7254M 0
97406 7254M 0
97407 7254M 0
97408 7254M 0
97409 7254M 0
97410 7254M 0
97411 7254M 0
97412 7254M 0
97413 7254M 0
97414 7254M 0
97415 7254M 0
97416 7254M 0
97417 7254M 0
97418 7254M 0
97419 7254M 0
97420 7254M 0
97421 7254M 0
97422 7254M 0
97423 7254M 0
97424 7254M 0
97425 7254M 0
97506 7254M 0
97507 7254M 0
97508 7254M 0
97509 7254M 0
97510 7254M 0
97511 7254M 0
97512 7254M 0
97513 7254M 0
97514 7254M 0
97515 7254M 0
97516 7254M 0
97517 7254M 0
97518 7254M 0
97519 7254M 0
97520 7254M 0
97521 7254M 0
97522 7254M 0
97523 7254M 0