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 (
    13951, 13952, 13953, 13954, 13955, 13956, 
    13957, 13958, 13959, 13960, 13961, 
    13962, 13963, 13964, 13965, 13966, 
    13967, 13968, 13969, 13970, 13971, 
    13972, 13973, 13974, 13975, 13976, 
    13977, 13978, 13979, 13980, 13981, 
    13982, 13983, 13984, 13985, 13986, 
    13987, 13988, 13989, 13990, 13991, 
    13992, 13993, 13994, 13995, 13996, 
    13997, 13998, 13999, 14000, 14001, 
    14002, 14003, 14004, 14005, 14006, 
    14007, 14008, 14009, 14010, 14011, 
    14012, 14013, 14014, 14015, 14016, 
    14017, 14018
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00075

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost": 0.176511992,
    "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": 68,
          "cost": 0.06862106,
          "filtered": 100,
          "attached_condition": "cscart_products_categories.product_id in (13951,13952,13953,13954,13955,13956,13957,13958,13959,13960,13961,13962,13963,13964,13965,13966,13967,13968,13969,13970,13971,13972,13973,13974,13975,13976,13977,13978,13979,13980,13981,13982,13983,13984,13985,13986,13987,13988,13989,13990,13991,13992,13993,13994,13995,13996,13997,13998,13999,14000,14001,14002,14003,14004,14005,14006,14007,14008,14009,14010,14011,14012,14013,14014,14015,14016,14017,14018)",
          "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": 68,
          "rows": 1,
          "cost": 0.06409872,
          "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
13951 576M
13952 576M
13953 576M
13954 576M
13955 576M
13956 576M
13957 576M
13958 576M
13959 576M
13960 576M
13961 576M
13962 576M
13963 576M
13964 576M
13965 576M
13966 576M
13967 576M
13968 576M
13969 576M
13970 576M
13971 576M
13972 576M
13973 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
13998 576M
13999 576M
14000 576M
14001 576M
14002 576M
14003 576M
14004 576M
14005 576M
14006 576M
14007 576M
14008 576M
14009 576M
14010 576M
14011 576M
14012 576M
14013 576M
14014 576M
14015 576M
14016 576M
14017 576M
14018 576M