Skip to content

Commit e292c67

Browse files
author
Varun Gupta
committed
MDEV-17781: Server crashes in next_linear_tab
For degenerate joins we may have JOIN::table_list as NULL, so instead of using JOIN::top_join_tab_count use the function JOIN::exec_join_tab_cnt to get the number of tables joined at the top level.
1 parent ce19598 commit e292c67

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

mysql-test/r/win.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3518,5 +3518,23 @@ rank() OVER (ORDER BY 1) ROW_NUMBER() OVER (ORDER BY (EXPORT_SET(5,'Y','N',',',4
35183518
1 3
35193519
drop table t1;
35203520
#
3521+
# MDEV-17781: Server crashes in next_linear_tab
3522+
#
3523+
CREATE TABLE t1 (i1 int);
3524+
explain
3525+
(SELECT AVG(0) OVER (), MAX('2') FROM t1)
3526+
UNION ALL
3527+
(SELECT AVG(0) OVER (), MAX('2') FROM t1);
3528+
id select_type table type possible_keys key key_len ref rows Extra
3529+
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
3530+
2 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
3531+
(SELECT AVG(0) OVER (), MAX('2') FROM t1)
3532+
UNION ALL
3533+
(SELECT AVG(0) OVER (), MAX('2') FROM t1);
3534+
AVG(0) OVER () MAX('2')
3535+
0.0000 NULL
3536+
0.0000 NULL
3537+
drop table t1;
3538+
#
35213539
# End of 10.2 tests
35223540
#

mysql-test/t/win.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,20 @@ insert into t1 values (1),(2),(3);
22652265
SELECT rank() OVER (ORDER BY 1), ROW_NUMBER() OVER (ORDER BY (EXPORT_SET(5,'Y','N',',',4))) FROM t1;
22662266
drop table t1;
22672267

2268+
--echo #
2269+
--echo # MDEV-17781: Server crashes in next_linear_tab
2270+
--echo #
2271+
2272+
CREATE TABLE t1 (i1 int);
2273+
explain
2274+
(SELECT AVG(0) OVER (), MAX('2') FROM t1)
2275+
UNION ALL
2276+
(SELECT AVG(0) OVER (), MAX('2') FROM t1);
2277+
(SELECT AVG(0) OVER (), MAX('2') FROM t1)
2278+
UNION ALL
2279+
(SELECT AVG(0) OVER (), MAX('2') FROM t1);
2280+
drop table t1;
2281+
22682282
--echo #
22692283
--echo # End of 10.2 tests
22702284
--echo #

sql/sql_select.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8867,7 +8867,7 @@ JOIN_TAB *next_linear_tab(JOIN* join, JOIN_TAB* tab,
88678867
}
88688868

88698869
/* If no more JOIN_TAB's on the top level */
8870-
if (++tab == join->join_tab + join->top_join_tab_count + join->aggr_tables)
8870+
if (++tab >= join->join_tab + join->exec_join_tab_cnt() + join->aggr_tables)
88718871
return NULL;
88728872

88738873
if (include_bush_roots == WITHOUT_BUSH_ROOTS && tab->bush_children)

0 commit comments

Comments
 (0)