From 70f4332beac65359d23733cc179c5c3cc689ef95 Mon Sep 17 00:00:00 2001 From: casazhang Date: Mon, 19 Sep 2022 19:11:28 +0800 Subject: [PATCH] [bugfix] gtid_subset should reset null_value to false. gtid_subset should reset null_value to false, otherwise records will be lost when scanning multiple records. --- mysql-test/suite/json/inc/json_functions.inc | 14 ++++++++++++++ .../suite/json/r/json_functions_innodb.result | 13 +++++++++++++ sql/item_func.cc | 18 ++++++++---------- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/mysql-test/suite/json/inc/json_functions.inc b/mysql-test/suite/json/inc/json_functions.inc index c0cec7b5fe3..2914835ea98 100644 --- a/mysql-test/suite/json/inc/json_functions.inc +++ b/mysql-test/suite/json/inc/json_functions.inc @@ -757,6 +757,20 @@ select json_extract(en, '$') from t1; drop table t1; +create table t1 ( c1 int, c2 text); + +insert into t1 values (1, '{\"time\":\"2022-09-18 17:18:12\"}'); +insert into t1 values (2, '{\"time\":\"2022-09-19 17:18:12\", \"gtid_set_column\":\"c55be2ea-14fc-12ec-a970-043f72e646cf:1-6667608119\"}'); +insert into t1 values (3, '{\"time\":\"2022-09-20 17:18:12\"}'); +insert into t1 values (4, '{\"time\":\"2022-09-21 17:18:12\", \"gtid_set_column\":\"c55be2ea-14fc-12ec-a970-043f72e646cf:1-6667608114\"}'); +insert into t1 values (5, '{\"time\":\"2022-09-22 17:18:12\"}'); +insert into t1 values (6, '{\"time\":\"2022-09-23 17:18:12\", \"gtid_set_column\":\"03465097-563b-12ec-a4cb-0c42a14d69f3:1-234648230\"}'); +insert into t1 values (7, '{\"time\":\"2022-09-24 17:18:12\"}'); + +select t1.c1 from t1 where gtid_subset(trim('"' from json_extract(t1.c2, '$.gtid_set_column')), "03465097-563b-12ec-a4cb-0c42a14d69f3:1-234648290") = 0; + +drop table t1; + create table t1 ( c1 varchar(200) character set 'latin1', c2 varchar(200) character set 'utf8' ); insert into t1 values ('[1,2]', # legal json, but not utf-8 diff --git a/mysql-test/suite/json/r/json_functions_innodb.result b/mysql-test/suite/json/r/json_functions_innodb.result index c2fa1dd9ede..36a81bd4b5b 100644 --- a/mysql-test/suite/json/r/json_functions_innodb.result +++ b/mysql-test/suite/json/r/json_functions_innodb.result @@ -5023,6 +5023,19 @@ cast(js as json) select json_extract(en, '$') from t1; ERROR 22032: Invalid data type for JSON data in argument 1 to function json_extract; a JSON string or JSON type is required. drop table t1; +create table t1 ( c1 int, c2 text); +insert into t1 values (1, '{\"time\":\"2022-09-18 17:18:12\"}'); +insert into t1 values (2, '{\"time\":\"2022-09-19 17:18:12\", \"gtid_set_column\":\"c55be2ea-14fc-12ec-a970-043f72e646cf:1-6667608119\"}'); +insert into t1 values (3, '{\"time\":\"2022-09-20 17:18:12\"}'); +insert into t1 values (4, '{\"time\":\"2022-09-21 17:18:12\", \"gtid_set_column\":\"c55be2ea-14fc-12ec-a970-043f72e646cf:1-6667608114\"}'); +insert into t1 values (5, '{\"time\":\"2022-09-22 17:18:12\"}'); +insert into t1 values (6, '{\"time\":\"2022-09-23 17:18:12\", \"gtid_set_column\":\"03465097-563b-12ec-a4cb-0c42a14d69f3:1-234648230\"}'); +insert into t1 values (7, '{\"time\":\"2022-09-24 17:18:12\"}'); +select t1.c1 from t1 where gtid_subset(trim('"' from json_extract(t1.c2, '$.gtid_set_column')), "03465097-563b-12ec-a4cb-0c42a14d69f3:1-234648290") = 0; +c1 +2 +4 +drop table t1; create table t1 ( c1 varchar(200) character set 'latin1', c2 varchar(200) character set 'utf8' ); insert into t1 values ('[1,2]', # legal json, but not utf-8 diff --git a/sql/item_func.cc b/sql/item_func.cc index db8d2c15ab8..044a47e6884 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -5167,21 +5167,19 @@ longlong Item_master_gtid_set_wait::val_int() longlong Item_func_gtid_subset::val_int() { DBUG_ENTER("Item_func_gtid_subset::val_int()"); - if (args[0]->null_value || args[1]->null_value) - { - null_value= true; - DBUG_RETURN(0); - } String *string1, *string2; const char *charp1, *charp2; int ret= 1; enum_return_status status; - // get strings without lock - if ((string1= args[0]->val_str(&buf1)) != NULL && - (charp1= string1->c_ptr_safe()) != NULL && - (string2= args[1]->val_str(&buf2)) != NULL && - (charp2= string2->c_ptr_safe()) != NULL) + null_value= false; + if ((string1 = args[0]->val_str(&buf1)) == NULL || + (string2 = args[1]->val_str(&buf2)) == NULL) { + null_value = true; + ret = 0; + } else if ((charp1= string1->c_ptr_safe()) != NULL && + (charp2= string2->c_ptr_safe()) != NULL) + { // get strings without lock Sid_map sid_map(NULL/*no rwlock*/); // compute sets while holding locks const Gtid_set sub_set(&sid_map, charp1, &status); -- 2.26.2