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 (
    599, 600, 601, 602, 603, 604, 605, 606, 
    675, 676, 677, 911, 912, 914, 915, 916, 
    917, 918, 919, 920, 921, 922, 923, 924, 
    925, 926, 927, 928, 929, 930, 931, 596, 
    597, 672, 673, 674, 678, 679, 680, 880, 
    881, 882, 883, 890, 891, 892, 893, 896, 
    897, 898, 899, 900, 901, 902, 903, 904, 
    905, 906, 907, 934, 935, 937, 938, 939, 
    940
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00165

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "113.15"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "9.06"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 125,
            "rows_produced_per_join": 5,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "29.49",
              "eval_cost": "1.00",
              "prefix_cost": "30.49",
              "data_read_per_join": "20K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`cscart`.`cscart_categories`.`storefront_id` in (0,1)) and ((`cscart`.`cscart_categories`.`usergroup_ids` = '') or find_in_set(0,`cscart`.`cscart_categories`.`usergroup_ids`) or find_in_set(1,`cscart`.`cscart_categories`.`usergroup_ids`)) and (`cscart`.`cscart_categories`.`status` in ('A','H')))"
          }
        },
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "cscart.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 12,
            "rows_produced_per_join": 9,
            "filtered": "15.10",
            "index_condition": "(`cscart`.`cscart_products_categories`.`product_id` in (599,600,601,602,603,604,605,606,675,676,677,911,912,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,930,931,596,597,672,673,674,678,679,680,880,881,882,883,890,891,892,893,896,897,898,899,900,901,902,903,904,905,906,907,934,935,937,938,939,940))",
            "cost_info": {
              "read_cost": "61.60",
              "eval_cost": "1.81",
              "prefix_cost": "104.09",
              "data_read_per_join": "144"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
596 303,326,304M
597 303,326,304M
599 329,305,303M
600 329,305,303M
601 303,329,305M
602 305M,303,329
603 329,305M,303
604 329,305M,303
605 329,305,303M
606 329,305,303M
672 303,326,304M
673 326,304M,303
674 326,304M,303
675 303M,329,305
676 305,303M,329
677 329,305,303M
678 315,317,303M
679 317,303M,315
680 317,303M,315
880 315,317M,303
881 315,317M,303
882 315,318M,303
883 315,318M,303
890 321M,303,316
891 321M,303,316
892 322M,303,304
893 322M,303,304
896 322M,303,304
897 322M,303,304
898 303,304,322M
899 322M,303,304
900 322,303,304M
901 322,303,304M
902 325M,303,304
903 325M,303,304
904 325M,303,304
905 325M,303,304
906 325M,303,304
907 325M,303,304
911 327M,305,303
912 327M,305,303
914 327M,305,303
915 303,327M,305
916 303,327M,305
917 327M,305,303
918 327M,305,303
919 327M,305,303
920 327M,305,303
921 327M,305,303
922 303,328M,305
923 328M,305,303
924 328M,305,303
925 328M,305,303
926 329M,305,303
927 329M,305,303
928 303,329M,305
929 305,303,329M
930 305,303,329M
931 329M,305,303
934 330M,314,303
935 330M,314,303
937 303,332M,314
938 314,303,332M
939 314,303,332M
940 314,303,332M