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 
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') 
WHERE 
  cscart_products_categories.product_id IN (
    13451, 13479, 13861, 13862, 13863, 13864, 
    13865, 13897, 13898, 13902, 13903, 
    13909, 13910, 13911, 13913, 13914, 
    13915, 13921, 13922, 13923, 13924, 
    13925, 13944, 13945, 13947, 13948, 
    13949, 13971, 13972, 13973, 15751, 
    15752, 16338, 16339
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00046

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost": 0.128140228,
    "nested_loop": [
      {
        "table": {
          "table_name": "cscart_products_categories",
          "access_type": "range",
          "possible_keys": ["PRIMARY", "pt"],
          "key": "pt",
          "key_length": "3",
          "used_key_parts": ["product_id"],
          "loops": 1,
          "rows": 56,
          "cost": 0.03875236,
          "filtered": 100,
          "attached_condition": "cscart_products_categories.product_id in (13451,13479,13861,13862,13863,13864,13865,13897,13898,13902,13903,13909,13910,13911,13913,13914,13915,13921,13922,13923,13924,13925,13944,13945,13947,13948,13949,13971,13972,13973,15751,15752,16338,16339)",
          "using_index": true
        }
      },
      {
        "table": {
          "table_name": "cscart_categories",
          "access_type": "eq_ref",
          "possible_keys": ["PRIMARY", "c_status", "p_category_id"],
          "key": "PRIMARY",
          "key_length": "3",
          "used_key_parts": ["category_id"],
          "ref": ["u508912950_dev_2025.cscart_products_categories.category_id"],
          "loops": 56,
          "rows": 1,
          "cost": 0.05336544,
          "filtered": 100,
          "attached_condition": "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')"
        }
      }
    ]
  }
}

Result

product_id category_ids
13451 1632M
13479 1632M
13861 574M
13862 574M
13863 574M
13864 574M
13865 574M
13897 574M
13898 574M
13902 575M
13903 575M
13909 575M
13910 575M
13911 575M
13913 575M
13914 575M
13915 575M
13921 575M
13922 575M
13923 575M
13924 575M
13925 575M
13944 577M
13945 577M
13947 577M
13948 577M
13949 577M
13971 576M
13972 576M
13973 576M
15751 925,1396,1398,1411,1613M
15752 925,1396,1398,1411,1613M
16338 925,1125,1397,1613,1620,1670,1671,1396M
16339 925,1125,1397,1613,1620,1670,1671,1396M