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 (
    97524, 97534, 97535, 97536, 97537, 97538, 
    97539, 97540, 97541, 97542, 97543, 
    97544, 97545, 97546, 97547, 97548, 
    97549, 97550, 97551, 97552, 97553, 
    97554, 97555, 97556, 97557, 97558, 
    97559, 97560, 97561, 97562, 97563, 
    97564, 97565, 97566, 97568, 97569, 
    97571, 97572, 97587, 97588, 97589, 
    97590, 97591, 97592, 97593, 97594, 
    97595, 97596, 97597, 97598, 97599, 
    97600, 97601, 97602, 97603, 97604, 
    97605, 97606, 97607, 98457, 98458, 
    98459, 98460, 98461, 98462, 98463, 
    98464, 98465, 98466, 98467, 98468, 
    98469, 98470, 98471, 98472, 98473, 
    98474, 98475, 99050, 99051, 99052, 
    99053, 99282, 99283, 99284, 99285, 
    99286, 99287, 99288, 99289, 99290, 
    99291, 99292, 99293, 99294, 99295
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00236

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 (97524,97534,97535,97536,97537,97538,97539,97540,97541,97542,97543,97544,97545,97546,97547,97548,97549,97550,97551,97552,97553,97554,97555,97556,97557,97558,97559,97560,97561,97562,97563,97564,97565,97566,97568,97569,97571,97572,97587,97588,97589,97590,97591,97592,97593,97594,97595,97596,97597,97598,97599,97600,97601,97602,97603,97604,97605,97606,97607,98457,98458,98459,98460,98461,98462,98463,98464,98465,98466,98467,98468,98469,98470,98471,98472,98473,98474,98475,99050,99051,99052,99053,99282,99283,99284,99285,99286,99287,99288,99289,99290,99291,99292,99293,99294,99295))"
          }
        },
        {
          "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
97524 7254M 0
97534 7254M 0
97535 7254M 0
97536 7254M 0
97537 7254M 0
97538 7254M 0
97539 7254M 0
97540 7254M 0
97541 7254M 0
97542 7254M 0
97543 7254M 0
97544 7254M 0
97545 7254M 0
97546 7254M 0
97547 7254M 0
97548 7254M 0
97549 7254M 0
97550 7254M 0
97551 7254M 0
97552 7254M 0
97553 7254M 0
97554 7254M 0
97555 7254M 0
97556 7254M 0
97557 7254M 0
97558 7254M 0
97559 7254M 0
97560 7254M 0
97561 7254M 0
97562 7254M 0
97563 7254M 0
97564 7254M 0
97565 7254M 0
97566 7254M 0
97568 7254M 0
97569 7254M 0
97571 7254M 0
97572 7254M 0
97587 7254M 0
97588 7254M 0
97589 7254M 0
97590 7254M 0
97591 7254M 0
97592 7254M 0
97593 7254M 0
97594 7254M 0
97595 7254M 0
97596 7254M 0
97597 7254M 0
97598 7254M 0
97599 7254M 0
97600 7254M 0
97601 7254M 0
97602 7254M 0
97603 7254M 0
97604 7254M 0
97605 7254M 0
97606 7254M 0
97607 7254M 0
98457 7254M 0
98458 7254M 0
98459 7254M 0
98460 7254M 0
98461 7254M 0
98462 7254M 0
98463 7254M 0
98464 7254M 0
98465 7254M 0
98466 7254M 0
98467 7254M 0
98468 7254M 0
98469 7254M 0
98470 7254M 0
98471 7254M 0
98472 7254M 0
98473 7254M 0
98474 7254M 0
98475 7254M 0
99050 7254M 0
99051 7254M 0
99052 7254M 0
99053 7254M 0
99282 7254M 0
99283 7254M 0
99284 7254M 0
99285 7254M 0
99286 7254M 0
99287 7254M 0
99288 7254M 0
99289 7254M 0
99290 7254M 0
99291 7254M 0
99292 7254M 0
99293 7254M 0
99294 7254M 0
99295 7254M 0