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 (
    13866, 13867, 13868, 13869, 13873, 13874, 
    13875, 13897, 13898, 13909, 13910, 
    13911, 13921, 13922, 13923, 13924, 
    13925, 13944, 13945, 13951, 13952, 
    13953, 13954, 13955, 13956, 13957, 
    13958, 13959, 13960, 13961, 13962, 
    13969, 13970, 13974, 13975, 13976, 
    13977, 13978, 13979, 13980, 13981, 
    13982, 13983, 13984, 13985, 13986, 
    13987, 13988, 13989, 13990, 13991, 
    13992, 13993, 13994, 13995, 13996, 
    13997, 14021, 14022
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00076

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost": 0.153873184,
    "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": 59,
          "cost": 0.059860415,
          "filtered": 100,
          "attached_condition": "cscart_products_categories.product_id in (13866,13867,13868,13869,13873,13874,13875,13897,13898,13909,13910,13911,13921,13922,13923,13924,13925,13944,13945,13951,13952,13953,13954,13955,13956,13957,13958,13959,13960,13961,13962,13969,13970,13974,13975,13976,13977,13978,13979,13980,13981,13982,13983,13984,13985,13986,13987,13988,13989,13990,13991,13992,13993,13994,13995,13996,13997,14021,14022)",
          "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": 59,
          "rows": 1,
          "cost": 0.05604876,
          "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
13866 574M
13867 574M
13868 574M
13869 574M
13873 574M
13874 574M
13875 574M
13897 574M
13898 574M
13909 575M
13910 575M
13911 575M
13921 575M
13922 575M
13923 575M
13924 575M
13925 575M
13944 577M
13945 577M
13951 576M
13952 576M
13953 576M
13954 576M
13955 576M
13956 576M
13957 576M
13958 576M
13959 576M
13960 576M
13961 576M
13962 576M
13969 576M
13970 576M
13974 576M
13975 576M
13976 576M
13977 576M
13978 576M
13979 576M
13980 576M
13981 576M
13982 576M
13983 576M
13984 576M
13985 576M
13986 576M
13987 576M
13988 576M
13989 576M
13990 576M
13991 576M
13992 576M
13993 576M
13994 576M
13995 576M
13996 576M
13997 576M
14021 578M
14022 578M