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 (
    3354, 3834, 3308, 3306, 3841, 3212, 3226, 
    3350, 3218, 3392, 3301, 3751, 3828, 
    3520, 3529, 3809, 3518, 3918, 3215, 
    3213, 3597, 3752, 3552, 3836, 3232, 
    3589, 3556, 3845, 3822, 3370, 3843, 
    3840, 3882, 3377, 3373, 3593, 3551, 
    3831, 3519, 3919, 3356, 3404, 3366, 
    3222, 3522, 3401, 3358, 3537, 3291, 
    3225, 3844, 3876, 3559, 3917, 3528, 
    3819, 3922, 3534, 3531, 3812, 3372, 
    3374, 3309, 3590, 3351, 3532, 3546, 
    3827, 3548, 3521, 3355, 3398, 3357, 
    3369, 3807, 3525, 3408, 3746, 3393, 
    3744
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00386

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "210.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": 238,
            "rows_produced_per_join": 238,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (3354,3834,3308,3306,3841,3212,3226,3350,3218,3392,3301,3751,3828,3520,3529,3809,3518,3918,3215,3213,3597,3752,3552,3836,3232,3589,3556,3845,3822,3370,3843,3840,3882,3377,3373,3593,3551,3831,3519,3919,3356,3404,3366,3222,3522,3401,3358,3537,3291,3225,3844,3876,3559,3917,3528,3819,3922,3534,3531,3812,3372,3374,3309,3590,3351,3532,3546,3827,3548,3521,3355,3398,3357,3369,3807,3525,3408,3746,3393,3744))",
            "cost_info": {
              "read_cost": "103.31",
              "eval_cost": "23.80",
              "prefix_cost": "127.11",
              "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": 11,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "59.50",
              "eval_cost": "1.19",
              "prefix_cost": "210.41",
              "data_read_per_join": "37K"
            },
            "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
3212 448,423,166M
3213 450,423,424,166M
3215 450,424,423,166M
3218 545,543,568,546,521,250,406,328,402,166,343M
3222 450,424,423,166M
3225 424,423,166M
3226 545,543,568,546,521,250,406,328,402,166,343M
3232 423,448,166M
3291 329,166,457M
3301 423,424,450,166M
3306 450,424,423,166M
3308 423,448,166M
3309 423,450,424,166M
3350 424,423,166M
3351 423,424,166M
3354 423,448,166M
3355 423,426,166M
3356 424,423,166M
3357 423,424,166M
3358 250,166,401,351,446M
3366 329,166,344M
3369 329,166,457M
3370 166,378,490M
3372 492,423,166M
3373 329,166,344M
3374 423,424,166M
3377 492,424,423,166M
3392 423,424,166M
3393 424,347,329,166,492M
3398 492,424,423,166M
3401 492,424,423,166M
3404 329,166,344M
3408 329,166,344M
3518 423,448,166M
3519 423,424,166M
3520 423,424,450,166M
3521 423,424,166M
3522 423,424,450,166M
3525 423,424,166M
3528 423,424,450,166M
3529 423,424,450,166M
3531 423,424,166M
3532 423,424,450,166M
3534 423,424,166M
3537 423,450,424,166M
3546 166,423,424,426M
3548 329,166,344M
3551 424,423,166M
3552 423,424,450,166M
3556 329,166,457M
3559 166,378,490M
3589 423,449,166M
3590 423,424,166M
3593 329,166,457M
3597 250,166,351,401,446M
3744 329,166,344M
3746 424,423,166M
3751 350,166,308,250,387,383M
3752 350,166,387,250,308,383M
3807 423,424,450,166M
3809 423,424,450,166M
3812 329,166,457M
3819 424,423,450,166M
3822 452,424,423,166M
3827 423,448,166M
3828 423,448,166M
3831 423,424,450,166M
3834 423,424,450,166M
3836 378,166,490M
3840 423,424,450,166M
3841 448,166M
3843 423,424,450,166M
3844 423,166M
3845 423,424,450,166M
3876 329,166,457M
3882 166,378,490M
3917 166,378,490M
3918 448,423,166M
3919 166,378,490M
3922 452,424,423,166,492M