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, 2729, 2730, 2731, 
    2732, 2746, 2747, 2749, 2750, 2751, 
    2752, 2753, 2754, 2755, 2756, 2757, 
    2822, 2823, 2824, 2825, 2826, 2869, 
    2870, 2871, 2927, 2928, 2929, 3026, 
    3030, 3029, 3090, 3091, 3092, 3093, 
    3094, 3140, 3141
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00331

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "155.36"
    },
    "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": 172,
            "rows_produced_per_join": 172,
            "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,2729,2730,2731,2732,2746,2747,2749,2750,2751,2752,2753,2754,2755,2756,2757,2822,2823,2824,2825,2826,2869,2870,2871,2927,2928,2929,3026,3030,3029,3090,3091,3092,3093,3094,3140,3141))",
            "cost_info": {
              "read_cost": "77.96",
              "eval_cost": "17.20",
              "prefix_cost": "95.16",
              "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": "43.00",
              "eval_cost": "0.86",
              "prefix_cost": "155.36",
              "data_read_per_join": "26K"
            },
            "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
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
2822 329,166,344M
2823 329,166,344M
2824 329,166,344M
2825 329,166,344M
2826 329,166,344M
2869 329,166,344M
2870 329,166,344M
2871 329,166,344M
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
3140 329,166,344M
3141 329,166,344M
3663 329,166,344M