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 (
    20673, 20947, 22253, 20168, 19430, 19431, 
    19432, 19438, 19439, 19440, 19443, 
    19444, 19445, 19760, 19761, 19814, 
    19815, 19816, 19817, 19819, 19861, 
    20674, 22462, 21341, 19934, 19138, 
    19433, 19434, 19435, 19436, 19437, 
    19441, 19442, 19759, 19818, 19932
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00086

JSON explain

{
  "query_block": {
    "select_id": 1,
    "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"],
          "rows": 37,
          "filtered": 100,
          "index_condition": "cscart_products_categories.product_id in (20673,20947,22253,20168,19430,19431,19432,19438,19439,19440,19443,19444,19445,19760,19761,19814,19815,19816,19817,19819,19861,20674,22462,21341,19934,19138,19433,19434,19435,19436,19437,19441,19442,19759,19818,19932)"
        }
      },
      {
        "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": ["lillyshop_lillyshop.cscart_products_categories.category_id"],
          "rows": 1,
          "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
19138 1089M
19430 1089M
19431 1089M
19432 1089M
19433 1089M
19434 1089M
19435 1089M
19436 1089M
19437 1089M
19438 1089M
19439 1089M
19440 1089M
19441 1089M
19442 1089M
19443 1089M
19444 1089M
19445 1089M
19759 1089M
19760 1089M
19761 1089M
19814 1089M
19815 1089M
19816 1089M
19817 1089M
19818 1089M
19819 1089M
19861 1089M
19932 1089M
19934 1089M
20168 1089M
20673 1089M
20674 1089M
20947 1089M
21341 1089M
22253 1089M
22462 1089M