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, 
    2262, 
    2261, 
    2252, 
    2265, 
    2264, 
    2263, 
    2253, 
    2267, 
    2266, 
    2254, 
    2559, 
    2560, 
    3663, 
    2562, 
    2729, 
    2730, 
    2731, 
    2732, 
    2746, 
    2747, 
    2749, 
    2750, 
    2751, 
    2752, 
    2753, 
    2754, 
    2755, 
    2756, 
    2757, 
    2768, 
    2767, 
    2775, 
    2786, 
    2787, 
    2788, 
    2789, 
    2790, 
    2791, 
    2792, 
    2793, 
    2794, 
    2795, 
    2796, 
    2800, 
    2801, 
    2822, 
    2823, 
    2824, 
    2825, 
    2826, 
    2860, 
    2869, 
    2870, 
    2871, 
    2877, 
    2878, 
    2879, 
    2880, 
    2881, 
    2927, 
    2928, 
    2929, 
    2935, 
    2936, 
    3011, 
    3012, 
    3013, 
    3014, 
    3015, 
    3021, 
    3022, 
    3023, 
    3024, 
    3026, 
    3030, 
    3029, 
    3060, 
    3061, 
    3090, 
    3091, 
    3092, 
    3093, 
    3094, 
    3099, 
    3100, 
    3140, 
    3141, 
    3160, 
    3161, 
    2760, 
    3164, 
    3165, 
    3366, 
    3367, 
    3404, 
    3405, 
    3548, 
    3549, 
    3373, 
    4124, 
    4125, 
    5129, 
    5126, 
    5135, 
    5133, 
    5151, 
    5153, 
    7871, 
    7872, 
    7873, 
    7875, 
    7876, 
    7874, 
    7877, 
    8703, 
    8704, 
    8705, 
    8706, 
    10454, 
    10455
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00531

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "299.51"
    },
    "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": 330,
            "rows_produced_per_join": 330,
            "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,2262,2261,2252,2265,2264,2263,2253,2267,2266,2254,2559,2560,3663,2562,2729,2730,2731,2732,2746,2747,2749,2750,2751,2752,2753,2754,2755,2756,2757,2768,2767,2775,2786,2787,2788,2789,2790,2791,2792,2793,2794,2795,2796,2800,2801,2822,2823,2824,2825,2826,2860,2869,2870,2871,2877,2878,2879,2880,2881,2927,2928,2929,2935,2936,3011,3012,3013,3014,3015,3021,3022,3023,3024,3026,3030,3029,3060,3061,3090,3091,3092,3093,3094,3099,3100,3140,3141,3160,3161,2760,3164,3165,3366,3367,3404,3405,3548,3549,3373,4124,4125,5129,5126,5135,5133,5151,5153,7871,7872,7873,7875,7876,7874,7877,8703,8704,8705,8706,10454,10455))",
            "cost_info": {
              "read_cost": "151.01",
              "eval_cost": "33.00",
              "prefix_cost": "184.01",
              "data_read_per_join": "5K"
            },
            "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": 16,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "82.50",
              "eval_cost": "1.65",
              "prefix_cost": "299.51",
              "data_read_per_join": "51K"
            },
            "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
2252 329,166,344M
2253 329,166,344M
2254 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
2261 329,166,344M
2262 329,166,344M
2263 329,166,344M
2264 329,166,344M
2265 329,166,344M
2266 329,166,344M
2267 329,166,344M
2559 329,166,344M
2560 329,166,344M
2562 329,166,344M
2729 329,166,344M
2730 329,166,344M
2731 329,166,344M
2732 329,166,344M
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
2760 329,166,344M
2767 329,166,344M
2768 329,166,344M
2775 329,166,344M
2786 329,166,344M
2787 166,329,344M
2788 329,166,344M
2789 166,329,344M
2790 166,329,344M
2791 166,329,344M
2792 329,166,344M
2793 166,329,344M
2794 329,166,344M
2795 329,166,344M
2796 166,329,344M
2800 329,166,344M
2801 329,166,344M
2822 329,166,344M
2823 329,166,344M
2824 329,166,344M
2825 329,166,344M
2826 329,166,344M
2860 329,166,344M
2869 329,166,344M
2870 329,166,344M
2871 329,166,344M
2877 329,166,344M
2878 329,166,344M
2879 329,166,344M
2880 329,166,344M
2881 329,166,344M
2927 329,166,344M
2928 329,166,344M
2929 329,166,344M
2935 329,166,344M
2936 329,166,344M
3011 329,166,344M
3012 329,166,344M
3013 329,166,344M
3014 329,166,344M
3015 166,329,344M
3021 329,166,344M
3022 166,329,344M
3023 329,166,344M
3024 166,329,344M
3026 329,166,344M
3029 166,329,344M
3030 329,166,344M
3060 329,166,344M
3061 329,166,344M
3090 329,166,344M
3091 329,166,344M
3092 329,166,344M
3093 329,166,344M
3094 329,166,344M
3099 329,166,344M
3100 329,166,344M
3140 329,166,344M
3141 329,166,344M
3160 329,166,344M
3161 329,166,344M
3164 329,166,344M
3165 329,166,344M
3366 329,166,344M
3367 329,166,344M
3373 329,166,344M
3404 329,166,344M
3405 329,166,344M
3548 329,166,344M
3549 329,166,344M
3663 329,166,344M
4124 329,166,344M
4125 166,329,344M
5126 329,166,344M
5129 329,166,344M
5133 329,166,344M
5135 329,166,344M
5151 329,166,344M
5153 329,166,344M
7871 344M
7872 344M
7873 344M
7874 344M
7875 344M
7876 344M
7877 344M
8703 344M
8704 344M
8705 344M
8706 344M
10454 344M
10455 344M