MDEV-24760 SELECT..CASE statement syntax error at Spider Engine table
The root cause of the bug is in `spider_db_mbase_util::open_item_func()`. The function handles an instance of the `Item_func` class based on its `Item_func::Functype`. The `Functype` of `CASE WHEN ... THEN` is `CASE_SEARCHED_FUNC`. However, the Spider SE doesn't recognize this `Functype` because `CASE_SEARCHED_FUNC` is newly added by 4de0d92. This results in the wrong handling of `CASE WHEN ... THEN`. The above also applies to `CASE_SIMPLE_FUNC`.
This commit is contained in:
parent
efa311ab8e
commit
cf6d83e7d6
49
storage/spider/mysql-test/spider/bugfix/r/mdev_24760.result
Normal file
49
storage/spider/mysql-test/spider/bugfix/r/mdev_24760.result
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#
|
||||||
|
# MDEV-24760 SELECT..CASE statement syntax error at Spider Engine table
|
||||||
|
#
|
||||||
|
for master_1
|
||||||
|
for child2
|
||||||
|
child2_1
|
||||||
|
child2_2
|
||||||
|
child2_3
|
||||||
|
for child3
|
||||||
|
connection child2_1;
|
||||||
|
CREATE DATABASE auto_test_remote;
|
||||||
|
USE auto_test_remote;
|
||||||
|
DROP TABLE IF EXISTS tbl_a;
|
||||||
|
Warnings:
|
||||||
|
Note 1051 Unknown table 'auto_test_remote.tbl_a'
|
||||||
|
CREATE TABLE tbl_a (
|
||||||
|
id int NOT NULL AUTO_INCREMENT,
|
||||||
|
name varchar(255) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
INSERT INTO tbl_a (name) VALUES ('Alice'), ('Bob');
|
||||||
|
connection master_1;
|
||||||
|
CREATE DATABASE auto_test_local;
|
||||||
|
USE auto_test_local;
|
||||||
|
CREATE TABLE tbl_a (
|
||||||
|
id int NOT NULL AUTO_INCREMENT,
|
||||||
|
name varchar(255) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a"'
|
||||||
|
PARTITION BY HASH(id) (
|
||||||
|
PARTITION pt1 COMMENT='srv "s_2_1"'
|
||||||
|
);
|
||||||
|
SELECT id, CASE WHEN name='Alice' THEN "A" WHEN name='Bob' THEN "B" END FROM tbl_a;
|
||||||
|
id CASE WHEN name='Alice' THEN "A" WHEN name='Bob' THEN "B" END
|
||||||
|
1 A
|
||||||
|
2 B
|
||||||
|
SELECT id, CASE name WHEN 'Alice' THEN "A" WHEN 'Bob' THEN "B" END FROM tbl_a;
|
||||||
|
id CASE name WHEN 'Alice' THEN "A" WHEN 'Bob' THEN "B" END
|
||||||
|
1 A
|
||||||
|
2 B
|
||||||
|
DROP DATABASE auto_test_local;
|
||||||
|
connection child2_1;
|
||||||
|
DROP DATABASE auto_test_remote;
|
||||||
|
for master_1
|
||||||
|
for child2
|
||||||
|
child2_1
|
||||||
|
child2_2
|
||||||
|
child2_3
|
||||||
|
for child3
|
3
storage/spider/mysql-test/spider/bugfix/t/mdev_24760.cnf
Normal file
3
storage/spider/mysql-test/spider/bugfix/t/mdev_24760.cnf
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
!include include/default_mysqld.cnf
|
||||||
|
!include ../my_1_1.cnf
|
||||||
|
!include ../my_2_1.cnf
|
49
storage/spider/mysql-test/spider/bugfix/t/mdev_24760.test
Normal file
49
storage/spider/mysql-test/spider/bugfix/t/mdev_24760.test
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
--echo #
|
||||||
|
--echo # MDEV-24760 SELECT..CASE statement syntax error at Spider Engine table
|
||||||
|
--echo #
|
||||||
|
|
||||||
|
--disable_query_log
|
||||||
|
--disable_result_log
|
||||||
|
--source ../t/test_init.inc
|
||||||
|
--enable_query_log
|
||||||
|
--enable_result_log
|
||||||
|
|
||||||
|
--connection child2_1
|
||||||
|
CREATE DATABASE auto_test_remote;
|
||||||
|
USE auto_test_remote;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS tbl_a;
|
||||||
|
eval CREATE TABLE tbl_a (
|
||||||
|
id int NOT NULL AUTO_INCREMENT,
|
||||||
|
name varchar(255) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
|
||||||
|
|
||||||
|
INSERT INTO tbl_a (name) VALUES ('Alice'), ('Bob');
|
||||||
|
|
||||||
|
--connection master_1
|
||||||
|
CREATE DATABASE auto_test_local;
|
||||||
|
USE auto_test_local;
|
||||||
|
|
||||||
|
eval CREATE TABLE tbl_a (
|
||||||
|
id int NOT NULL AUTO_INCREMENT,
|
||||||
|
name varchar(255) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a"'
|
||||||
|
PARTITION BY HASH(id) (
|
||||||
|
PARTITION pt1 COMMENT='srv "s_2_1"'
|
||||||
|
);
|
||||||
|
|
||||||
|
SELECT id, CASE WHEN name='Alice' THEN "A" WHEN name='Bob' THEN "B" END FROM tbl_a;
|
||||||
|
SELECT id, CASE name WHEN 'Alice' THEN "A" WHEN 'Bob' THEN "B" END FROM tbl_a;
|
||||||
|
|
||||||
|
DROP DATABASE auto_test_local;
|
||||||
|
|
||||||
|
--connection child2_1
|
||||||
|
DROP DATABASE auto_test_remote;
|
||||||
|
|
||||||
|
--disable_query_log
|
||||||
|
--disable_result_log
|
||||||
|
--source ../t/test_deinit.inc
|
||||||
|
--enable_query_log
|
||||||
|
--enable_result_log
|
@ -4181,88 +4181,18 @@ int spider_db_mbase_util::open_item_func(
|
|||||||
) {
|
) {
|
||||||
/* no action */
|
/* no action */
|
||||||
break;
|
break;
|
||||||
} else if (func_name_length == 4)
|
} else if (func_name_length == 4 &&
|
||||||
{
|
!strncasecmp("rand", func_name, func_name_length) &&
|
||||||
if (
|
|
||||||
!strncasecmp("rand", func_name, func_name_length) &&
|
|
||||||
#ifdef SPIDER_Item_args_arg_count_IS_PROTECTED
|
#ifdef SPIDER_Item_args_arg_count_IS_PROTECTED
|
||||||
!item_func->argument_count()
|
!item_func->argument_count()
|
||||||
#else
|
#else
|
||||||
!item_func->arg_count
|
!item_func->arg_count
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
if (str)
|
if (str)
|
||||||
str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN);
|
str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN);
|
||||||
DBUG_RETURN(spider_db_open_item_int(item_func, NULL, spider, str,
|
DBUG_RETURN(spider_db_open_item_int(item_func, NULL, spider, str,
|
||||||
alias, alias_length, dbton_id, use_fields, fields));
|
alias, alias_length, dbton_id, use_fields, fields));
|
||||||
} else if (
|
|
||||||
!strncasecmp("case", func_name, func_name_length)
|
|
||||||
) {
|
|
||||||
#ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC
|
|
||||||
Item_func_case *item_func_case = (Item_func_case *) item_func;
|
|
||||||
if (str)
|
|
||||||
{
|
|
||||||
if (str->reserve(SPIDER_SQL_CASE_LEN))
|
|
||||||
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
|
||||||
str->q_append(SPIDER_SQL_CASE_STR, SPIDER_SQL_CASE_LEN);
|
|
||||||
}
|
|
||||||
if (item_func_case->first_expr_num != -1)
|
|
||||||
{
|
|
||||||
if ((error_num = spider_db_print_item_type(
|
|
||||||
item_list[item_func_case->first_expr_num], NULL, spider, str,
|
|
||||||
alias, alias_length, dbton_id, use_fields, fields)))
|
|
||||||
DBUG_RETURN(error_num);
|
|
||||||
}
|
|
||||||
for (roop_count = 0; roop_count < item_func_case->ncases;
|
|
||||||
roop_count += 2)
|
|
||||||
{
|
|
||||||
if (str)
|
|
||||||
{
|
|
||||||
if (str->reserve(SPIDER_SQL_WHEN_LEN))
|
|
||||||
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
|
||||||
str->q_append(SPIDER_SQL_WHEN_STR, SPIDER_SQL_WHEN_LEN);
|
|
||||||
}
|
|
||||||
if ((error_num = spider_db_print_item_type(
|
|
||||||
item_list[roop_count], NULL, spider, str,
|
|
||||||
alias, alias_length, dbton_id, use_fields, fields)))
|
|
||||||
DBUG_RETURN(error_num);
|
|
||||||
if (str)
|
|
||||||
{
|
|
||||||
if (str->reserve(SPIDER_SQL_THEN_LEN))
|
|
||||||
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
|
||||||
str->q_append(SPIDER_SQL_THEN_STR, SPIDER_SQL_THEN_LEN);
|
|
||||||
}
|
|
||||||
if ((error_num = spider_db_print_item_type(
|
|
||||||
item_list[roop_count + 1], NULL, spider, str,
|
|
||||||
alias, alias_length, dbton_id, use_fields, fields)))
|
|
||||||
DBUG_RETURN(error_num);
|
|
||||||
}
|
|
||||||
if (item_func_case->else_expr_num != -1)
|
|
||||||
{
|
|
||||||
if (str)
|
|
||||||
{
|
|
||||||
if (str->reserve(SPIDER_SQL_ELSE_LEN))
|
|
||||||
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
|
||||||
str->q_append(SPIDER_SQL_ELSE_STR, SPIDER_SQL_ELSE_LEN);
|
|
||||||
}
|
|
||||||
if ((error_num = spider_db_print_item_type(
|
|
||||||
item_list[item_func_case->else_expr_num], NULL, spider, str,
|
|
||||||
alias, alias_length, dbton_id, use_fields, fields)))
|
|
||||||
DBUG_RETURN(error_num);
|
|
||||||
}
|
|
||||||
if (str)
|
|
||||||
{
|
|
||||||
if (str->reserve(SPIDER_SQL_END_LEN + SPIDER_SQL_CLOSE_PAREN_LEN))
|
|
||||||
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
|
||||||
str->q_append(SPIDER_SQL_END_STR, SPIDER_SQL_END_LEN);
|
|
||||||
str->q_append(SPIDER_SQL_CLOSE_PAREN_STR,
|
|
||||||
SPIDER_SQL_CLOSE_PAREN_LEN);
|
|
||||||
}
|
|
||||||
DBUG_RETURN(0);
|
|
||||||
#else
|
|
||||||
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
} else if (func_name_length == 6 &&
|
} else if (func_name_length == 6 &&
|
||||||
!strncasecmp("istrue", func_name, func_name_length)
|
!strncasecmp("istrue", func_name, func_name_length)
|
||||||
) {
|
) {
|
||||||
@ -5088,6 +5018,72 @@ int spider_db_mbase_util::open_item_func(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case Item_func::CASE_SEARCHED_FUNC:
|
||||||
|
case Item_func::CASE_SIMPLE_FUNC:
|
||||||
|
#ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC
|
||||||
|
Item_func_case *item_func_case = (Item_func_case *) item_func;
|
||||||
|
if (str)
|
||||||
|
{
|
||||||
|
if (str->reserve(SPIDER_SQL_CASE_LEN))
|
||||||
|
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
||||||
|
str->q_append(SPIDER_SQL_CASE_STR, SPIDER_SQL_CASE_LEN);
|
||||||
|
}
|
||||||
|
if (item_func_case->first_expr_num != -1)
|
||||||
|
{
|
||||||
|
if ((error_num = spider_db_print_item_type(
|
||||||
|
item_list[item_func_case->first_expr_num], NULL, spider, str,
|
||||||
|
alias, alias_length, dbton_id, use_fields, fields)))
|
||||||
|
DBUG_RETURN(error_num);
|
||||||
|
}
|
||||||
|
for (roop_count = 0; roop_count < item_func_case->ncases;
|
||||||
|
roop_count += 2)
|
||||||
|
{
|
||||||
|
if (str)
|
||||||
|
{
|
||||||
|
if (str->reserve(SPIDER_SQL_WHEN_LEN))
|
||||||
|
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
||||||
|
str->q_append(SPIDER_SQL_WHEN_STR, SPIDER_SQL_WHEN_LEN);
|
||||||
|
}
|
||||||
|
if ((error_num = spider_db_print_item_type(
|
||||||
|
item_list[roop_count], NULL, spider, str,
|
||||||
|
alias, alias_length, dbton_id, use_fields, fields)))
|
||||||
|
DBUG_RETURN(error_num);
|
||||||
|
if (str)
|
||||||
|
{
|
||||||
|
if (str->reserve(SPIDER_SQL_THEN_LEN))
|
||||||
|
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
||||||
|
str->q_append(SPIDER_SQL_THEN_STR, SPIDER_SQL_THEN_LEN);
|
||||||
|
}
|
||||||
|
if ((error_num = spider_db_print_item_type(
|
||||||
|
item_list[roop_count + 1], NULL, spider, str,
|
||||||
|
alias, alias_length, dbton_id, use_fields, fields)))
|
||||||
|
DBUG_RETURN(error_num);
|
||||||
|
}
|
||||||
|
if (item_func_case->else_expr_num != -1)
|
||||||
|
{
|
||||||
|
if (str)
|
||||||
|
{
|
||||||
|
if (str->reserve(SPIDER_SQL_ELSE_LEN))
|
||||||
|
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
||||||
|
str->q_append(SPIDER_SQL_ELSE_STR, SPIDER_SQL_ELSE_LEN);
|
||||||
|
}
|
||||||
|
if ((error_num = spider_db_print_item_type(
|
||||||
|
item_list[item_func_case->else_expr_num], NULL, spider, str,
|
||||||
|
alias, alias_length, dbton_id, use_fields, fields)))
|
||||||
|
DBUG_RETURN(error_num);
|
||||||
|
}
|
||||||
|
if (str)
|
||||||
|
{
|
||||||
|
if (str->reserve(SPIDER_SQL_END_LEN + SPIDER_SQL_CLOSE_PAREN_LEN))
|
||||||
|
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
||||||
|
str->q_append(SPIDER_SQL_END_STR, SPIDER_SQL_END_LEN);
|
||||||
|
str->q_append(SPIDER_SQL_CLOSE_PAREN_STR,
|
||||||
|
SPIDER_SQL_CLOSE_PAREN_LEN);
|
||||||
|
}
|
||||||
|
DBUG_RETURN(0);
|
||||||
|
#else
|
||||||
|
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
THD *thd = spider->trx->thd;
|
THD *thd = spider->trx->thd;
|
||||||
SPIDER_SHARE *share = spider->share;
|
SPIDER_SHARE *share = spider->share;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user