diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 41b809774ad..8ebdd3861e7 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4543,6 +4543,7 @@ finish: DBUG_ASSERT(!thd->in_active_multi_stmt_transaction() || thd->in_multi_stmt_transaction_mode()); + lex->unit.cleanup(); if (! thd->in_sub_stmt) { @@ -4575,7 +4576,6 @@ finish: #endif } - lex->unit.cleanup(); /* Free tables */ thd_proc_info(thd, "closing tables"); close_thread_tables(thd); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index cd475b28783..a224bd77bce 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2258,6 +2258,7 @@ JOIN::exec() In this case JOIN::exec must check for JOIN::having_value, in the same way it checks for JOIN::cond_value. */ + DBUG_ASSERT(error == 0); if (cond_value != Item::COND_FALSE && having_value != Item::COND_FALSE && (!conds || conds->val_int()) && @@ -2268,16 +2269,15 @@ JOIN::exec() procedure->end_of_records()) : result->send_data(fields_list)> 0)) error= 1; else - { - error= (int) result->send_eof(); send_records= ((select_options & OPTION_FOUND_ROWS) ? 1 : thd->sent_row_count); - } } else - { - error=(int) result->send_eof(); send_records= 0; + if (!error) + { + join_free(); // Unlock all cursors + error= (int) result->send_eof(); } } /* Single select (without union) always returns 0 or 1 row */ diff --git a/storage/tokudb/mysql-test/tokudb_mariadb/r/commit_5396.result b/storage/tokudb/mysql-test/tokudb_mariadb/r/commit_5396.result new file mode 100644 index 00000000000..b226abc81d1 --- /dev/null +++ b/storage/tokudb/mysql-test/tokudb_mariadb/r/commit_5396.result @@ -0,0 +1,16 @@ +CREATE TABLE t1 (a VARCHAR(8), INDEX(a)) ENGINE=TokuDB; +INSERT INTO t1 VALUES ('foo'),('bar'); +CREATE TABLE t2 AS SELECT 'qux' IN (SELECT a FROM t1) AS f1; +DROP TABLE t1, t2; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (3),(4); +CREATE TABLE t3 (c VARCHAR(3), INDEX(c)) ENGINE=TokuDB; +INSERT INTO t3 VALUES ('foo'),('bar'); +EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT b FROM t2) OR 'qux' IN (SELECT c FROM t3); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +3 SUBQUERY t3 index_subquery c c 6 const 0 Using index; Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 +DROP TABLE t1, t2, t3; diff --git a/storage/tokudb/mysql-test/tokudb_mariadb/t/commit_5396.test b/storage/tokudb/mysql-test/tokudb_mariadb/t/commit_5396.test new file mode 100644 index 00000000000..6df7fb6ac09 --- /dev/null +++ b/storage/tokudb/mysql-test/tokudb_mariadb/t/commit_5396.test @@ -0,0 +1,18 @@ +# +# MDEV-5396 Assertion `Handlerton: r==0 ' failed (errno=0) on EXPLAIN with TokuDB tables +# + +CREATE TABLE t1 (a VARCHAR(8), INDEX(a)) ENGINE=TokuDB; +INSERT INTO t1 VALUES ('foo'),('bar'); +CREATE TABLE t2 AS SELECT 'qux' IN (SELECT a FROM t1) AS f1; +DROP TABLE t1, t2; + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (3),(4); +CREATE TABLE t3 (c VARCHAR(3), INDEX(c)) ENGINE=TokuDB; +INSERT INTO t3 VALUES ('foo'),('bar'); +EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT b FROM t2) OR 'qux' IN (SELECT c FROM t3); +DROP TABLE t1, t2, t3; +