From 5bffb50d596bfb37ff89dac89c904d872643a1f6 Mon Sep 17 00:00:00 2001 From: augety Date: Mon, 12 Jun 2023 15:03:26 +0800 Subject: [PATCH] fix(tianmu): fix when using where to filter hexadecimal format data, return incorrect(#1625) `Item_hex_string` will be transformed to `Item_int` here eventually leading to wrong type of item in evaluation. Only `Item_hex_string` and Comparison context is `REAL_RESULT` need transformation. --- .../suite/tianmu/r/insert_update.result | 9 +++++++- mysql-test/suite/tianmu/r/issue1625.result | 14 +++++++++++++ mysql-test/suite/tianmu/r/update_v1.result | 4 ++-- mysql-test/suite/tianmu/t/insert_update.test | 6 +++++- mysql-test/suite/tianmu/t/issue1625.test | 21 +++++++++++++++++++ storage/tianmu/core/query.cpp | 3 +-- 6 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 mysql-test/suite/tianmu/r/issue1625.result create mode 100644 mysql-test/suite/tianmu/t/issue1625.test diff --git a/mysql-test/suite/tianmu/r/insert_update.result b/mysql-test/suite/tianmu/r/insert_update.result index 9af1e74c6..a1f8b532a 100644 --- a/mysql-test/suite/tianmu/r/insert_update.result +++ b/mysql-test/suite/tianmu/r/insert_update.result @@ -126,14 +126,21 @@ Warning 3135 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' Warning 3090 Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release. INSERT INTO t_latin1 values(x'f242', x'f242', x'f242'); UPDATE t_latin1 SET a=x'f343' where a=x'f242'; +select * from t_latin1; +a b c +óC òB òB INSERT INTO t_gb2312 values(x'e5ac', x'e5ac', x'e5ac'); UPDATE t_gb2312 SET a=x'e6af' where a=x'e5ac'; +select * from t_gb2312; +a b c +? ? ? INSERT INTO t_utf8 values(x'e4b8ad', x'e4b8ad', x'e4b8ad'); INSERT INTO t_utf8 values(x'f4b8ad', x'f4b8ad', x'f4b8ad'); ERROR HY000: Incorrect string value: '\xF4\xB8\xAD' for column 'a' at row 1 UPDATE t_utf8 SET a=x'e69687' where a=x'e4b8ad'; -UPDATE t_utf8 SET a=x'f69687' where a=x'e69687'; select * from t_utf8; a b c ? ? ? +UPDATE t_utf8 SET a=x'f69687' where a=x'e69687'; +ERROR HY000: Incorrect string value: '\xF6\x96\x87' for column 'a' at row 1 DROP DATABASE insert_update_db; diff --git a/mysql-test/suite/tianmu/r/issue1625.result b/mysql-test/suite/tianmu/r/issue1625.result new file mode 100644 index 000000000..793124292 --- /dev/null +++ b/mysql-test/suite/tianmu/r/issue1625.result @@ -0,0 +1,14 @@ +DROP DATABASE IF EXISTS issue1625_test; +create database issue1625_test; +use issue1625_test; +CREATE TABLE t_latin1( +a CHAR(20) CHARACTER SET latin1, +b VARCHAR(20) CHARACTER SET latin1, +c TEXT(20) CHARACTER SET latin1 +)engine=tianmu; +INSERT INTO t_latin1 values(x'f242', x'f242', x'f242'); +select * from t_latin1 where a=x'f242'; +a b c +òB òB òB +DROP TABLE t_latin1; +drop database issue1625_test; diff --git a/mysql-test/suite/tianmu/r/update_v1.result b/mysql-test/suite/tianmu/r/update_v1.result index 2b2db54bf..6c0542382 100644 --- a/mysql-test/suite/tianmu/r/update_v1.result +++ b/mysql-test/suite/tianmu/r/update_v1.result @@ -259,7 +259,7 @@ id token UPDATE t1 SET token = NULL WHERE token = X'ad'; SELECT * FROM t1; id token -1 ­ -2 ­ +1 NULL +2 NULL DROP TABLE t1; DROP DATABASE update_v1_db; diff --git a/mysql-test/suite/tianmu/t/insert_update.test b/mysql-test/suite/tianmu/t/insert_update.test index 3d48cee79..06701f350 100644 --- a/mysql-test/suite/tianmu/t/insert_update.test +++ b/mysql-test/suite/tianmu/t/insert_update.test @@ -126,14 +126,18 @@ CREATE TABLE t_utf8( SET SQL_MODE="STRICT_TRANS_TABLES"; INSERT INTO t_latin1 values(x'f242', x'f242', x'f242'); UPDATE t_latin1 SET a=x'f343' where a=x'f242'; +select * from t_latin1; INSERT INTO t_gb2312 values(x'e5ac', x'e5ac', x'e5ac'); UPDATE t_gb2312 SET a=x'e6af' where a=x'e5ac'; +select * from t_gb2312; INSERT INTO t_utf8 values(x'e4b8ad', x'e4b8ad', x'e4b8ad'); --disable_abort_on_error INSERT INTO t_utf8 values(x'f4b8ad', x'f4b8ad', x'f4b8ad'); --enable_abort_on_error UPDATE t_utf8 SET a=x'e69687' where a=x'e4b8ad'; -UPDATE t_utf8 SET a=x'f69687' where a=x'e69687'; select * from t_utf8; +--disable_abort_on_error +UPDATE t_utf8 SET a=x'f69687' where a=x'e69687'; +--enable_abort_on_error # Clean UP DROP DATABASE insert_update_db; diff --git a/mysql-test/suite/tianmu/t/issue1625.test b/mysql-test/suite/tianmu/t/issue1625.test new file mode 100644 index 000000000..23ef8c8b5 --- /dev/null +++ b/mysql-test/suite/tianmu/t/issue1625.test @@ -0,0 +1,21 @@ +--source include/have_tianmu.inc + +--disable_warnings +DROP DATABASE IF EXISTS issue1625_test; +--enable_warnings + +create database issue1625_test; +use issue1625_test; + +CREATE TABLE t_latin1( +a CHAR(20) CHARACTER SET latin1, +b VARCHAR(20) CHARACTER SET latin1, +c TEXT(20) CHARACTER SET latin1 +)engine=tianmu; + +INSERT INTO t_latin1 values(x'f242', x'f242', x'f242'); + +select * from t_latin1 where a=x'f242'; + +DROP TABLE t_latin1; +drop database issue1625_test; \ No newline at end of file diff --git a/storage/tianmu/core/query.cpp b/storage/tianmu/core/query.cpp index 3cb2f877e..f298a1bd4 100644 --- a/storage/tianmu/core/query.cpp +++ b/storage/tianmu/core/query.cpp @@ -1103,7 +1103,6 @@ QueryRouteTo Query::Item2CQTerm(Item *an_arg, CQTerm &term, const TabID &tmp_tab return QueryRouteTo::kToTianmu; } else { // WHERE FILTER - AttrID vc; AttrID col; TabID tab; @@ -1117,7 +1116,7 @@ QueryRouteTo Query::Item2CQTerm(Item *an_arg, CQTerm &term, const TabID &tmp_tab phys2virt.insert(std::make_pair(std::pair(tab.n, col.n), phys_vc)); } vc.n = phys_vc.second; - } else if (an_arg->type() == Item::VARBIN_ITEM) { + } else if (an_arg->type() == Item::VARBIN_ITEM && an_arg->cmp_context == REAL_RESULT) { String str; an_arg->val_str(&str); // sets null_value if (!an_arg->null_value) {