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 (
    8703, 8783, 8804, 8275, 8569, 8724, 8445, 
    8470, 8435, 8801, 8805, 8811, 8815, 
    8441, 8446, 8543, 8245, 8440, 8519, 
    8593, 8595, 8432, 8444, 8471, 8594, 
    8472, 8457, 8806, 8830, 8575, 8828, 
    8269, 8466, 8363, 8459, 8460, 8603, 
    8581, 8709, 8438
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00138

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "48.41"
    },
    "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": 48,
            "rows_produced_per_join": 48,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (8703,8783,8804,8275,8569,8724,8445,8470,8435,8801,8805,8811,8815,8441,8446,8543,8245,8440,8519,8593,8595,8432,8444,8471,8594,8472,8457,8806,8830,8575,8828,8269,8466,8363,8459,8460,8603,8581,8709,8438))",
            "cost_info": {
              "read_cost": "26.81",
              "eval_cost": "4.80",
              "prefix_cost": "31.61",
              "data_read_per_join": "768"
            },
            "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": "12.00",
              "eval_cost": "0.24",
              "prefix_cost": "48.41",
              "data_read_per_join": "7K"
            },
            "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
8245 432M
8269 542M
8275 423M
8363 423,477M
8432 386,382M
8435 657M
8438 347M
8440 449M
8441 449M
8444 449M
8445 449M
8446 449M
8457 449M
8459 380,166,425M
8460 166,425M
8466 449M
8470 658M
8471 449M
8472 378,432M
8519 347M
8543 417M
8569 542,546,568,343M
8575 658M
8581 658M
8593 449M
8594 449M
8595 449M
8603 457M
8703 344M
8709 344M
8724 449M
8783 658M
8801 423,657M
8804 423M
8805 399M
8806 166,446M
8811 449M
8815 658M
8828 449M
8830 524M