From 5be4148e587ba651e5e1ba807b830216484012f7 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Sat, 3 Sep 2011 17:05:05 +0400 Subject: [PATCH] BUG#834514: Assertion `!table || (!table->read_set || bitmap_is_set(...' with aggregates - Make find_all_keys() not to rely on table->tmp_set remaining constant during execution quick_index_merge_select->reset() may change it. --- mysql-test/r/index_merge_myisam.result | 20 ++++++++++++++++++++ mysql-test/t/index_merge_myisam.test | 24 ++++++++++++++++++++++++ sql/filesort.cc | 12 +++++++++--- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/index_merge_myisam.result b/mysql-test/r/index_merge_myisam.result index 2ed58245b54..ea578accaaa 100644 --- a/mysql-test/r/index_merge_myisam.result +++ b/mysql-test/r/index_merge_myisam.result @@ -1594,4 +1594,24 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index_merge a,b,c a,c 5,5 NULL 54 Using sort_union(a,c); Using where set optimizer_switch=default; drop table t0, t1; +# +# BUG#834514 Assertion `!table || (!table->read_set || bitmap_is_set(...' with aggregates +# +CREATE TABLE t1 ( a int , b int, c int, KEY (b), PRIMARY KEY (a)) ; +INSERT INTO t1 VALUES (1,4,0),(5,0,0),(6,7,0),(7,7,0),(8,1,0),(9,7,0),(10,1,0); +CREATE TABLE t2 ( b int, c int, KEY (c,b)) ; +INSERT INTO t2 VALUES (7,0),(1,0),(7,0),(1,0); +CREATE TABLE t3 ( a int ) ; +SELECT COUNT(DISTINCT t2.b), CONCAT(t1.c) +FROM t1, t2 +WHERE (t2.c = t1.c) +AND ( +t1.b IN ( 4 ) +OR t1.a = 137 +AND EXISTS ( SELECT a FROM t3 ) +) +GROUP BY 2; +COUNT(DISTINCT t2.b) CONCAT(t1.c) +2 0 +DROP TABLE t1,t2,t3; set optimizer_switch= @optimizer_switch_save; diff --git a/mysql-test/t/index_merge_myisam.test b/mysql-test/t/index_merge_myisam.test index 5431c6dba2b..614c6595d61 100644 --- a/mysql-test/t/index_merge_myisam.test +++ b/mysql-test/t/index_merge_myisam.test @@ -125,5 +125,29 @@ set optimizer_switch=default; drop table t0, t1; + +--echo # +--echo # BUG#834514 Assertion `!table || (!table->read_set || bitmap_is_set(...' with aggregates +--echo # +CREATE TABLE t1 ( a int , b int, c int, KEY (b), PRIMARY KEY (a)) ; +INSERT INTO t1 VALUES (1,4,0),(5,0,0),(6,7,0),(7,7,0),(8,1,0),(9,7,0),(10,1,0); + +CREATE TABLE t2 ( b int, c int, KEY (c,b)) ; +INSERT INTO t2 VALUES (7,0),(1,0),(7,0),(1,0); + +CREATE TABLE t3 ( a int ) ; + +SELECT COUNT(DISTINCT t2.b), CONCAT(t1.c) +FROM t1, t2 +WHERE (t2.c = t1.c) +AND ( + t1.b IN ( 4 ) + OR t1.a = 137 + AND EXISTS ( SELECT a FROM t3 ) +) +GROUP BY 2; + +DROP TABLE t1,t2,t3; + set optimizer_switch= @optimizer_switch_save; diff --git a/sql/filesort.cc b/sql/filesort.cc index 559f4f1dcf6..b3bb15bd7f0 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -624,15 +624,21 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select, SQL_SELECT::skip_record evaluates this condition. it may include a correlated subquery predicate, such that some field in the subquery refers to 'sort_form'. + + PSergey-todo: discuss the above with Timour. */ + MY_BITMAP *tmp_read_set= sort_form->read_set; + MY_BITMAP *tmp_write_set= sort_form->write_set; + MY_BITMAP *tmp_vcol_set= sort_form->vcol_set; + if (select->cond->with_subselect) sort_form->column_bitmaps_set(save_read_set, save_write_set, save_vcol_set); write_record= (select->skip_record(thd) > 0); if (select->cond->with_subselect) - sort_form->column_bitmaps_set(&sort_form->tmp_set, - &sort_form->tmp_set, - &sort_form->tmp_set); + sort_form->column_bitmaps_set(tmp_read_set, + tmp_write_set, + tmp_vcol_set); } else write_record= true;