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 (
    6903, 6911, 6993, 7438, 7415, 7422, 7439, 
    7443, 6880, 6996, 9523, 7172, 9520, 
    8132, 8133, 9372, 9413, 9521, 9522, 
    9368, 9374, 9375, 9624, 8793, 9414, 
    9415, 9419, 9420, 9426, 9427, 9524, 
    9416, 9417, 9418, 9469, 8791, 8794, 
    9373, 8413, 8790
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00124

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "42.01"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 40,
            "rows_produced_per_join": 40,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (6903,6911,6993,7438,7415,7422,7439,7443,6880,6996,9523,7172,9520,8132,8133,9372,9413,9521,9522,9368,9374,9375,9624,8793,9414,9415,9419,9420,9426,9427,9524,9416,9417,9418,9469,8791,8794,9373,8413,8790))",
            "cost_info": {
              "read_cost": "24.01",
              "eval_cost": "4.00",
              "prefix_cost": "28.01",
              "data_read_per_join": "640"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        },
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 2,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "10.00",
              "eval_cost": "0.20",
              "prefix_cost": "42.01",
              "data_read_per_join": "6K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`storefront_id` in (0,1)) and ((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`))) and (`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
6880 630M
6903 630M
6911 630M
6993 630M
6996 630M
7172 630M
7415 636M
7422 636M
7438 636M
7439 636M
7443 636M
8132 631M
8133 637M
8413 635M
8790 632M
8791 632M
8793 632M
8794 632M
9368 643M
9372 643M
9373 643M
9374 643M
9375 643M
9413 643M
9414 643M
9415 643M
9416 643M
9417 643M
9418 643M
9419 643M
9420 643M
9426 643M
9427 643M
9469 643M
9520 646M
9521 646M
9522 646M
9523 646M
9524 646M
9624 634M