SELECT 
  products_categories.product_id, 
  GROUP_CONCAT(
    IF(
      products_categories.link_type = "M", 
      CONCAT(
        products_categories.category_id, 
        "M"
      ), 
      products_categories.category_id
    )
  ) AS category_ids 
FROM 
  products_categories 
  INNER JOIN categories ON categories.category_id = products_categories.category_id 
  AND categories.storefront_id IN (0, 1) 
  AND (
    categories.usergroup_ids = '' 
    OR FIND_IN_SET(0, categories.usergroup_ids) 
    OR FIND_IN_SET(1, categories.usergroup_ids)
  ) 
  AND categories.status IN ('A', 'H') 
WHERE 
  products_categories.product_id IN (
    283106, 283123, 283129, 289266, 291486, 
    306655, 282371, 282946, 282977, 282989, 
    283048, 283058, 283139, 289286, 289289, 
    289300, 282362, 282379, 282895, 282912, 
    282922, 282959, 283047, 283086, 291454, 
    282370, 282934, 282944, 282951, 282964, 
    283003, 283005, 283019, 283031, 283071, 
    283075, 283135, 283137, 283154, 289293, 
    291446, 291500, 282353, 282366, 282369, 
    282916, 282937, 282950, 282962, 282978, 
    283028, 283045, 283073, 283078, 283104, 
    283110, 283127, 283153, 289261, 282372, 
    282906, 282945, 282970, 282986, 283059, 
    283112, 283147, 283155, 289215, 289284, 
    291448, 291481, 282896, 282919, 283027, 
    283092, 283102, 283133, 291461, 291496, 
    306662, 282355, 282374, 282902, 282967, 
    282995, 282996, 283036, 283130, 289269, 
    291447, 291489, 282367, 282894, 282981, 
    283008
  ) 
GROUP BY 
  products_categories.product_id

Query time 0.00267

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "158.78"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "link_type",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 288,
            "rows_produced_per_join": 288,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "29.18",
              "eval_cost": "28.80",
              "prefix_cost": "57.98",
              "data_read_per_join": "4K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`goimagine`.`products_categories`.`product_id` in (283106,283123,283129,289266,291486,306655,282371,282946,282977,282989,283048,283058,283139,289286,289289,289300,282362,282379,282895,282912,282922,282959,283047,283086,291454,282370,282934,282944,282951,282964,283003,283005,283019,283031,283071,283075,283135,283137,283154,289293,291446,291500,282353,282366,282369,282916,282937,282950,282962,282978,283028,283045,283073,283078,283104,283110,283127,283153,289261,282372,282906,282945,282970,282986,283059,283112,283147,283155,289215,289284,291448,291481,282896,282919,283027,283092,283102,283133,291461,291496,306662,282355,282374,282902,282967,282995,282996,283036,283130,289269,291447,291489,282367,282894,282981,283008))"
          }
        },
        {
          "table": {
            "table_name": "categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "goimagine.products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 14,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "72.00",
              "eval_cost": "1.44",
              "prefix_cost": "158.78",
              "data_read_per_join": "37K"
            },
            "used_columns": [
              "category_id",
              "usergroup_ids",
              "status",
              "storefront_id"
            ],
            "attached_condition": "((`goimagine`.`categories`.`storefront_id` in (0,1)) and ((`goimagine`.`categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`goimagine`.`categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`goimagine`.`categories`.`usergroup_ids`))) and (`goimagine`.`categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
282353 6534,20906,2566M
282355 6534,20915,2566M
282362 6534,20910,2566M
282366 6534,20899,2566M
282367 6534,20907,2566M
282369 6534,20894,20907,2566M
282370 6534,20916,2566M
282371 6534,20918,2566M
282372 6534,20881,2566M
282374 6534,20907,2566M
282379 6534,20880,2566M
282894 6534,20899,2566M
282895 6534,20899,2566M
282896 6534,20899,2566M
282902 6534,20899,2566M
282906 6534,20899,2566M
282912 6534,20899,2566M
282916 6534,20899,2566M
282919 6534,20899,2566M
282922 6534,20899,2566M
282934 6534,20899,2566M
282937 6534,20899,2566M
282944 6534,2566M
282945 6534,20899,2566M
282946 6534,20899,2566M
282950 6534,20899,2566M
282951 6534,20899,2566M
282959 6534,20899,2566M
282962 6534,20899,2566M
282964 6534,20899,2566M
282967 6534,20899,2566M
282970 6534,20899,2566M
282977 6534,20899,2566M
282978 6534,20899,2566M
282981 6534,20899,2566M
282986 6534,20899,2566M
282989 6534,20899,2566M
282995 6534,20899,2566M
282996 6534,20899,2566M
283003 6534,20899,2566M
283005 6534,20899,2566M
283008 6534,20899,2566M
283019 6534,20899,2566M
283027 6534,20899,2566M
283028 6534,20899,2566M
283031 6534,20899,2566M
283036 6534,20899,2566M
283045 6534,20899,2566M
283047 6534,20899,2566M
283048 6534,20899,2566M
283058 6534,20899,2566M
283059 6534,20899,2566M
283071 6534,20899,2566M
283073 6534,20899,2566M
283075 6534,20899,2566M
283078 6534,20899,2566M
283086 6534,20899,2566M
283092 6534,20899,2566M
283102 6534,20899,2566M
283104 6534,20899,2566M
283106 6534,20899,2566M
283110 6534,20899,2566M
283112 6534,20899,2566M
283123 6534,20899,2566M
283127 6534,20899,2566M
283129 6534,20899,2566M
283130 6534,20899,2566M
283133 6534,20899,2566M
283135 6534,20899,2566M
283137 6534,20899,2566M
283139 6534,20899,2566M
283147 6534,20899,2566M
283153 6534,20899,2566M
283154 6534,20899,2566M
283155 6534,20899,2566M
289215 6534,20889,2566M
289261 6534,20889,2566M
289266 6534,20889,2566M
289269 6534,20889,2566M
289284 6534,20889,2566M
289286 6534,20889,2566M
289289 6534,20889,2566M
289293 6534,20889,2566M
289300 6534,20889,2566M
291446 6534,20915,2566M
291447 6534,20895,2566M
291448 6534,20895,2566M
291454 6534,20894,2566M
291461 6534,20886,2566M
291481 6534,20895,2566M
291486 6534,20896,2566M
291489 6534,20887,2566M
291496 6534,20900,2566M
291500 6534,20904,2566M
306655 6534,20895,2566M
306662 6534,20895,2566M