Skip to content

Commit 860c1ca

Browse files
MDEV-33679 Spider group by handler: skip on multiple equalities
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.
1 parent 9c93d41 commit 860c1ca

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# MDEV-33679 spider returns parsing failure on valid left join select by translating the on expression to ()
3+
#
4+
for master_1
5+
for child2
6+
for child3
7+
CREATE SERVER srv FOREIGN DATA WRAPPER mysql
8+
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
9+
CREATE TABLE `t1` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) ENGINE=MYISAM;
10+
CREATE TABLE `t2` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL ) ENGINE=MYISAM;
11+
SET spider_same_server_link= on;
12+
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;
13+
CREATE TABLE `t2_spider` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL
14+
, PRIMARY KEY (`a`) USING BTREE
15+
) COMMENT='wrapper "mysql",srv "srv",table "t2"' ENGINE=SPIDER;
16+
INSERT INTO t1_spider VALUES(1,'oooo');
17+
INSERT INTO t2_spider VALUES(1,1);
18+
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;
19+
a c
20+
1 1
21+
Warnings:
22+
Warning 1815 Internal error: Spider group by handler: Encountered multiple equalities, likely an optimizer bug
23+
drop table t1, t2, t1_spider, t2_spider;
24+
drop server srv;
25+
for master_1
26+
for child2
27+
for child3
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--echo #
2+
--echo # MDEV-33679 spider returns parsing failure on valid left join select by translating the on expression to ()
3+
--echo #
4+
--disable_query_log
5+
--disable_result_log
6+
--source ../../t/test_init.inc
7+
--enable_result_log
8+
--enable_query_log
9+
evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
10+
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
11+
12+
CREATE TABLE `t1` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) ENGINE=MYISAM;
13+
CREATE TABLE `t2` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL ) ENGINE=MYISAM;
14+
SET spider_same_server_link= on;
15+
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;
16+
CREATE TABLE `t2_spider` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL
17+
, PRIMARY KEY (`a`) USING BTREE
18+
) COMMENT='wrapper "mysql",srv "srv",table "t2"' ENGINE=SPIDER;
19+
INSERT INTO t1_spider VALUES(1,'oooo');
20+
INSERT INTO t2_spider VALUES(1,1);
21+
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;
22+
23+
drop table t1, t2, t1_spider, t2_spider;
24+
drop server srv;
25+
--disable_query_log
26+
--disable_result_log
27+
--source ../../t/test_deinit.inc
28+
--enable_result_log
29+
--enable_query_log

storage/spider/spd_db_mysql.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5566,6 +5566,17 @@ int spider_db_mbase_util::check_item_func(
55665566
if (spider_db_check_ft_idx(item_func, spider) == MAX_KEY)
55675567
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
55685568
break;
5569+
case Item_func::MULT_EQUAL_FUNC:
5570+
/* If there is still Item_equal by the time of
5571+
JOIN::make_aggr_tables_info() where the spider group by handler
5572+
is created, it indicates a bug in the optimizer, because there
5573+
shouldn't be any. */
5574+
push_warning_printf(
5575+
spider->trx->thd, SPIDER_WARN_LEVEL_WARN, ER_INTERNAL_ERROR,
5576+
ER_THD(spider->trx->thd, ER_INTERNAL_ERROR),
5577+
"Spider group by handler: Encountered multiple equalities, likely "
5578+
"an optimizer bug");
5579+
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
55695580
default:
55705581
break;
55715582
}
@@ -6492,6 +6503,17 @@ int spider_db_mbase_util::print_item_func(
64926503
last_str = SPIDER_SQL_CLOSE_PAREN_STR;
64936504
last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN;
64946505
break;
6506+
case Item_func::MULT_EQUAL_FUNC:
6507+
/* If there is still Item_equal by the time of
6508+
JOIN::make_aggr_tables_info() where the spider group by handler
6509+
is created, it indicates a bug in the optimizer, because there
6510+
shouldn't be any. */
6511+
push_warning_printf(
6512+
spider->trx->thd, SPIDER_WARN_LEVEL_WARN, ER_INTERNAL_ERROR,
6513+
ER_THD(spider->trx->thd, ER_INTERNAL_ERROR),
6514+
"Spider group by handler: Encountered multiple equalities, likely "
6515+
"an optimizer bug");
6516+
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
64956517
default:
64966518
THD *thd = spider->trx->thd;
64976519
SPIDER_SHARE *share = spider->share;

0 commit comments

Comments
 (0)