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 (
    12259, 12260, 12261, 12262, 12263, 12264, 
    12265, 12266, 12267, 12268, 12269, 
    12270, 12271, 12272, 12273, 12274, 
    12275, 12276, 12277, 12278, 12279, 
    12280, 12281, 12282, 12283, 12284, 
    12285, 12286, 12287, 12288, 12289, 
    12290, 12291, 12292, 12293, 12294, 
    12295, 12296, 12297, 12298, 12299, 
    12300, 12301, 12302, 12303, 12304, 
    12305, 12306, 12307, 12308, 12309, 
    12310, 12311, 12312, 12313, 12314, 
    12315, 12316, 12317, 12318, 12319, 
    12320, 12321, 12322, 12323, 12324, 
    12325, 12326, 12327, 12328, 12329, 
    12330, 12331, 12332, 12333, 12334, 
    12335, 12336, 12337, 12338, 12339, 
    12340, 12341, 12342, 12343, 12344, 
    12345, 12346, 12347, 12348
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00266

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "60.67"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.89"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 46,
            "rows_produced_per_join": 1,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "5.15",
              "eval_cost": "0.18",
              "prefix_cost": "5.33",
              "data_read_per_join": "7K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`test2_gaseus`.`cscart_categories`.`storefront_id` in (0,1)) and ((`test2_gaseus`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`test2_gaseus`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`test2_gaseus`.`cscart_categories`.`usergroup_ids`))) and (`test2_gaseus`.`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": [
              "test2_gaseus.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 83,
            "rows_produced_per_join": 1,
            "filtered": "1.24",
            "index_condition": "(`test2_gaseus`.`cscart_products_categories`.`product_id` in (12259,12260,12261,12262,12263,12264,12265,12266,12267,12268,12269,12270,12271,12272,12273,12274,12275,12276,12277,12278,12279,12280,12281,12282,12283,12284,12285,12286,12287,12288,12289,12290,12291,12292,12293,12294,12295,12296,12297,12298,12299,12300,12301,12302,12303,12304,12305,12306,12307,12308,12309,12310,12311,12312,12313,12314,12315,12316,12317,12318,12319,12320,12321,12322,12323,12324,12325,12326,12327,12328,12329,12330,12331,12332,12333,12334,12335,12336,12337,12338,12339,12340,12341,12342,12343,12344,12345,12346,12347,12348))",
            "cost_info": {
              "read_cost": "38.18",
              "eval_cost": "0.19",
              "prefix_cost": "58.78",
              "data_read_per_join": "30"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
12259 306M
12260 306M
12261 306M
12262 306M
12263 306M
12264 306M
12265 306M
12266 306M
12267 306M
12268 306M
12269 306M
12270 306M
12271 306M
12272 306M
12273 306M
12274 306M
12275 306M
12276 306M
12277 306M
12278 306M
12279 306M
12280 306M
12281 306M
12282 306M
12283 306M
12284 306M
12285 306M
12286 306M
12287 306M
12288 306M
12289 306M
12290 306M
12291 306M
12292 306M
12293 306M
12294 306M
12295 306M
12296 306M
12297 306M
12298 306M
12299 306M
12300 306M
12301 306M
12302 306M
12303 306M
12304 306M
12305 306M
12306 306M
12307 306M
12308 306M
12309 306M
12310 306M
12311 306M
12312 306M
12313 306M
12314 306M
12315 306M
12316 306M
12317 306M
12318 306M
12319 306M
12320 306M
12321 306M
12322 306M
12323 306M
12324 306M
12325 306M
12326 306M
12327 306M
12328 306M
12329 306M
12330 306M
12331 306M
12332 306M
12333 306M
12334 306M
12335 306M
12336 306M
12337 306M
12338 306M
12339 306M
12340 306M
12341 306M
12342 306M
12343 306M
12344 306M
12345 306M
12346 306M
12347 306M
12348 306M