Skip to content

Commit

Permalink
MDEV-33679 Spider group by handler: skip on multiple equalities
Browse files Browse the repository at this point in the history
The spider group by handler is created in
JOIN::make_aggr_tables_info(), by which time calls to
substitute_for_best_equal_field() should have already removed all the
multiple equalities (i.e. Item_equal, with MULT_EQUAL_FUNC func_type).
Therefore, if there is still such items, it is deemed as an optimizer
bug and should be skipped.
  • Loading branch information
mariadb-YuchenPei committed Apr 8, 2024
1 parent 9c93d41 commit 860c1ca
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
27 changes: 27 additions & 0 deletions storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# MDEV-33679 spider returns parsing failure on valid left join select by translating the on expression to ()
#
for master_1
for child2
for child3
CREATE SERVER srv FOREIGN DATA WRAPPER mysql
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
CREATE TABLE `t1` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) ENGINE=MYISAM;
CREATE TABLE `t2` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL ) ENGINE=MYISAM;
SET spider_same_server_link= on;
CREATE TABLE `t1_spider` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) COMMENT='wrapper "mysql",srv "srv", table "t1"' ENGINE=SPIDER;
CREATE TABLE `t2_spider` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL
, PRIMARY KEY (`a`) USING BTREE
) COMMENT='wrapper "mysql",srv "srv",table "t2"' ENGINE=SPIDER;
INSERT INTO t1_spider VALUES(1,'oooo');
INSERT INTO t2_spider VALUES(1,1);
SELECT t2_spider.a,t1_spider.c FRoM t2_spider LEFT join t1_spider ON (t2_spider.c = t1_spider.c) WHERE t2_spider.a = 1;
a c
1 1
Warnings:
Warning 1815 Internal error: Spider group by handler: Encountered multiple equalities, likely an optimizer bug
drop table t1, t2, t1_spider, t2_spider;
drop server srv;
for master_1
for child2
for child3
29 changes: 29 additions & 0 deletions storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--echo #
--echo # MDEV-33679 spider returns parsing failure on valid left join select by translating the on expression to ()
--echo #
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');

CREATE TABLE `t1` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) ENGINE=MYISAM;
CREATE TABLE `t2` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL ) ENGINE=MYISAM;
SET spider_same_server_link= on;
CREATE TABLE `t1_spider` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) COMMENT='wrapper "mysql",srv "srv", table "t1"' ENGINE=SPIDER;
CREATE TABLE `t2_spider` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL
, PRIMARY KEY (`a`) USING BTREE
) COMMENT='wrapper "mysql",srv "srv",table "t2"' ENGINE=SPIDER;
INSERT INTO t1_spider VALUES(1,'oooo');
INSERT INTO t2_spider VALUES(1,1);
SELECT t2_spider.a,t1_spider.c FRoM t2_spider LEFT join t1_spider ON (t2_spider.c = t1_spider.c) WHERE t2_spider.a = 1;

drop table t1, t2, t1_spider, t2_spider;
drop server srv;
--disable_query_log
--disable_result_log
--source ../../t/test_deinit.inc
--enable_result_log
--enable_query_log
22 changes: 22 additions & 0 deletions storage/spider/spd_db_mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5566,6 +5566,17 @@ int spider_db_mbase_util::check_item_func(
if (spider_db_check_ft_idx(item_func, spider) == MAX_KEY)
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
break;
case Item_func::MULT_EQUAL_FUNC:
/* If there is still Item_equal by the time of
JOIN::make_aggr_tables_info() where the spider group by handler
is created, it indicates a bug in the optimizer, because there
shouldn't be any. */
push_warning_printf(
spider->trx->thd, SPIDER_WARN_LEVEL_WARN, ER_INTERNAL_ERROR,
ER_THD(spider->trx->thd, ER_INTERNAL_ERROR),
"Spider group by handler: Encountered multiple equalities, likely "
"an optimizer bug");
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
default:
break;
}
Expand Down Expand Up @@ -6492,6 +6503,17 @@ int spider_db_mbase_util::print_item_func(
last_str = SPIDER_SQL_CLOSE_PAREN_STR;
last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN;
break;
case Item_func::MULT_EQUAL_FUNC:
/* If there is still Item_equal by the time of
JOIN::make_aggr_tables_info() where the spider group by handler
is created, it indicates a bug in the optimizer, because there
shouldn't be any. */
push_warning_printf(
spider->trx->thd, SPIDER_WARN_LEVEL_WARN, ER_INTERNAL_ERROR,
ER_THD(spider->trx->thd, ER_INTERNAL_ERROR),
"Spider group by handler: Encountered multiple equalities, likely "
"an optimizer bug");
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
default:
THD *thd = spider->trx->thd;
SPIDER_SHARE *share = spider->share;
Expand Down

0 comments on commit 860c1ca

Please sign in to comment.