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 (
    13861, 13862, 13863, 13864, 13865, 13866, 
    13867, 13868, 13869, 13873, 13874, 
    13875, 13876, 13877, 13878, 13879, 
    13880, 13881, 13882, 13883, 13884, 
    13885, 13886, 13887, 13888, 13897, 
    13898, 13899, 13900, 13901
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00043

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost": 0.080968104,
    "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": 30,
          "cost": 0.03163167,
          "filtered": 100,
          "attached_condition": "cscart_products_categories.product_id in (13861,13862,13863,13864,13865,13866,13867,13868,13869,13873,13874,13875,13876,13877,13878,13879,13880,13881,13882,13883,13884,13885,13886,13887,13888,13897,13898,13899,13900,13901)",
          "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": 30,
          "rows": 1,
          "cost": 0.03011,
          "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
13861 574M
13862 574M
13863 574M
13864 574M
13865 574M
13866 574M
13867 574M
13868 574M
13869 574M
13873 574M
13874 574M
13875 574M
13876 574M
13877 574M
13878 574M
13879 574M
13880 574M
13881 574M
13882 574M
13883 574M
13884 574M
13885 574M
13886 574M
13887 574M
13888 574M
13897 574M
13898 574M
13899 574M
13900 574M
13901 574M