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 (
    3213, 3214, 3216, 3215, 3222, 3223, 3310, 
    3309, 3352, 3351, 3366, 3367, 3609, 
    3370, 3371, 3377, 3378, 3398, 3399, 
    3401, 3402, 3404, 3405, 3522, 3523, 
    3525, 3526, 3532, 3533, 3548, 3549, 
    3552, 3553, 3610, 3556, 3557, 3588, 
    3559, 3560, 3591, 3590, 3593, 3594, 
    3812, 3813, 3832, 3831, 3834, 3835, 
    3836, 3839, 3838, 3837, 3873, 3546, 
    3876, 3877, 3923, 3922, 3373, 4124, 
    4125
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00363

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "156.31"
    },
    "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": 176,
            "rows_produced_per_join": 176,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (3213,3214,3216,3215,3222,3223,3310,3309,3352,3351,3366,3367,3609,3370,3371,3377,3378,3398,3399,3401,3402,3404,3405,3522,3523,3525,3526,3532,3533,3548,3549,3552,3553,3610,3556,3557,3588,3559,3560,3591,3590,3593,3594,3812,3813,3832,3831,3834,3835,3836,3839,3838,3837,3873,3546,3876,3877,3923,3922,3373,4124,4125))",
            "cost_info": {
              "read_cost": "77.11",
              "eval_cost": "17.60",
              "prefix_cost": "94.71",
              "data_read_per_join": "2K"
            },
            "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": 8,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "44.00",
              "eval_cost": "0.88",
              "prefix_cost": "156.31",
              "data_read_per_join": "27K"
            },
            "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
3213 450,423,424,166M
3214 450,424,423,166M
3215 450,424,423,166M
3216 450,423,424,166M
3222 450,424,423,166M
3223 450,423,424,166M
3309 423,450,424,166M
3310 423,450,424,166M
3351 423,424,166M
3352 423,424,166M
3366 329,166,344M
3367 329,166,344M
3370 166,378,490M
3371 378,166,490M
3373 329,166,344M
3377 492,424,423,166M
3378 492,423,424,166M
3398 492,424,423,166M
3399 424,423,492,166M
3401 492,424,423,166M
3402 423,424,492,166M
3404 329,166,344M
3405 329,166,344M
3522 423,424,450,166M
3523 423,424,450,166M
3525 423,424,166M
3526 423,424,166M
3532 423,424,450,166M
3533 423,424,450,166M
3546 166,423,424,426M
3548 329,166,344M
3549 329,166,344M
3552 423,424,450,166M
3553 423,424,450,166M
3556 329,166,457M
3557 329,166,457M
3559 166,378,490M
3560 378,166,490M
3588 166,378,490M
3590 423,424,166M
3591 423,424,166M
3593 329,166,457M
3594 166,329,457M
3609 166,378,490M
3610 166,329,457M
3812 329,166,457M
3813 329,166,457M
3831 423,424,450,166M
3832 424,450,423,166M
3834 423,424,450,166M
3835 423,424,450,166M
3836 378,166,490M
3837 378,166,490M
3838 378,166,490M
3839 378,166,490M
3873 424,166,423,426M
3876 329,166,457M
3877 329,166,457M
3922 452,424,423,166,492M
3923 424,423,452,166,492M
4124 329,166,344M
4125 166,329,344M