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 (
    1987, 
    2110, 
    2111, 
    2112, 
    1900, 
    1813, 
    1820, 
    2366, 
    1897, 
    1750, 
    1924, 
    2227, 
    2204, 
    2010, 
    2309, 
    2060, 
    2122, 
    2274, 
    2061, 
    1918, 
    1913, 
    1958, 
    2290, 
    1751, 
    1957, 
    2202, 
    1814, 
    2331, 
    1748, 
    2005, 
    2214, 
    2342, 
    2215, 
    2211, 
    2225, 
    2212, 
    2213, 
    2226, 
    2151, 
    1882, 
    1815, 
    1853, 
    1759, 
    2001, 
    2276, 
    2231, 
    2281, 
    2379, 
    2388, 
    2115, 
    1929, 
    2373, 
    2372, 
    2374, 
    1760, 
    1807, 
    1847, 
    2363, 
    1816, 
    2146, 
    2201, 
    2386, 
    2359, 
    2279, 
    1843, 
    1859, 
    1794, 
    1793, 
    1817, 
    1795, 
    2278, 
    1818, 
    1784, 
    1819, 
    1849, 
    2338, 
    2383, 
    2337, 
    2336, 
    2389, 
    1802, 
    1801, 
    1880, 
    1767, 
    2346, 
    2301, 
    2081, 
    1947, 
    2157, 
    2207, 
    2142, 
    2121, 
    2375, 
    2088, 
    2089, 
    2090, 
    2087, 
    2158, 
    1787, 
    2105, 
    2133, 
    2125, 
    2092, 
    2093, 
    2046, 
    2045, 
    2044, 
    2047, 
    2049, 
    2048, 
    1995, 
    1943, 
    2120, 
    2094, 
    2385, 
    1989, 
    2314, 
    1951, 
    2096, 
    1988, 
    2098, 
    2097, 
    2099, 
    2199, 
    2200, 
    1948, 
    2095, 
    2100, 
    2124, 
    2101, 
    2134, 
    2198, 
    2291, 
    2103, 
    2307, 
    2166, 
    2208, 
    2102, 
    2104, 
    2345, 
    2143, 
    2119, 
    2144, 
    2362, 
    2233, 
    2350, 
    2232, 
    2244, 
    2051, 
    1855, 
    2367, 
    1808, 
    1891, 
    1892, 
    2368, 
    2393, 
    1952, 
    1939, 
    1930, 
    1764
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00116

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "28.52"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "4.43"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 68,
            "rows_produced_per_join": 2,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "7.63",
              "eval_cost": "0.27",
              "prefix_cost": "7.91",
              "data_read_per_join": "9K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`cscartdevel`.`cscart_categories`.`storefront_id` in (0,1)) and ((`cscartdevel`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`cscartdevel`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`cscartdevel`.`cscart_categories`.`usergroup_ids`))) and (`cscartdevel`.`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": [
              "cscartdevel.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 17,
            "rows_produced_per_join": 4,
            "filtered": "9.59",
            "index_condition": "(`cscartdevel`.`cscart_products_categories`.`product_id` in (1987,2110,2111,2112,1900,1813,1820,2366,1897,1750,1924,2227,2204,2010,2309,2060,2122,2274,2061,1918,1913,1958,2290,1751,1957,2202,1814,2331,1748,2005,2214,2342,2215,2211,2225,2212,2213,2226,2151,1882,1815,1853,1759,2001,2276,2231,2281,2379,2388,2115,1929,2373,2372,2374,1760,1807,1847,2363,1816,2146,2201,2386,2359,2279,1843,1859,1794,1793,1817,1795,2278,1818,1784,1819,1849,2338,2383,2337,2336,2389,1802,1801,1880,1767,2346,2301,2081,1947,2157,2207,2142,2121,2375,2088,2089,2090,2087,2158,1787,2105,2133,2125,2092,2093,2046,2045,2044,2047,2049,2048,1995,1943,2120,2094,2385,1989,2314,1951,2096,1988,2098,2097,2099,2199,2200,1948,2095,2100,2124,2101,2134,2198,2291,2103,2307,2166,2208,2102,2104,2345,2143,2119,2144,2362,2233,2350,2232,2244,2051,1855,2367,1808,1891,1892,2368,2393,1952,1939,1930,1764))",
            "cost_info": {
              "read_cost": "11.56",
              "eval_cost": "0.44",
              "prefix_cost": "24.09",
              "data_read_per_join": "70"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
1748 324M
1750 299M
1751 313M
1759 388M
1760 303M
1764 404M
1767 404M
1784 388M
1787 389M
1793 388M
1794 388M
1795 388M
1801 303M
1802 303M
1807 303M
1808 303M
1813 404M
1814 324M
1815 388M
1816 303M
1817 388M
1818 388M
1819 303M
1820 303M
1843 388M
1847 303M
1849 303M
1853 388M
1855 303M
1859 388M
1880 303M
1882 388M
1891 303M
1892 303M
1897 303M
1900 404M
1913 299M
1918 299M
1924 403M
1929 299M
1930 299M
1939 306M
1943 389M
1947 389M
1948 389M
1951 389M
1952 306M
1957 324M
1958 396M
1987 394M
1988 389M
1989 389M
1995 389M
2001 388M
2005 324M
2010 313M
2044 389M
2045 389M
2046 389M
2047 389M
2048 389M
2049 389M
2051 313M
2060 324M
2061 324M
2081 389M
2087 389M
2088 389M
2089 389M
2090 389M
2092 389M
2093 389M
2094 389M
2095 389M
2096 389M
2097 389M
2098 389M
2099 389M
2100 389M
2101 389M
2102 389M
2103 389M
2104 389M
2105 389M
2110 394M
2111 394M
2112 394M
2115 299M
2119 389M
2120 389M
2121 389M
2122 324M
2124 389M
2125 389M
2133 389M
2134 389M
2142 389M
2143 389M
2144 389M
2146 313M
2151 313M
2157 389M
2158 389M
2166 389M
2198 389M
2199 389M
2200 389M
2201 313M
2202 299M
2204 313M
2207 389M
2208 389M
2211 324M
2212 324M
2213 324M
2214 324M
2215 324M
2225 324M
2226 324M
2227 324M
2231 313M
2232 313M
2233 313M
2244 313M
2274 324M
2276 401M
2278 401M
2279 401M
2281 389M
2290 313M
2291 389M
2301 389M
2307 389M
2309 405M
2314 389M
2331 324M
2336 392M
2337 392M
2338 392M
2342 324M
2345 389M
2346 389M
2350 299M
2359 390M
2362 389M
2363 303M
2366 362M
2367 362M
2368 362M
2372 362M
2373 362M
2374 362M
2375 389M
2379 389M
2383 392M
2385 389M
2386 390M
2388 299M
2389 313M
2393 393M