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 (
    5485, 5479, 5420, 5518, 5441, 5434, 5590, 
    5417, 5541, 5406, 5407, 5493, 5526, 
    5484, 5412, 5583, 5680, 5416, 5482, 
    5544, 5589, 5600, 5487, 5418, 5421, 
    5499, 5521, 5532, 5597, 5455, 5512, 
    5560, 5562, 5588, 5669, 5525, 5679, 
    5533, 5974, 5579, 5584, 5481, 5489, 
    5428, 5524, 5591, 5511, 5419, 5495, 
    5423, 5424, 5480, 5486, 5657, 5546, 
    5543, 5440, 5547, 5548, 9547, 5438, 
    5443, 5476, 5542, 5592, 5585, 5649, 
    5447, 5529, 5439, 5659, 5602, 5496, 
    5656, 5475, 5433, 5498, 5603, 5432, 
    5514
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00351

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "180.81"
    },
    "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": 201,
            "rows_produced_per_join": 201,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (5485,5479,5420,5518,5441,5434,5590,5417,5541,5406,5407,5493,5526,5484,5412,5583,5680,5416,5482,5544,5589,5600,5487,5418,5421,5499,5521,5532,5597,5455,5512,5560,5562,5588,5669,5525,5679,5533,5974,5579,5584,5481,5489,5428,5524,5591,5511,5419,5495,5423,5424,5480,5486,5657,5546,5543,5440,5547,5548,9547,5438,5443,5476,5542,5592,5585,5649,5447,5529,5439,5659,5602,5496,5656,5475,5433,5498,5603,5432,5514))",
            "cost_info": {
              "read_cost": "90.36",
              "eval_cost": "20.10",
              "prefix_cost": "110.46",
              "data_read_per_join": "3K"
            },
            "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": 10,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "50.25",
              "eval_cost": "1.01",
              "prefix_cost": "180.81",
              "data_read_per_join": "31K"
            },
            "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
5406 473,577,474M
5407 473,577,474M
5412 473,577,474M
5416 474M
5417 473,577,474M
5418 473,577,474M
5419 473,577,474M
5420 473,577,475M
5421 473,577,475M
5423 577,578M
5424 577,578M
5428 466,372,574M
5432 466,372,574M
5433 466,372,574M
5434 466,372,574M
5438 466,372,574M
5439 466,372,574M
5440 466,372,574M
5441 466,372,574M
5443 466,372,574M
5447 466,372,574M
5455 466,372,574M
5475 466,372,574M
5476 466,372,574M
5479 466,372,575M
5480 466,372,575M
5481 466,372,575M
5482 466,372,575M
5484 466,372,575M
5485 466,372,575M
5486 466,372,575M
5487 466,372,575M
5489 466,372,575M
5493 466,372,575M
5495 466,372,575M
5496 466,372,573M
5498 466,372,573M
5499 466,372,573M
5511 466,372,573M
5512 466,372,573M
5514 466,372,573M
5518 466,372,573M
5521 466,372,573M
5524 466,372,576M
5525 466,372,576M
5526 466,372,467M
5529 466,372,573M
5532 466,372,580M
5533 466,372,579M
5541 554,556M
5542 553,250,552,554,372,556M
5543 553,250,552,554,372,556M
5544 553,250,552,554,372,556M
5546 553,250,552,554,372,556M
5547 553,250,552,554,372,556M
5548 553,250,552,554,372,556M
5560 572,372,582M
5562 572,372,582M
5579 572,372,582M
5583 572,372,582M
5584 572,372,582M
5585 466,372,573M
5588 466,372,573M
5589 466,372,573M
5590 466,372,573M
5591 466,372,573M
5592 466,372,573M
5597 466,372,573M
5600 466,372,573M
5602 466,372,573M
5603 466,372,573M
5649 372,384,460M
5656 372,384M
5657 372,384M
5659 372,384M
5669 566,372,596M
5679 566,372,596M
5680 566,372,597,596M
5974 577,578M
9547 577M