Commit 43099af9 authored by Yongxin Xu's avatar Yongxin Xu Committed by GitHub

MDEV-24020: Trim with remove_str Fails on Spider

This patch fixes the bug that TRIM(BOTH ... FROM $str), TRIM(LEADING ... FROM $str),
and TRIM(TRAILING ... FROM $str) failed with errors when executing on Spider.
parent 6ed47508
--let $MASTER_1_COMMENT_P_2_1= $MASTER_1_COMMENT_P_2_1_BACKUP
--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP
--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP
--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP
--disable_warnings
--disable_query_log
--disable_result_log
--source ../t/test_deinit.inc
--enable_result_log
--enable_query_log
--enable_warnings
--disable_warnings
--disable_query_log
--disable_result_log
--source ../t/test_init.inc
--enable_result_log
--enable_query_log
--enable_warnings
--let $MASTER_1_COMMENT_P_2_1_BACKUP= $MASTER_1_COMMENT_P_2_1
let $MASTER_1_COMMENT_P_2_1=
PARTITION BY LIST(a % 3) (
PARTITION pt1 VALUES IN (0) COMMENT='srv "s_2_1", table "ta_r2"',
PARTITION pt2 VALUES IN (1) COMMENT='srv "s_2_1", table "ta_r3"',
PARTITION pt3 VALUES IN (2) COMMENT='srv "s_2_1", table "ta_r4"'
);
--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES
let $CHILD2_1_DROP_TABLES=
DROP TABLE IF EXISTS ta_r2 $STR_SEMICOLON
DROP TABLE IF EXISTS ta_r3 $STR_SEMICOLON
DROP TABLE IF EXISTS ta_r4;
--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES
let $CHILD2_1_CREATE_TABLES=
CREATE TABLE ta_r2 (
a INT,
b VARCHAR(30),
PRIMARY KEY(a)
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON
CREATE TABLE ta_r3 (
a INT,
b VARCHAR(30),
PRIMARY KEY(a)
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON
CREATE TABLE ta_r4 (
a INT,
b VARCHAR(30),
PRIMARY KEY(a)
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES
let $CHILD2_1_SELECT_TABLES=
SELECT a, b FROM ta_r2 ORDER BY a $STR_SEMICOLON
SELECT a, b FROM ta_r3 ORDER BY a $STR_SEMICOLON
SELECT a, b FROM ta_r4 ORDER BY a;
let $CHILD2_1_SELECT_ARGUMENT1=
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
for master_1
for child2
child2_1
child2_2
child2_3
for child3
this test is for MDEV-24020
drop and create databases
connection master_1;
CREATE DATABASE auto_test_local;
USE auto_test_local;
connection child2_1;
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
create table and insert
connection child2_1;
CHILD2_1_CREATE_TABLES
connection master_1;
CREATE TABLE tbl_a (
a INT,
b VARCHAR(30),
PRIMARY KEY(a)
) ENGINE=Spider PARTITION BY LIST(a % 3) (
PARTITION pt1 VALUES IN (0) COMMENT='srv "s_2_1", table "ta_r2"',
PARTITION pt2 VALUES IN (1) COMMENT='srv "s_2_1", table "ta_r3"',
PARTITION pt3 VALUES IN (2) COMMENT='srv "s_2_1", table "ta_r4"'
)
INSERT INTO tbl_a VALUES(10000, " abcd ");
INSERT INTO tbl_a VALUES(10001, " abcd ");
INSERT INTO tbl_a VALUES(10002, " abcd ");
INSERT INTO tbl_a VALUES(10003, "[[[abcd][[");
INSERT INTO tbl_a VALUES(10004, "[[[abcd][[");
INSERT INTO tbl_a VALUES(10005, "[[[abcd][[");
INSERT INTO tbl_a VALUES(10006, "[[[abcd]]");
INSERT INTO tbl_a VALUES(10007, "[[[abcd]]");
INSERT INTO tbl_a VALUES(10008, "[[[abcd]]");
INSERT INTO tbl_a VALUES(10009, "[[[**abcd****]]");
test 1
connection master_1;
UPDATE tbl_a SET b = trim(b) WHERE a = 10000;
SELECT * FROM tbl_a WHERE a = 10000;
a b
10000 abcd
UPDATE tbl_a SET b = ltrim(b) WHERE a = 10001;
SELECT * FROM tbl_a WHERE a = 10001;
a b
10001 abcd
UPDATE tbl_a SET b = rtrim(b) WHERE a = 10002;
SELECT * FROM tbl_a WHERE a = 10002;
a b
10002 abcd
UPDATE tbl_a SET b = trim(BOTH '[' FROM b) WHERE a = 10003;
SELECT * FROM tbl_a WHERE a = 10003;
a b
10003 abcd]
UPDATE tbl_a SET b = trim(LEADING '[' FROM b) WHERE a = 10004;
SELECT * FROM tbl_a WHERE a = 10004;
a b
10004 abcd][[
UPDATE tbl_a SET b = trim(TRAILING '[' FROM b) WHERE a = 10005;
SELECT * FROM tbl_a WHERE a = 10005;
a b
10005 [[[abcd]
UPDATE tbl_a SET b = trim(LEADING '[' FROM trim(TRAILING ']' FROM b)) WHERE a = 10006;
SELECT * FROM tbl_a WHERE a = 10006;
a b
10006 abcd
UPDATE tbl_a SET b = trim(TRAILING '[' FROM trim(LEADING ']' FROM b)) WHERE a = 10007;
SELECT * FROM tbl_a WHERE a = 10007;
a b
10007 [[[abcd]]
UPDATE tbl_a SET b = trim(TRAILING ']' FROM trim(LEADING '[' FROM b)) WHERE a = 10008;
SELECT * FROM tbl_a WHERE a = 10008;
a b
10008 abcd
UPDATE tbl_a SET b = trim(BOTH '*' FROM trim(TRAILING ']' FROM trim(LEADING '[' FROM b))) WHERE a = 10009;
SELECT * FROM tbl_a WHERE a = 10009;
a b
10009 abcd
deinit
connection master_1;
DROP DATABASE IF EXISTS auto_test_local;
connection child2_1;
DROP DATABASE IF EXISTS auto_test_remote;
for master_1
for child2
child2_1
child2_2
child2_3
for child3
end of test
!include include/default_mysqld.cnf
!include ../my_1_1.cnf
!include ../my_2_1.cnf
--source ../include/mdev_24020_init.inc
--echo
--echo this test is for MDEV-24020
--echo
--echo drop and create databases
--connection master_1
--disable_warnings
CREATE DATABASE auto_test_local;
USE auto_test_local;
--connection child2_1
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
--enable_warnings
--echo
--echo create table and insert
--connection child2_1
--disable_query_log
--disable_ps_protocol
echo CHILD2_1_CREATE_TABLES;
eval $CHILD2_1_CREATE_TABLES;
--enable_ps_protocol
--enable_query_log
--connection master_1
--disable_query_log
echo CREATE TABLE tbl_a (
a INT,
b VARCHAR(30),
PRIMARY KEY(a)
) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1;
eval CREATE TABLE tbl_a (
a INT,
b VARCHAR(30),
PRIMARY KEY(a)
) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1;
--enable_query_log
INSERT INTO tbl_a VALUES(10000, " abcd ");
INSERT INTO tbl_a VALUES(10001, " abcd ");
INSERT INTO tbl_a VALUES(10002, " abcd ");
INSERT INTO tbl_a VALUES(10003, "[[[abcd][[");
INSERT INTO tbl_a VALUES(10004, "[[[abcd][[");
INSERT INTO tbl_a VALUES(10005, "[[[abcd][[");
INSERT INTO tbl_a VALUES(10006, "[[[abcd]]");
INSERT INTO tbl_a VALUES(10007, "[[[abcd]]");
INSERT INTO tbl_a VALUES(10008, "[[[abcd]]");
INSERT INTO tbl_a VALUES(10009, "[[[**abcd****]]");
--echo
--echo test 1
--connection master_1
UPDATE tbl_a SET b = trim(b) WHERE a = 10000;
SELECT * FROM tbl_a WHERE a = 10000;
UPDATE tbl_a SET b = ltrim(b) WHERE a = 10001;
SELECT * FROM tbl_a WHERE a = 10001;
UPDATE tbl_a SET b = rtrim(b) WHERE a = 10002;
SELECT * FROM tbl_a WHERE a = 10002;
UPDATE tbl_a SET b = trim(BOTH '[' FROM b) WHERE a = 10003;
SELECT * FROM tbl_a WHERE a = 10003;
UPDATE tbl_a SET b = trim(LEADING '[' FROM b) WHERE a = 10004;
SELECT * FROM tbl_a WHERE a = 10004;
UPDATE tbl_a SET b = trim(TRAILING '[' FROM b) WHERE a = 10005;
SELECT * FROM tbl_a WHERE a = 10005;
UPDATE tbl_a SET b = trim(LEADING '[' FROM trim(TRAILING ']' FROM b)) WHERE a = 10006;
SELECT * FROM tbl_a WHERE a = 10006;
UPDATE tbl_a SET b = trim(TRAILING '[' FROM trim(LEADING ']' FROM b)) WHERE a = 10007;
SELECT * FROM tbl_a WHERE a = 10007;
UPDATE tbl_a SET b = trim(TRAILING ']' FROM trim(LEADING '[' FROM b)) WHERE a = 10008;
SELECT * FROM tbl_a WHERE a = 10008;
UPDATE tbl_a SET b = trim(BOTH '*' FROM trim(TRAILING ']' FROM trim(LEADING '[' FROM b))) WHERE a = 10009;
SELECT * FROM tbl_a WHERE a = 10009;
--echo
--echo deinit
--disable_warnings
--connection master_1
DROP DATABASE IF EXISTS auto_test_local;
--connection child2_1
DROP DATABASE IF EXISTS auto_test_remote;
--enable_warnings
--source ../include/mdev_24020_deinit.inc
--echo
--echo end of test
......@@ -252,6 +252,15 @@
#define SPIDER_SQL_B_STR "b"
#define SPIDER_SQL_B_LEN (sizeof(SPIDER_SQL_B_STR) - 1)
#define SPIDER_SQL_TRIM_STR "trim"
#define SPIDER_SQL_TRIM_LEN sizeof(SPIDER_SQL_TRIM_STR) - 1
#define SPIDER_SQL_TRIM_BOTH_STR "both "
#define SPIDER_SQL_TRIM_BOTH_LEN sizeof(SPIDER_SQL_TRIM_BOTH_STR) - 1
#define SPIDER_SQL_TRIM_LEADING_STR "leading "
#define SPIDER_SQL_TRIM_LEADING_LEN sizeof(SPIDER_SQL_TRIM_LEADING_STR) - 1
#define SPIDER_SQL_TRIM_TRAILING_STR "trailing "
#define SPIDER_SQL_TRIM_TRAILING_LEN sizeof(SPIDER_SQL_TRIM_TRAILING_STR) - 1
#define SPIDER_SQL_INDEX_IGNORE_STR " IGNORE INDEX "
#define SPIDER_SQL_INDEX_IGNORE_LEN (sizeof(SPIDER_SQL_INDEX_IGNORE_STR) - 1)
#define SPIDER_SQL_INDEX_USE_STR " USE INDEX "
......
......@@ -4181,18 +4181,122 @@ int spider_db_mbase_util::open_item_func(
) {
/* no action */
break;
} else if (func_name_length == 4 &&
!strncasecmp("rand", func_name, func_name_length) &&
} else if (func_name_length == 4)
{
if (
!strncasecmp("rand", func_name, func_name_length) &&
#ifdef SPIDER_Item_args_arg_count_IS_PROTECTED
!item_func->argument_count()
!item_func->argument_count()
#else
!item_func->arg_count
!item_func->arg_count
#endif
) {
if (str)
str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN);
DBUG_RETURN(spider_db_open_item_int(item_func, NULL, spider, str,
alias, alias_length, dbton_id, use_fields, fields));
) {
if (str)
str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN);
DBUG_RETURN(spider_db_open_item_int(item_func, NULL, spider, str,
alias, alias_length, dbton_id, use_fields, fields));
} else if (
!strncasecmp("trim", func_name, func_name_length) &&
item_count == 2
) {
/* item_count == 1 means this TRIM() is without a remove_str */
item = item_list[0];
Item *item_tmp = item_list[1];
if (str)
{
if (item_tmp->type() == Item::STRING_ITEM)
{
/* 1. append 'TRIM(BOTH ' */
if (str->reserve(SPIDER_SQL_TRIM_LEN + SPIDER_SQL_OPEN_PAREN_LEN +
SPIDER_SQL_TRIM_BOTH_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_TRIM_STR, SPIDER_SQL_TRIM_LEN);
str->q_append(SPIDER_SQL_OPEN_PAREN_STR,
SPIDER_SQL_OPEN_PAREN_LEN);
str->q_append(SPIDER_SQL_TRIM_BOTH_STR, SPIDER_SQL_TRIM_BOTH_LEN);
/* 2. append "remove_str"*/
if ((error_num = spider_db_print_item_type(
item_tmp, NULL, spider, str, alias, alias_length, dbton_id,
use_fields, fields)))
DBUG_RETURN(error_num);
/* 3. append ' FROM ' */
if (str->reserve(SPIDER_SQL_FROM_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN);
/* 4. append `field` */
if ((error_num = spider_db_print_item_type(
item, NULL, spider, str, alias, alias_length, dbton_id,
use_fields, fields)))
DBUG_RETURN(error_num);
/* 5. append ')' */
if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_CLOSE_PAREN_STR,
SPIDER_SQL_CLOSE_PAREN_LEN);
}
}
item_count -= 2;
break;
}
} else if (func_name_length == 5)
{
if (
(!strncasecmp("ltrim", func_name, func_name_length) ||
!strncasecmp("rtrim", func_name, func_name_length)) &&
(item_count == 2)
) {
/* the func_name for TRIM(LEADING ...) is LTRIM, for TRIM(TRAILING) is RTRIM */
/* item_count == 2 means this TRIM(LEADING/TRAILING ...) is with a remove_str */
item = item_list[0];
Item *item_tmp = item_list[1];
if (str)
{
if (item_tmp->type() == Item::STRING_ITEM)
{
/* 1. append 'TRIM(LEADING ' or 'TRIM(TRAILING ' */
if (func_name[0] == 'l' || func_name[0] == 'L')
{ /* ltrim */
if (str->reserve(SPIDER_SQL_TRIM_LEN + SPIDER_SQL_OPEN_PAREN_LEN +
SPIDER_SQL_TRIM_LEADING_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_TRIM_STR, SPIDER_SQL_TRIM_LEN);
str->q_append(SPIDER_SQL_OPEN_PAREN_STR,
SPIDER_SQL_OPEN_PAREN_LEN);
str->q_append(SPIDER_SQL_TRIM_LEADING_STR, SPIDER_SQL_TRIM_LEADING_LEN);
} else
{ /* rtrim */
if (str->reserve(SPIDER_SQL_TRIM_LEN + SPIDER_SQL_OPEN_PAREN_LEN +
SPIDER_SQL_TRIM_TRAILING_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_TRIM_STR, SPIDER_SQL_TRIM_LEN);
str->q_append(SPIDER_SQL_OPEN_PAREN_STR,
SPIDER_SQL_OPEN_PAREN_LEN);
str->q_append(SPIDER_SQL_TRIM_TRAILING_STR, SPIDER_SQL_TRIM_TRAILING_LEN);
}
/* 2. append "remove_str"*/
if ((error_num = spider_db_print_item_type(
item_tmp, NULL, spider, str, alias, alias_length, dbton_id,
use_fields, fields)))
DBUG_RETURN(error_num);
/* 3. append ' FROM ' */
if (str->reserve(SPIDER_SQL_FROM_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN);
/* 4. append `field` */
if ((error_num = spider_db_print_item_type(
item, NULL, spider, str, alias, alias_length, dbton_id,
use_fields, fields)))
DBUG_RETURN(error_num);
/* 5. append ')' */
if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_CLOSE_PAREN_STR,
SPIDER_SQL_CLOSE_PAREN_LEN);
}
}
item_count -= 2;
break;
}
} else if (func_name_length == 6 &&
!strncasecmp("istrue", func_name, func_name_length)
) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment