summaryrefslogtreecommitdiff
path: root/mysql-test/t/join_cache.test
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2011-06-28 18:31:54 -0700
committerIgor Babaev <igor@askmonty.org>2011-06-28 18:31:54 -0700
commit31edda66fddf96187444b8b47cd24195556306a0 (patch)
tree61332a3c5925c459ef53d5f3de488e86b7e6f579 /mysql-test/t/join_cache.test
parent5ce5e8db92ab04086f0a0f634eec78634f21ff3a (diff)
downloadmariadb-git-31edda66fddf96187444b8b47cd24195556306a0.tar.gz
Fixed LP bug #802860.
This crashing bug could manifest itself at execution of join queries over materialized derived tables with IN subquery predicates in the where clause. If for such a query the optimizer chose to use duplicate weed-out with duplicates in a materialized derived table and chose to employ join cache the the execution could cause a crash of the server. It happened because the JOIN_CACHE::init method assumed that the value of TABLE::file::ref is set at the moment when the method was called for the employed join cache. It's true for regular tables, but it's not true for materialized derived tables that are filled now at the first access to them, i.e. after the JOIN_CACHE::init has done its job. To fix this problem for any ROWID field of materialized derived table the procedure that copies fields from record buffers into the employed join buffer first checks whether the value of TABLE::file::ref has been set for the table, and if it's not so the procedure sets this value.
Diffstat (limited to 'mysql-test/t/join_cache.test')
-rw-r--r--mysql-test/t/join_cache.test35
1 files changed, 35 insertions, 0 deletions
diff --git a/mysql-test/t/join_cache.test b/mysql-test/t/join_cache.test
index 0073d1e45b0..1d5addeb808 100644
--- a/mysql-test/t/join_cache.test
+++ b/mysql-test/t/join_cache.test
@@ -3100,5 +3100,40 @@ SET SESSION join_buffer_size = DEFAULT;
DROP TABLE t1,t2;
+--echo #
+--echo # Bug #802860: crash on join cache + derived + duplicate_weedout
+--echo #
+
+SET SESSION optimizer_switch=
+ 'semijoin=on,materialization=off,firstmatch=off,loosescan=off';
+
+CREATE TABLE t1 (a int) ;
+INSERT IGNORE INTO t1 VALUES (0), (1), (0);
+
+CREATE TABLE t2 (a int) ;
+INSERT IGNORE INTO t2 VALUES (0), (3), (0), (2);
+
+SET SESSION join_cache_level = 0;
+
+EXPLAIN
+SELECT * FROM (SELECT DISTINCT * FROM t1) t
+ WHERE t.a IN (SELECT t2.a FROM t2);
+SELECT * FROM (SELECT DISTINCT * FROM t1) t
+ WHERE t.a IN (SELECT t2.a FROM t2);
+
+SET SESSION join_cache_level = 1;
+
+EXPLAIN
+SELECT * FROM (SELECT DISTINCT * FROM t1) t
+ WHERE t.a IN (SELECT t2.a FROM t2);
+SELECT * FROM (SELECT DISTINCT * FROM t1) t
+ WHERE t.a IN (SELECT t2.a FROM t2);
+
+SET SESSION join_cache_level = DEFAULT;
+
+DROP TABLE t1, t2;
+
+SET SESSION optimizer_switch=default;
+
# this must be the last command in the file
set @@optimizer_switch=@save_optimizer_switch;