Skip to content

Commit d2bf101

Browse files
committed
MDEV-13723: Server crashes in ha_heap::find_unique_row or Assertion `0' failed in st_select_lex_unit::optimize with INTERSECT
With INTERSECT/EXCEPT fact that subquery item of IN/ALL/ANY was not assigned value does not mean that temporary table used for calculating unit is empty (records could be deleted).
1 parent 386e5d4 commit d2bf101

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

mysql-test/r/except.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,3 +525,13 @@ t3 CREATE TABLE `t3` (
525525
`b1` blob DEFAULT NULL
526526
) ENGINE=MyISAM DEFAULT CHARSET=latin1
527527
drop tables t1,t2,t3;
528+
#
529+
# MDEV-13723: Server crashes in ha_heap::find_unique_row or
530+
# Assertion `0' failed in st_select_lex_unit::optimize with INTERSECT
531+
#
532+
CREATE TABLE t (i INT);
533+
INSERT INTO t VALUES (1),(2);
534+
SELECT * FROM t WHERE i != ANY ( SELECT 3 EXCEPT SELECT 3 );
535+
i
536+
drop table t;
537+
# End of 10.3 tests

mysql-test/r/intersect.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,3 +689,4 @@ View Create View character_set_client collation_connection
689689
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS (select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union select `__3`.`c` AS `c`,`__3`.`d` AS `d` from ((select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) intersect (select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`)) `__3` union (select 4 AS `4`,4 AS `4`) latin1 latin1_swedish_ci
690690
drop view v1;
691691
drop tables t1,t2,t3;
692+
# End of 10.3 tests

mysql-test/t/except.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,17 @@ create table t3 (select a,b,b1 from t1) except (select c,d,d1 from t2);
8181
show create table t3;
8282

8383
drop tables t1,t2,t3;
84+
85+
--echo #
86+
--echo # MDEV-13723: Server crashes in ha_heap::find_unique_row or
87+
--echo # Assertion `0' failed in st_select_lex_unit::optimize with INTERSECT
88+
--echo #
89+
CREATE TABLE t (i INT);
90+
INSERT INTO t VALUES (1),(2);
91+
92+
SELECT * FROM t WHERE i != ANY ( SELECT 3 EXCEPT SELECT 3 );
93+
94+
drop table t;
95+
96+
97+
--echo # End of 10.3 tests

mysql-test/t/intersect.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,4 @@ show create view v1;
190190
drop view v1;
191191
drop tables t1,t2,t3;
192192

193+
--echo # End of 10.3 tests

sql/sql_union.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,11 +1299,11 @@ bool st_select_lex_unit::optimize()
12991299
{
13001300
item->assigned(0); // We will reinit & rexecute unit
13011301
item->reset();
1302-
if (table->is_created())
1303-
{
1304-
table->file->ha_delete_all_rows();
1305-
table->file->info(HA_STATUS_VARIABLE);
1306-
}
1302+
}
1303+
if (table->is_created())
1304+
{
1305+
table->file->ha_delete_all_rows();
1306+
table->file->info(HA_STATUS_VARIABLE);
13071307
}
13081308
/* re-enabling indexes for next subselect iteration */
13091309
if (union_distinct && table->file->ha_enable_indexes(HA_KEY_SWITCH_ALL))

0 commit comments

Comments
 (0)