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 (
    18508, 18509, 18510, 18511, 18513, 18514, 
    18515, 18516, 18517, 18518, 18519, 
    18520, 18521, 18522, 18523, 18524, 
    18525, 18526, 18527, 18528, 18529, 
    18530, 18531, 18532, 18533, 18534, 
    19936, 19937, 19938, 19939, 19940, 
    19941
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00056

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost": 0.129863357,
    "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": 58,
          "cost": 0.03739229,
          "filtered": 100,
          "attached_condition": "cscart_products_categories.product_id in (18508,18509,18510,18511,18513,18514,18515,18516,18517,18518,18519,18520,18521,18522,18523,18524,18525,18526,18527,18528,18529,18530,18531,18532,18533,18534,19936,19937,19938,19939,19940,19941)",
          "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": 58,
          "rows": 1,
          "cost": 0.05515432,
          "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
18508 1629,319M
18509 1629,319M
18510 1629,319M
18511 1629,319M
18513 1629,319M
18514 1629,319M
18515 1629,319M
18516 1629,319M
18517 1629,319M
18518 1629,319M
18519 1629,319M
18520 1629,319M
18521 1629,319M
18522 1629,319M
18523 1629,319M
18524 1629,319M
18525 1629,319M
18526 1629,319M
18527 1629,319M
18528 1629,319M
18529 1629,319M
18530 1629,319M
18531 1629,319M
18532 1629,319M
18533 1629,319M
18534 1629,319M
19936 484M
19937 484M
19938 484M
19939 484M
19940 484M
19941 484M