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 = 7184 
WHERE 
  cscart_products_categories.product_id IN (
    99659, 99660, 99661, 99662, 99663, 99664, 
    99665, 99666, 99667, 99668, 100144, 
    100145, 100146, 100147, 100148, 100149, 
    100292, 100293, 100294, 100295, 100480, 
    100481, 100482, 100483, 100484, 100485, 
    100486, 100487, 100488, 100489, 100490, 
    100491, 100492, 100493, 100494, 100495, 
    100496, 100497, 100498, 100499, 100504, 
    100505, 100506, 100507, 100508, 100509, 
    100510, 100511, 100512, 100513, 100514, 
    100515, 100516, 100517, 100518, 100519, 
    100520, 100521, 100522, 100523, 100524, 
    100525, 100526, 100527, 100528, 100529, 
    100530, 100531, 100532, 100533, 100534, 
    100535, 100536, 100537, 100538, 100539, 
    100594, 100595, 100596, 100597, 100612, 
    100613, 100614, 100615, 100616, 100617, 
    100618, 100619, 100620, 100621, 100622, 
    100623, 100624, 100625, 100626, 100627
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00256

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "87.14"
    },
    "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": 153,
            "rows_produced_per_join": 153,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "15.62",
              "eval_cost": "15.30",
              "prefix_cost": "30.92",
              "data_read_per_join": "2K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`nuie_scalesta_net`.`cscart_products_categories`.`product_id` in (99659,99660,99661,99662,99663,99664,99665,99666,99667,99668,100144,100145,100146,100147,100148,100149,100292,100293,100294,100295,100480,100481,100482,100483,100484,100485,100486,100487,100488,100489,100490,100491,100492,100493,100494,100495,100496,100497,100498,100499,100504,100505,100506,100507,100508,100509,100510,100511,100512,100513,100514,100515,100516,100517,100518,100519,100520,100521,100522,100523,100524,100525,100526,100527,100528,100529,100530,100531,100532,100533,100534,100535,100536,100537,100538,100539,100594,100595,100596,100597,100612,100613,100614,100615,100616,100617,100618,100619,100620,100621,100622,100623,100624,100625,100626,100627))"
          }
        },
        {
          "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": 7,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "38.25",
              "eval_cost": "0.77",
              "prefix_cost": "84.47",
              "data_read_per_join": "19K"
            },
            "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": 7,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "1.91",
              "eval_cost": "0.77",
              "prefix_cost": "87.14",
              "data_read_per_join": "122"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
99659 7337,7217M
99660 7337,7217M
99661 7337,7217M
99662 7337,7217M
99663 7337,7217M
99664 7337,7217M
99665 7337,7217M
99666 7337,7217M
99667 7337,7217M
99668 7337,7217M
100144 7185M
100145 7188M
100146 7186M
100147 7185M
100148 7186M
100149 7185M
100292 7186M
100293 7185M
100294 7186M
100295 7185M
100480 7341,7342,7343,7157M
100481 7341,7342,7343,7157M
100482 7186M
100483 7185M
100484 7341,7342,7343,7157M
100485 7341,7342,7343,7157M
100486 7341,7342,7343,7157M
100487 7186M
100488 7185M
100489 7186M
100490 7186M
100491 7186M
100492 7185M
100493 7186M
100494 7186M
100495 7186M
100496 7186M
100497 7185M
100498 7186M
100499 7186M
100504 7337,7217M
100505 7337,7217M
100506 7337,7217M
100507 7337,7217M
100508 7337,7217M
100509 7337,7217M
100510 7337,7217M
100511 7337,7217M
100512 7337,7217M
100513 7337,7217M
100514 7337,7217M
100515 7337,7217M
100516 7337,7217M
100517 7337,7217M
100518 7337,7217M
100519 7337,7217M
100520 7337,7217M
100521 7337,7217M
100522 7337,7217M
100523 7337,7217M
100524 7337,7217M
100525 7337,7217M
100526 7337,7217M
100527 7337,7217M
100528 7337,7217M
100529 7337,7217M
100530 7337,7217M
100531 7337,7217M
100532 7337,7217M
100533 7337,7217M
100534 7337,7217M
100535 7337,7217M
100536 7186M
100537 7185M
100538 7186M
100539 7185M
100594 7186M
100595 7185M
100596 7186M
100597 7185M
100612 7185M
100613 7186M
100614 7186M
100615 7186M
100616 7185M
100617 7186M
100618 7185M
100619 7185M
100620 7186M
100621 7185M
100622 7185M
100623 7186M
100624 7185M
100625 7186M
100626 7185M
100627 7185M