MySQL 匈牙利语字符的 ORDER BY 错误

MySQL wrong ORDER BY for hungarian characters

我运行以下查询:

SELECT name FROM shops ORDER BY name;

当前结果:

ABC shop
ÁDE shop
ALT shop

预期结果应为:

ABC shop
ALT shop
ÁDE shop

看起来 AÁ 相等。 (正确顺序:a < á < e < é < o < ó < ö...)

我尝试使用匈牙利语排序规则(mysql 8.0.17):

ALTER DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_hu_0900_ai_ci;

我发现 mysql 团队已经在 mysql 8.0.1 中解决了这个问题:https://bugs.mysql.com/bug.php?id=12519

显示创建 TABLE 家商店;

| shops | CREATE TABLE `shops` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `address_id` bigint(20) unsigned DEFAULT NULL,
  `shop_category_id` bigint(20) unsigned DEFAULT NULL,
  `shop_chain_id` bigint(20) unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `partner_id` bigint(20) unsigned DEFAULT NULL,
  `location_id` bigint(20) unsigned DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `user_id` bigint(20) unsigned DEFAULT NULL,
  `deputy_user_id` bigint(20) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `shops_address_id_foreign` (`address_id`),
  KEY `shops_shop_category_id_foreign` (`shop_category_id`),
  KEY `shops_shop_chain_id_foreign` (`shop_chain_id`),
  KEY `shops_partner_id_foreign` (`partner_id`),
  KEY `shops_location_id_foreign` (`location_id`),
  KEY `shops_user_id_foreign` (`user_id`),
  KEY `shops_deputy_user_id_foreign` (`deputy_user_id`),
  CONSTRAINT `shops_address_id_foreign` FOREIGN KEY (`address_id`) REFERENCES `addresses` (`id`) ON DELETE SET NULL,
  CONSTRAINT `shops_deputy_user_id_foreign` FOREIGN KEY (`deputy_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `shops_location_id_foreign` FOREIGN KEY (`location_id`) REFERENCES `locations` (`id`) ON DELETE SET NULL,
  CONSTRAINT `shops_partner_id_foreign` FOREIGN KEY (`partner_id`) REFERENCES `partners` (`id`) ON DELETE CASCADE,
  CONSTRAINT `shops_shop_category_id_foreign` FOREIGN KEY (`shop_category_id`) REFERENCES `shop_categories` (`id`) ON DELETE SET NULL,
  CONSTRAINT `shops_shop_chain_id_foreign` FOREIGN KEY (`shop_chain_id`) REFERENCES `shop_chains` (`id`) ON DELETE SET NULL,
  CONSTRAINT `shops_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=564 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_hu_0900_ai_ci 

没有简单的解决方案:

方案A:自己写整理。

B 计划:在 bugs.mysql.com 写一个错误,抱怨即使在 8.0.17 中,utf8mb4_hu_0900_ai_ci 也是 "incorrect"。

(同时,我怀疑 utf8mb4_hungarian_ci 保留了 5.7 排序规则以实现向后兼容性。)

问题本身就是错误的。预期结果是:

ABC shop
ÁDE shop
ALT shop

没错。

https://helyesiras.mta.hu/helyesiras/default/akh12#F2_4