Skip to content

Commit e3dd9a9

Browse files
committed
MDEV-6736: Valgrind warnings 'Invalid read' in subselect_engine::calc_const_tables with SQ in WHERE and
HAVING, ORDER BY, materialization+semijoin During cleanup a pointer to the materialised table that was freed was not set to NULL
1 parent 3d5dff6 commit e3dd9a9

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

mysql-test/r/having.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,4 +723,18 @@ SELECT * FROM t1 JOIN t2 ON c1 = c2 HAVING c2 > 'a' ORDER BY c2 LIMIT 1;
723723
c1 c2
724724
x x
725725
DROP TABLE t1,t2;
726+
#
727+
# MDEV-6736: Valgrind warnings 'Invalid read' in subselect_engine::calc_const_tables with SQ
728+
# in WHERE and HAVING, ORDER BY, materialization+semijoin
729+
#
730+
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
731+
INSERT INTO t1 VALUES (3),(8);
732+
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
733+
INSERT INTO t2 VALUES (2),(1);
734+
SELECT a FROM t1
735+
WHERE 9 IN ( SELECT MIN( a ) FROM t1 )
736+
HAVING a <> ( SELECT COUNT(*) FROM t2 )
737+
ORDER BY a;
738+
a
739+
DROP TABLE t1,t2;
726740
End of 10.0 tests

mysql-test/t/having.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,4 +759,22 @@ SELECT * FROM t1 JOIN t2 ON c1 = c2 HAVING c2 > 'a' ORDER BY c2 LIMIT 1;
759759

760760
DROP TABLE t1,t2;
761761

762+
--echo #
763+
--echo # MDEV-6736: Valgrind warnings 'Invalid read' in subselect_engine::calc_const_tables with SQ
764+
--echo # in WHERE and HAVING, ORDER BY, materialization+semijoin
765+
--echo #
766+
767+
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
768+
INSERT INTO t1 VALUES (3),(8);
769+
770+
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
771+
INSERT INTO t2 VALUES (2),(1);
772+
773+
SELECT a FROM t1
774+
WHERE 9 IN ( SELECT MIN( a ) FROM t1 )
775+
HAVING a <> ( SELECT COUNT(*) FROM t2 )
776+
ORDER BY a;
777+
778+
DROP TABLE t1,t2;
779+
762780
--echo End of 10.0 tests

sql/sql_select.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11476,13 +11476,15 @@ void JOIN_TAB::cleanup()
1147611476
}
1147711477
else
1147811478
{
11479+
TABLE_LIST *tmp= table->pos_in_table_list;
1147911480
end_read_record(&read_record);
11480-
table->pos_in_table_list->jtbm_subselect->cleanup();
11481+
tmp->jtbm_subselect->cleanup();
1148111482
/*
1148211483
The above call freed the materializedd temptable. Set it to NULL so
1148311484
that we don't attempt to touch it if JOIN_TAB::cleanup() is invoked
1148411485
multiple times (it may be)
1148511486
*/
11487+
tmp->table= NULL;
1148611488
table=NULL;
1148711489
}
1148811490
DBUG_VOID_RETURN;

0 commit comments

Comments
 (0)