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 (
    3564, 3482, 3581, 3574, 3583, 3579, 3476, 
    3569, 3870, 3562, 3543, 3856, 3585, 
    3503, 3488, 2119, 3577, 3899, 3544, 
    3502, 3823, 3884, 3575, 3539, 3541, 
    2120, 3576, 3469, 3584, 3487, 3808, 
    3868, 3472, 3514, 3580, 3473, 3479, 
    3572, 3866, 3570, 3582, 3489, 3567, 
    3861, 3561, 3504, 3475, 3565, 3573, 
    3568, 3563, 3547, 3513, 3586, 3542, 
    3571, 3566, 3474, 3538, 3540, 3587
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00319

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "134.46"
    },
    "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": 149,
            "rows_produced_per_join": 149,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (3564,3482,3581,3574,3583,3579,3476,3569,3870,3562,3543,3856,3585,3503,3488,2119,3577,3899,3544,3502,3823,3884,3575,3539,3541,2120,3576,3469,3584,3487,3808,3868,3472,3514,3580,3473,3479,3572,3866,3570,3582,3489,3567,3861,3561,3504,3475,3565,3573,3568,3563,3547,3513,3586,3542,3571,3566,3474,3538,3540,3587))",
            "cost_info": {
              "read_cost": "67.41",
              "eval_cost": "14.90",
              "prefix_cost": "82.31",
              "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": 7,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "37.25",
              "eval_cost": "0.75",
              "prefix_cost": "134.46",
              "data_read_per_join": "23K"
            },
            "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
2119 167,166,354M
2120 167,166,354M
3469 167,166,354M
3472 167,166,354M
3473 167,166,354M
3474 167,166,354M
3475 167,166,354M
3476 167,166,354M
3479 167,166,354M
3482 167,166,354M
3487 167,166,354M
3488 167,166,354M
3489 167,166,354M
3502 167,166,354M
3503 167,166,354M
3504 167,166,354M
3513 167,166,354M
3514 167,166,354M
3538 167,166,354M
3539 167,166,354M
3540 167,166,354M
3541 167,166,354M
3542 167,166,354M
3543 167,166,354M
3544 167,166,354M
3547 167,166,354M
3561 167,166,354M
3562 167,166,354M
3563 167,166,354M
3564 167,166,354M
3565 167,166,354M
3566 167,166,354M
3567 167,166,354M
3568 167,166,354M
3569 167,166,354M
3570 167,166,354M
3571 167,166,354M
3572 167,166,354M
3573 167,166,354M
3574 167,166,354M
3575 167,166,354M
3576 167,166,354M
3577 167,166,354M
3579 167,166,354M
3580 167,166,354M
3581 167,166,354M
3582 167,166,354M
3583 167,166,354M
3584 167,166,354M
3585 167,166,354M
3586 167,166,354M
3587 167,166,354M
3808 170,166,505M
3823 170,166,505M
3856 170,166,505M
3861 170,166,505M
3866 170,166,505M
3868 170,166,505M
3870 170,166,505M
3884 170,166,505M
3899 170,166,505M