MySQL 8.0.26版本升級32版本查詢數(shù)據(jù)為空的解決方案
某業(yè)務(wù)系統(tǒng)將MySQL 8.0.26升級為GreatSQL 8.0.32-24 后,某些特定的SQL語句不能查詢到數(shù)據(jù)。經(jīng)測試 MySQL 8.0.32也存在相同的問題

此BUG已在 GreatSQL 8.0.32-25 版本中解決
MySQL 8.0.26版本升級32版本查詢數(shù)據(jù)為空的跟蹤
接到客戶反饋的問題后,對問題進(jìn)行了復(fù)現(xiàn)和分析。
版本信息
greatsql> select version(); +-----------+ | version() | +-----------+ | 8.0.32-24 | +-----------+ 1 row in set (0.00 sec)
建表語句
greatsql> show create table t_student; CREATE TABLE `t_student1` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `age` int NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
表數(shù)據(jù)
greatsql> select * from t_student; +----+--------+-----+ | id | name | age | +----+--------+-----+ | 1 | abc | 10 | | 2 | 湯姆 | 20 | +----+--------+-----+ 2 rows in set (0.08 sec)
查詢數(shù)據(jù)
greatsql> select * from (select * from t_student union select * from t_student) temp where name='湯姆'; Empty set, 2 warnings (0.00 sec) greatsql> show warnings; +---------+------+-------------------------------------------------------------------------+ | Level | Code | Message | +---------+------+-------------------------------------------------------------------------+ | Warning | 1300 | Cannot convert string '\xE6\xB1\xA4\xE5\xA7\x86' from utf8mb4 to binary | | Warning | 1300 | Cannot convert string '\xE6\xB1\xA4\xE5\xA7\x86' from utf8mb4 to binary | +---------+------+-------------------------------------------------------------------------+ 2 rows in set (0.00 sec) greatsql> select * from (select * from t_student union select * from t_student) temp; +----+--------+-----+ | id | name | age | +----+--------+-----+ | 1 | abc | 10 | | 2 | 湯姆 | 20 | +----+--------+-----+ 2 rows in set (0.00 sec) greatsql> select * from (select * from t_student union select * from t_student) temp where name='abc'; +----+------+-----+ | id | name | age | +----+------+-----+ | 1 | abc | 10 | +----+------+-----+ 1 row in set (0.00 sec)
可以看到 直接查詢temp這個view或者 在視圖上添加英文過濾條件均能查詢出數(shù)據(jù),在view上添加中文過濾條件sql語句返回結(jié)果為空,有warnings提醒,warnings具體內(nèi)容為Cannot convert string
在官方網(wǎng)站進(jìn)行搜索,以下連接有相似內(nèi)容:
https://bugs.mysql.com/bug.php?id=110228
https://bugs.mysql.com/bug.php?id=110955
MySQL 8.0.32版本中對于UNION/UNION ALL 后的結(jié)果中的字符串字段過濾篩選不生效,客戶端中提示:
Cannot convert string '%\x...' from utf8mb4 to binary
官方已確認(rèn)是8.0.32中的一個bug,已在8.0.33版本中修復(fù),對于8.0.32版本,官方給出的解決方式如下:
set optimizer_switch="derived_condition_pushdown=off";
讓所有Session都生效,需要在配置文件中將optimizer_switch設(shè)置為off
此BUG已在 GreatSQL 8.0.32-25 版本中解決
解決方法
方法一:
設(shè)置set optimizer_switch="derived_condition_pushdown=off";后SQL語句能正常執(zhí)行
greatsql> set optimizer_switch='derived_condition_pushdown=off'; Query OK, 0 rows affected (0.00 sec) greatsql> select * from (select * from t_student union select * from t_student) temp where name='湯姆'; +----+--------+-----+ | id | name | age | +----+--------+-----+ | 2 | 湯姆 | 20 | +----+--------+-----+ 1 row in set (0.00 sec)
方法二:
對單個SQL語句設(shè)置NO_DERIVED_CONDITION_PUSHDOWN hint
greatsql> set optimizer_switch='derived_condition_pushdown=on'; Query OK, 0 rows affected (0.00 sec) greatsql> select * from (select * from t_student union select * from t_student) temp where name='湯姆'; Empty set, 2 warnings (0.00 sec) greatsql> select /*+ NO_DERIVED_CONDITION_PUSHDOWN(temp) */ * from (select * from t_student union select * from t_student) temp where name='湯姆'; +----+--------+-----+ | id | name | age | +----+--------+-----+ | 2 | 湯姆 | 20 | +----+--------+-----+ 1 row in set (0.00 sec)
Enjoy GreatSQL ??
關(guān)于 GreatSQL
GreatSQL是適用于金融級應(yīng)用的國內(nèi)自主開源數(shù)據(jù)庫,具備高性能、高可靠、高易用性、高安全等多個核心特性,可以作為MySQL或Percona Server的可選替換,用于線上生產(chǎn)環(huán)境,且完全免費(fèi)并兼容MySQL或Percona Server。
相關(guān)鏈接: GreatSQL社區(qū) GiteeGitHubBilibili
GreatSQL社區(qū):
社區(qū)博客有獎?wù)鞲逶斍椋?a rel="external nofollow" target="_blank">https://greatsql.cn/thread-100-1-1.html
到此這篇關(guān)于MySQL 8.0.26版本升級32版本查詢數(shù)據(jù)為空的跟蹤的文章就介紹到這了,更多相關(guān)mysql查詢數(shù)據(jù)為空內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
mysql安裝出現(xiàn)Install/Remove of the Service D
這篇文章主要介紹了mysql安裝出現(xiàn)Install/Remove of the Service Denied!錯誤問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12
使用MySQL的geometry類型處理經(jīng)緯度距離問題的方法
這篇文章主要介紹了使用MySQL的geometry類型處理經(jīng)緯度距離問題的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-01-01
與MSSQL對比學(xué)習(xí)MYSQL的心得(六)--函數(shù)
這一節(jié)主要介紹MYSQL里的函數(shù),MYSQL里的函數(shù)很多,我這里主要介紹MYSQL里有而SQLSERVER沒有的函數(shù)2014-08-08
Workbench通過遠(yuǎn)程訪問mysql數(shù)據(jù)庫的方法詳解
這篇文章主要給大家介紹了Workbench通過遠(yuǎn)程訪問mysql數(shù)據(jù)庫的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。2017-06-06
MySQL表轉(zhuǎn)移數(shù)據(jù)的三種方式小結(jié)
本文主要介紹了MySQL表轉(zhuǎn)移數(shù)據(jù)的三種方式小結(jié),包括SQL命令,數(shù)據(jù)量不大的情況,直接使用SQL插入數(shù)據(jù)及使用Canal工具,具有一定的參考價(jià)值,感興趣的可以了解一下2025-02-02
mysql的自定義HINT語法實(shí)戰(zhàn)指南
SQL提示?(hint)是優(yōu)化數(shù)據(jù)庫的手段之一,使用它加入一些人為的提示來達(dá)到優(yōu)化操作的目的,這篇文章主要介紹了mysql自定義HINT語法的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2026-01-01
SQL HAVING子句在GROUP BY中的條件篩選靈活運(yùn)用
這篇文章主要為大家介紹了SQL HAVING子句在GROUP BY中的條件篩選靈活運(yùn)用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11
MySQL出現(xiàn)"Lock?wait?timeout?exceeded"錯誤的原因是什么詳解
這篇文章主要給大家介紹了關(guān)于MySQL出現(xiàn)"Lock?wait?timeout?exceeded"錯誤的原因是什么的相關(guān)資料,工作中同事遇到此異常,查找解決問題時,收集整理形成此篇文章,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-05-05

