diff options
author | unknown <timour@askmonty.org> | 2011-07-04 14:51:16 +0300 |
---|---|---|
committer | unknown <timour@askmonty.org> | 2011-07-04 14:51:16 +0300 |
commit | 59784abeadc4014f357e44ae507c62dc93c641b3 (patch) | |
tree | a8f6c46f48b05b15f8cfc0cca91778fd71e9130a /mysql-test/t/subselect4.test | |
parent | 55165f51747fc7d5f2b510d778fcdd8ffded808d (diff) | |
download | mariadb-git-59784abeadc4014f357e44ae507c62dc93c641b3.tar.gz |
Fix LP bug lp:802979
Analysis:
This bug consists of two related problems that are
result of too early evaluation of single-row subqueries
during the optimization phase of the outer query.
Several optimizer code paths try to evaluate single-row
subqueries in order to produce a constant and use that
constant for further optimzation.
When the execution of the subquery peforms destructive
changes to the representation of the subquery, and these
changes are not anticipated by the subsequent optimization
phases of the outer query, we tipically get a crash or
failed assert.
Specifically, in this bug the inner-most suqbuery with
DISTINCT triggers a substitution of the original JOIN
object by a single-table JOIN object with a temp table
needed to perform the DISTINCT operation (created by
JOIN::make_simple_join).
This substitution breaks EXPLAIN because:
a) in the first example JOIN::cleanup no longer can
reach the original table of the innermost subquery, and
close all indexes, and
b) in this second test query, EXPLAIN attempts to print
the name of the internal temp table, and crashes because
the temp table has no name (NULL pointer instead).
Solution:
a) fully disable subquery evaluation during optimization
in all cases - both for constant propagation and range
optimization, and
b) change JOIN::join_free() to perform cleanup irrespective
of EXPLAIN or not.
Diffstat (limited to 'mysql-test/t/subselect4.test')
-rw-r--r-- | mysql-test/t/subselect4.test | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/mysql-test/t/subselect4.test b/mysql-test/t/subselect4.test index 39561d5114f..0daff56571d 100644 --- a/mysql-test/t/subselect4.test +++ b/mysql-test/t/subselect4.test @@ -1415,3 +1415,45 @@ WHERE t2.f1 = ( FROM t1)); drop table t1, t2, t3; + +--echo # +--echo # LP BUG#802979 Assertion `table->key_read == 0' in close_thread_table +--echo # + +CREATE TABLE t1 ( f1 int, f2 int , KEY (f1)) ; +INSERT IGNORE INTO t1 VALUES (1,0),(5,0); +CREATE TABLE t2 ( f1 int, f2 int , KEY (f1)) ; +INSERT IGNORE INTO t2 VALUES (1,0),(5,0); +CREATE TABLE t3 ( f1 int, f2 int , KEY (f1)) ; +INSERT IGNORE INTO t3 VALUES (1,0),(5,0); +CREATE TABLE t4 ( f1 int, f2 int , KEY (f1)) ; +INSERT IGNORE INTO t4 VALUES (1,0),(5,0); + +EXPLAIN +SELECT * +FROM t1, t2 +WHERE t2.f2 = (SELECT f2 FROM t3 + WHERE EXISTS (SELECT DISTINCT f1 FROM t4)) + AND t2.f2 = t1.f1; + +-- error ER_SUBQUERY_NO_1_ROW +SELECT * +FROM t1, t2 +WHERE t2.f2 = (SELECT f2 FROM t3 + WHERE EXISTS (SELECT DISTINCT f1 FROM t4)) + AND t2.f2 = t1.f1; + +EXPLAIN +SELECT * +FROM t1, t2 +WHERE t2.f2 = (SELECT f2 FROM t3 + WHERE EXISTS (SELECT DISTINCT f1 FROM t4) LIMIT 1) + AND t2.f2 = t1.f1; + +SELECT * +FROM t1, t2 +WHERE t2.f2 = (SELECT f2 FROM t3 + WHERE EXISTS (SELECT DISTINCT f1 FROM t4) LIMIT 1) + AND t2.f2 = t1.f1; + +drop table t1,t2,t3,t4; |