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 (
    1003, 1001, 1000, 508, 1139, 1138, 1137, 
    1136, 1135, 1134, 1133, 1132, 1131, 
    1130, 1129, 827, 1406, 1407, 1408, 1409, 
    1410, 1411, 1412, 1266, 1442, 1447, 
    2490, 2491, 2492, 2493, 2494, 2495, 
    2496, 2497, 2524, 2525, 2526, 2527, 
    2528, 2529, 2530, 2531, 2698, 3090, 
    3091, 3092, 3093, 3094, 3974, 3977, 
    3976, 3975, 3973, 3972, 3978, 3979, 
    4022, 4021, 4020, 4420, 4423, 4426, 
    4416, 5618, 5619, 5620, 5621, 5696, 
    5697, 5698, 5699, 5721, 5722, 5723, 
    5724, 5725, 5726
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00375

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "173.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": 193,
            "rows_produced_per_join": 193,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (1003,1001,1000,508,1139,1138,1137,1136,1135,1134,1133,1132,1131,1130,1129,827,1406,1407,1408,1409,1410,1411,1412,1266,1442,1447,2490,2491,2492,2493,2494,2495,2496,2497,2524,2525,2526,2527,2528,2529,2530,2531,2698,3090,3091,3092,3093,3094,3974,3977,3976,3975,3973,3972,3978,3979,4022,4021,4020,4420,4423,4426,4416,5618,5619,5620,5621,5696,5697,5698,5699,5721,5722,5723,5724,5725,5726))",
            "cost_info": {
              "read_cost": "86.81",
              "eval_cost": "19.30",
              "prefix_cost": "106.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": 9,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "48.25",
              "eval_cost": "0.97",
              "prefix_cost": "173.66",
              "data_read_per_join": "30K"
            },
            "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
508 234,166,235M
827 166,322,323M
1000 166,234,235M
1001 234,166,235M
1003 166,234,235M
1129 166,322,323M
1130 166,322,323M
1131 166,322,323M
1132 166,322,323M
1133 166,322,323M
1134 322,166,323M
1135 166,322,323M
1136 166,322,323M
1137 166,322,323M
1138 166,322,323M
1139 166,322,323M
1266 234,166,326M
1406 234,166,326M
1407 234,166,326M
1408 234,166,326M
1409 234,166,326M
1410 234,166,326M
1411 234,166,326M
1412 234,166,326M
1442 234,166,326M
1447 234,166,326M
2490 166,234,236M
2491 166,234,236M
2492 166,234,236M
2493 166,234,236M
2494 166,234,236M
2495 166,234,236M
2496 166,234,236M
2497 166,234,236M
2524 166,234,236M
2525 234,166,236M
2526 234,166,236M
2527 234,166,236M
2528 234,166,236M
2529 234,166,236M
2530 234,166,236M
2531 234,166,236M
2698 450,424,423,166M
3090 329,166,344M
3091 329,166,344M
3092 329,166,344M
3093 329,166,344M
3094 329,166,344M
3972 166,167,356M
3973 167,166,356M
3974 167,166,356M
3975 167,166,356M
3976 167,166,356M
3977 167,166,356M
3978 167,166,356M
3979 167,166,356M
4020 167,166,356M
4021 167,166,356M
4022 167,166,356M
4416 320,166,321M
4420 320,166,321M
4423 320,166,321M
4426 320,166,321M
5618 423,449,166M
5619 423,449,166M
5620 423,449,166M
5621 423,449,166M
5696 423,449,166M
5697 423,449,166M
5698 423,449,166M
5699 423,449,166M
5721 423,585,166M
5722 423,585,166M
5723 423,585,166M
5724 423,585,166M
5725 423,585,166M
5726 423,585,166M