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 (
    908, 134, 1142, 853, 1146, 1145, 1144, 
    1143, 856, 1540, 1541, 1542, 1543, 1544, 
    1545, 2258, 2257, 2256, 2255, 2260, 
    2259, 2251, 2265, 2264, 2263, 2253, 
    2363, 2364, 2365, 2373, 2374, 2559, 
    2560, 3663, 2587, 2588, 2589, 2590, 
    2603, 2609, 2610, 2611, 2696, 2697, 
    2695, 2694, 2723, 2724, 2725, 2726, 
    2729, 2730, 2731, 2732, 2742, 2743, 
    2744, 2745, 2746, 2747, 2749, 2750, 
    2751, 2752, 2753, 2754, 2755, 2756, 
    2757, 2761, 2762, 2763, 2764, 2822, 
    2823, 2824, 2825, 2826, 2842, 2843, 
    2844, 2845, 2846, 2847, 2854, 2855, 
    2856, 2857, 2858, 2859, 2927, 2928, 
    2929, 3026, 3030, 3029, 3090, 3091, 
    3092, 3093, 3094, 3096, 3097, 3098, 
    3136, 3137, 3138, 3140, 3141, 3142, 
    3610, 3556, 3557
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00382

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "250.66"
    },
    "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": 278,
            "rows_produced_per_join": 278,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (908,134,1142,853,1146,1145,1144,1143,856,1540,1541,1542,1543,1544,1545,2258,2257,2256,2255,2260,2259,2251,2265,2264,2263,2253,2363,2364,2365,2373,2374,2559,2560,3663,2587,2588,2589,2590,2603,2609,2610,2611,2696,2697,2695,2694,2723,2724,2725,2726,2729,2730,2731,2732,2742,2743,2744,2745,2746,2747,2749,2750,2751,2752,2753,2754,2755,2756,2757,2761,2762,2763,2764,2822,2823,2824,2825,2826,2842,2843,2844,2845,2846,2847,2854,2855,2856,2857,2858,2859,2927,2928,2929,3026,3030,3029,3090,3091,3092,3093,3094,3096,3097,3098,3136,3137,3138,3140,3141,3142,3610,3556,3557))",
            "cost_info": {
              "read_cost": "125.56",
              "eval_cost": "27.80",
              "prefix_cost": "153.36",
              "data_read_per_join": "4K"
            },
            "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": 13,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "69.50",
              "eval_cost": "1.39",
              "prefix_cost": "250.66",
              "data_read_per_join": "43K"
            },
            "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
134 166,329,344M
853 329,166,344M
856 329,166,344M
908 329,166,344M
1142 329,166,344M
1143 329,166,344M
1144 329,166,344M
1145 329,166,344M
1146 329,166,344M
1540 329,166,344M
1541 329,166,344M
1542 329,166,344M
1543 329,166,344M
1544 329,166,344M
1545 166,329,344M
2251 329,166,344M
2253 329,166,344M
2255 329,166,344M
2256 329,166,344M
2257 329,166,344M
2258 329,166,344M
2259 329,166,344M
2260 329,166,344M
2263 329,166,344M
2264 329,166,344M
2265 329,166,344M
2363 166,329,347M
2364 329,166,347M
2365 329,166,347M
2373 166,329,347M
2374 329,166,347M
2559 329,166,344M
2560 329,166,344M
2587 329,166,457M
2588 329,166,457M
2589 166,329,457M
2590 166,329,457M
2603 329,166,457M
2609 329,166,457M
2610 329,166,457M
2611 329,166,457M
2694 329,166,457M
2695 329,166,457M
2696 329,166,457M
2697 329,166,457M
2723 329,166,457M
2724 329,166,457M
2725 329,166,457M
2726 329,166,457M
2729 329,166,344M
2730 329,166,344M
2731 329,166,344M
2732 329,166,344M
2742 329,166,457M
2743 329,166,457M
2744 329,166,457M
2745 329,166,457M
2746 166,329,344M
2747 329,166,344M
2749 329,166,344M
2750 329,166,344M
2751 329,166,344M
2752 329,166,344M
2753 329,166,344M
2754 329,166,344M
2755 329,166,344M
2756 329,166,344M
2757 329,166,344M
2761 329,166,457M
2762 329,166,457M
2763 329,166,457M
2764 329,166,457M
2822 329,166,344M
2823 329,166,344M
2824 329,166,344M
2825 329,166,344M
2826 329,166,344M
2842 166,329,347M
2843 329,166,347M
2844 329,166,347M
2845 329,166,347M
2846 329,166,347M
2847 329,166,347M
2854 329,166,347M
2855 329,166,347M
2856 329,166,347M
2857 329,166,347M
2858 329,166,347M
2859 329,166,347M
2927 329,166,344M
2928 329,166,344M
2929 329,166,344M
3026 329,166,344M
3029 166,329,344M
3030 329,166,344M
3090 329,166,344M
3091 329,166,344M
3092 329,166,344M
3093 329,166,344M
3094 329,166,344M
3096 329,166,457M
3097 329,166,457M
3098 329,166,457M
3136 329,166,457M
3137 329,166,457M
3138 329,166,457M
3140 329,166,344M
3141 329,166,344M
3142 329,166,347M
3556 329,166,457M
3557 329,166,457M
3610 166,329,457M
3663 329,166,344M