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 (
    19134, 
    19300, 
    19139, 
    19079, 
    19151, 
    19294, 
    18489, 
    19220, 
    19187, 
    19069, 
    18910, 
    19203, 
    18825, 
    18997, 
    19254, 
    19233, 
    19102, 
    18896, 
    19065, 
    18840, 
    18638, 
    19105, 
    18995, 
    18506, 
    18660, 
    18845, 
    18882, 
    19111, 
    19330, 
    18835, 
    19373, 
    18990, 
    18570, 
    18643, 
    18634, 
    18960, 
    19342, 
    19214, 
    18899, 
    19189, 
    18942, 
    19175, 
    18967, 
    19211, 
    19033, 
    19040, 
    18587, 
    18876, 
    18696, 
    19185, 
    19083, 
    18936, 
    18934, 
    18781, 
    18832, 
    19397, 
    19341, 
    19382, 
    19252, 
    19277, 
    19331, 
    19086, 
    19171, 
    19167, 
    18888, 
    19030, 
    19399, 
    18972, 
    19113, 
    19328, 
    19148, 
    19289, 
    19060, 
    18984, 
    18938, 
    19353, 
    19346, 
    18884, 
    19183, 
    19094, 
    19325, 
    18564, 
    19169, 
    18518, 
    19351, 
    18779, 
    18850, 
    19058, 
    18861, 
    19359, 
    19292, 
    19261, 
    19141, 
    18805, 
    18951, 
    19074, 
    19302, 
    18599, 
    19027, 
    18836, 
    19315, 
    18787, 
    19024, 
    18798, 
    19244, 
    18903, 
    19192, 
    19032, 
    19072, 
    19303, 
    19051, 
    19163, 
    18962, 
    18878, 
    18911, 
    19082, 
    19298, 
    19339, 
    19223, 
    19275, 
    18855, 
    18496, 
    18565, 
    18793, 
    18954, 
    19020, 
    18927, 
    18958, 
    19055, 
    18843, 
    18906, 
    19123, 
    19311, 
    19119, 
    19200, 
    18947, 
    18588, 
    19372, 
    18821, 
    18873, 
    19198, 
    18875, 
    19272, 
    19168, 
    18823, 
    18901, 
    18555, 
    19129, 
    19202, 
    18837, 
    18956, 
    18886, 
    18905, 
    18869, 
    19282, 
    19159, 
    19264, 
    18671, 
    19237, 
    19259, 
    19251, 
    18512, 
    19078, 
    19047, 
    19266, 
    18999, 
    18784, 
    18790, 
    18930, 
    19310, 
    18913, 
    18791, 
    18894, 
    18914, 
    18964, 
    18918, 
    18827, 
    19242, 
    18987, 
    19004
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00450

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "328.21"
    },
    "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": 354,
            "rows_produced_per_join": 354,
            "filtered": "100.00",
            "index_condition": "(`chocoramo`.`cscart_products_categories`.`product_id` in (19134,19300,19139,19079,19151,19294,18489,19220,19187,19069,18910,19203,18825,18997,19254,19233,19102,18896,19065,18840,18638,19105,18995,18506,18660,18845,18882,19111,19330,18835,19373,18990,18570,18643,18634,18960,19342,19214,18899,19189,18942,19175,18967,19211,19033,19040,18587,18876,18696,19185,19083,18936,18934,18781,18832,19397,19341,19382,19252,19277,19331,19086,19171,19167,18888,19030,19399,18972,19113,19328,19148,19289,19060,18984,18938,19353,19346,18884,19183,19094,19325,18564,19169,18518,19351,18779,18850,19058,18861,19359,19292,19261,19141,18805,18951,19074,19302,18599,19027,18836,19315,18787,19024,18798,19244,18903,19192,19032,19072,19303,19051,19163,18962,18878,18911,19082,19298,19339,19223,19275,18855,18496,18565,18793,18954,19020,18927,18958,19055,18843,18906,19123,19311,19119,19200,18947,18588,19372,18821,18873,19198,18875,19272,19168,18823,18901,18555,19129,19202,18837,18956,18886,18905,18869,19282,19159,19264,18671,19237,19259,19251,18512,19078,19047,19266,18999,18784,18790,18930,19310,18913,18791,18894,18914,18964,18918,18827,19242,18987,19004))",
            "cost_info": {
              "read_cost": "168.91",
              "eval_cost": "35.40",
              "prefix_cost": "204.31",
              "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": [
              "chocoramo.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 17,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "88.50",
              "eval_cost": "1.77",
              "prefix_cost": "328.21",
              "data_read_per_join": "59K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`chocoramo`.`cscart_categories`.`storefront_id` in (0,1)) and ((`chocoramo`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`chocoramo`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`chocoramo`.`cscart_categories`.`usergroup_ids`))) and (`chocoramo`.`cscart_categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
18489 721,673M
18496 721,673M
18506 722,705M
18512 710,673M
18518 717,673M
18555 723,673M
18564 713,673M
18565 716,673M
18570 713,673M
18587 721,673M
18588 712,673M
18599 721,673M
18634 721,673M
18638 716,673M
18643 713,673M
18660 716,673M
18671 713,673M
18696 721,673M
18779 713,673M
18781 718,673M
18784 722,673M
18787 721,673M
18790 716,673M
18791 713,673M
18793 712,673M
18798 714,673M
18805 723,673M
18821 723,707M
18823 713,673M
18825 721,673M
18827 725,673M
18832 825,673M
18835 719,673M
18836 726,673M
18837 722,673M
18840 715,673M
18843 709,673M
18845 713,673M
18850 724,673M
18855 709,673M
18861 712,707M
18869 721,673M
18873 725,673M
18875 712,673M
18876 718,673M
18878 724,673M
18882 825,673M
18884 718,673M
18886 712,673M
18888 709,673M
18894 723,673M
18896 709,673M
18899 723,673M
18901 713,673M
18903 713,673M
18905 709,707M
18906 723,673M
18910 721,673M
18911 721,673M
18913 725,707M
18914 715,673M
18918 723,673M
18927 709,673M
18930 724,673M
18934 724,673M
18936 723,673M
18938 825,673M
18942 713,673M
18947 721,707M
18951 709,673M
18954 709,673M
18956 716,673M
18958 709,673M
18960 709,707M
18962 709,673M
18964 710,673M
18967 723,673M
18972 712,673M
18984 713,673M
18987 713,673M
18990 713,673M
18995 724,673M
18997 712,673M
18999 722,673M
19004 725,673M
19020 722,673M
19024 726,673M
19027 712,673M
19030 724,673M
19032 722,707M
19033 724,673M
19040 723,673M
19047 709,1821M
19051 722,673M
19055 721,673M
19058 714,673M
19060 724,673M
19065 722,673M
19069 721,673M
19072 725,673M
19074 723,673M
19078 715,673M
19079 722,673M
19082 717,673M
19083 715,673M
19086 719,673M
19094 721,673M
19102 713,673M
19105 721,673M
19111 724,673M
19113 712,673M
19119 710,673M
19123 724,673M
19129 710,673M
19134 726,673M
19139 713,673M
19141 723,673M
19148 721,673M
19151 721,673M
19159 710,673M
19163 721,673M
19167 716,673M
19168 717,673M
19169 724,673M
19171 721,673M
19175 722,673M
19183 723,673M
19185 712,673M
19187 724,673M
19189 825,673M
19192 723,673M
19198 712,707M
19200 726,673M
19202 717,673M
19203 723,673M
19211 721,673M
19214 724,673M
19220 712,673M
19223 713,707M
19233 725,673M
19237 724,673M
19242 720,673M
19244 712,673M
19251 723,673M
19252 721,673M
19254 716,673M
19259 721,673M
19261 712,673M
19264 722,673M
19266 724,673M
19272 723,673M
19275 713,673M
19277 723,673M
19282 710,673M
19289 721,673M
19292 725,673M
19294 722,673M
19298 725,707M
19300 712,673M
19302 714,673M
19303 723,673M
19310 710,673M
19311 712,673M
19315 717,673M
19325 724,673M
19328 721,673M
19330 713,673M
19331 721,673M
19339 825,673M
19341 725,673M
19342 725,673M
19346 717,673M
19351 725,673M
19353 722,673M
19359 716,673M
19372 721,673M
19373 721,673M
19382 712,673M
19397 713,673M
19399 726,673M