Commit fdf789a7 authored by Igor Babaev's avatar Igor Babaev

Fixed LP bug #874378.

This bug happened for the queries over multi-table mergeable views
because the bitmap TABLE::read_set of the underlying tables were not
updated after the views had been merged into the query.
Now this bitmaps are updated properly.
Also the bitmap TABLE::merge_keys now is updated in prevention of
future bugs.
parent b117a3c4
...@@ -1576,4 +1576,59 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -1576,4 +1576,59 @@ id select_type table type possible_keys key key_len ref rows Extra
2 DERIVED t1 ALL NULL NULL NULL NULL 3 Using temporary; Using filesort 2 DERIVED t1 ALL NULL NULL NULL NULL 3 Using temporary; Using filesort
DROP VIEW v1,v2; DROP VIEW v1,v2;
DROP TABLE t1,t2; DROP TABLE t1,t2;
#
# Bug #743378: join over merged view employing BNL
#
CREATE TABLE t1 ( d varchar(1) NOT NULL) ;
INSERT INTO t1 VALUES ('j'),('v'),('c');
CREATE TABLE t2 (h time NOT NULL, d varchar(1) NOT NULL) ;
INSERT INTO t2 VALUES ('05:03:03','w'),('02:59:24','d'),('00:01:58','e');
CREATE TABLE t3 (
b int NOT NULL, e varchar(1) NOT NULL, d varchar(1) NOT NULL, KEY (e,b)
);
INSERT INTO t3 VALUES (4,'x','x'),(9,'w','w'),(4,'d','d'),(8,'e','e');
CREATE TABLE t4 (i int NOT NULL, m varchar(1) NOT NULL) ;
INSERT INTO t4 VALUES (8,'m'),(9,'d'),(2,'s'),(4,'r'),(8,'m');
CREATE TABLE t5 (
a int NOT NULL, c int NOT NULL, b int NOT NULL, f date NOT NULL,
g date NOT NULL, h time NOT NULL, j time NOT NULL, k datetime NOT NULL
);
INSERT INTO t5 VALUES
(1,4,0,'0000-00-00','0000-00-00','21:22:34','21:22:34','2002-02-13 17:30'),
(2,6,8,'2004-09-18','2004-09-18','10:50:38','10:50:38','2008-09-27 00:34');
CREATE VIEW v3 AS SELECT t3.*, t4.i FROM t3, t4, t5;
SET SESSION join_cache_level = 1;
SET SESSION join_buffer_size = 512;
EXPLAIN
SELECT t2.d FROM t1,t2,v3 WHERE v3.e = t2.d AND v3.i < 3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 3
1 SIMPLE t3 ref e e 3 test.t2.d 1 Using index
1 SIMPLE t5 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
SELECT t2.d FROM t1,t2,v3 WHERE v3.e = t2.d AND v3.i < 3;
d
w
d
e
w
d
e
w
d
e
w
d
e
w
d
e
w
d
e
SET SESSION join_cache_level = DEFAULT;
SET SESSION join_buffer_size = DEFAULT;
DROP VIEW v3;
DROP TABLE t1,t2,t3,t4,t5;
set optimizer_switch=@exit_optimizer_switch; set optimizer_switch=@exit_optimizer_switch;
...@@ -1016,5 +1016,48 @@ SELECT v1.a FROM v1,v2 WHERE v2.b = v1.b ORDER BY 1; ...@@ -1016,5 +1016,48 @@ SELECT v1.a FROM v1,v2 WHERE v2.b = v1.b ORDER BY 1;
DROP VIEW v1,v2; DROP VIEW v1,v2;
DROP TABLE t1,t2; DROP TABLE t1,t2;
--echo #
--echo # Bug #743378: join over merged view employing BNL
--echo #
CREATE TABLE t1 ( d varchar(1) NOT NULL) ;
INSERT INTO t1 VALUES ('j'),('v'),('c');
CREATE TABLE t2 (h time NOT NULL, d varchar(1) NOT NULL) ;
INSERT INTO t2 VALUES ('05:03:03','w'),('02:59:24','d'),('00:01:58','e');
CREATE TABLE t3 (
b int NOT NULL, e varchar(1) NOT NULL, d varchar(1) NOT NULL, KEY (e,b)
);
INSERT INTO t3 VALUES (4,'x','x'),(9,'w','w'),(4,'d','d'),(8,'e','e');
CREATE TABLE t4 (i int NOT NULL, m varchar(1) NOT NULL) ;
INSERT INTO t4 VALUES (8,'m'),(9,'d'),(2,'s'),(4,'r'),(8,'m');
CREATE TABLE t5 (
a int NOT NULL, c int NOT NULL, b int NOT NULL, f date NOT NULL,
g date NOT NULL, h time NOT NULL, j time NOT NULL, k datetime NOT NULL
);
INSERT INTO t5 VALUES
(1,4,0,'0000-00-00','0000-00-00','21:22:34','21:22:34','2002-02-13 17:30'),
(2,6,8,'2004-09-18','2004-09-18','10:50:38','10:50:38','2008-09-27 00:34');
CREATE VIEW v3 AS SELECT t3.*, t4.i FROM t3, t4, t5;
SET SESSION join_cache_level = 1;
SET SESSION join_buffer_size = 512;
EXPLAIN
SELECT t2.d FROM t1,t2,v3 WHERE v3.e = t2.d AND v3.i < 3;
SELECT t2.d FROM t1,t2,v3 WHERE v3.e = t2.d AND v3.i < 3;
SET SESSION join_cache_level = DEFAULT;
SET SESSION join_buffer_size = DEFAULT;
DROP VIEW v3;
DROP TABLE t1,t2,t3,t4,t5;
# The following command must be the last one the file # The following command must be the last one the file
set optimizer_switch=@exit_optimizer_switch; set optimizer_switch=@exit_optimizer_switch;
...@@ -2172,10 +2172,9 @@ bool Item_field::enumerate_field_refs_processor(uchar *arg) ...@@ -2172,10 +2172,9 @@ bool Item_field::enumerate_field_refs_processor(uchar *arg)
return FALSE; return FALSE;
} }
bool Item_field::covering_keys_processor(uchar *arg) bool Item_field::update_table_bitmaps_processor(uchar *arg)
{ {
if (field && field->table) update_table_bitmaps();
field->table->covering_keys.intersect(field->part_of_key);
return FALSE; return FALSE;
} }
......
...@@ -1018,7 +1018,7 @@ public: ...@@ -1018,7 +1018,7 @@ public:
virtual bool mark_as_eliminated_processor(uchar *arg) { return 0; } virtual bool mark_as_eliminated_processor(uchar *arg) { return 0; }
virtual bool eliminate_subselect_processor(uchar *arg) { return 0; } virtual bool eliminate_subselect_processor(uchar *arg) { return 0; }
virtual bool set_fake_select_as_master_processor(uchar *arg) { return 0; } virtual bool set_fake_select_as_master_processor(uchar *arg) { return 0; }
virtual bool covering_keys_processor(uchar *arg) { return 0; } virtual bool update_table_bitmaps_processor(uchar *arg) { return 0; }
virtual bool view_used_tables_processor(uchar *arg) { return 0; } virtual bool view_used_tables_processor(uchar *arg) { return 0; }
virtual bool eval_not_null_tables(uchar *opt_arg) { return 0; } virtual bool eval_not_null_tables(uchar *opt_arg) { return 0; }
virtual bool clear_sum_processor(uchar *opt_arg) { return 0; } virtual bool clear_sum_processor(uchar *opt_arg) { return 0; }
...@@ -1817,11 +1817,20 @@ public: ...@@ -1817,11 +1817,20 @@ public:
bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate); bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate);
bool is_null() { return field->is_null(); } bool is_null() { return field->is_null(); }
void update_null_value(); void update_null_value();
void update_used_tables() void update_table_bitmaps()
{ {
if (field && field->table) if (field && field->table)
field->table->covering_keys.intersect(field->part_of_key); {
} TABLE *tab= field->table;
tab->covering_keys.intersect(field->part_of_key);
tab->merge_keys.merge(field->part_of_key);
if (tab->read_set)
bitmap_fast_test_and_set(tab->read_set, field->field_index);
if (field->vcol_info)
tab->mark_virtual_col(field);
}
}
void update_used_tables() { update_table_bitmaps(); }
Item *get_tmp_table_item(THD *thd); Item *get_tmp_table_item(THD *thd);
bool collect_item_field_processor(uchar * arg); bool collect_item_field_processor(uchar * arg);
bool add_field_to_set_processor(uchar * arg); bool add_field_to_set_processor(uchar * arg);
...@@ -1833,7 +1842,7 @@ public: ...@@ -1833,7 +1842,7 @@ public:
bool vcol_in_partition_func_processor(uchar *bool_arg); bool vcol_in_partition_func_processor(uchar *bool_arg);
bool check_vcol_func_processor(uchar *arg) { return FALSE;} bool check_vcol_func_processor(uchar *arg) { return FALSE;}
bool enumerate_field_refs_processor(uchar *arg); bool enumerate_field_refs_processor(uchar *arg);
bool covering_keys_processor(uchar *arg); bool update_table_bitmaps_processor(uchar *arg);
void cleanup(); void cleanup();
Item_equal *get_item_equal() { return item_equal; } Item_equal *get_item_equal() { return item_equal; }
void set_item_equal(Item_equal *item_eq) { item_equal= item_eq; } void set_item_equal(Item_equal *item_eq) { item_equal= item_eq; }
......
...@@ -492,7 +492,7 @@ void Item_subselect::recalc_used_tables(st_select_lex *new_parent, ...@@ -492,7 +492,7 @@ void Item_subselect::recalc_used_tables(st_select_lex *new_parent,
upper->item->walk(&Item::enumerate_field_refs_processor, FALSE, upper->item->walk(&Item::enumerate_field_refs_processor, FALSE,
(uchar*)&fixer); (uchar*)&fixer);
used_tables_cache |= fixer.used_tables; used_tables_cache |= fixer.used_tables;
upper->item->walk(&Item::covering_keys_processor, FALSE, NULL); upper->item->walk(&Item::update_table_bitmaps_processor, FALSE, NULL);
/* /*
if (after_pullout) if (after_pullout)
upper->item->fix_after_pullout(new_parent, &(upper->item)); upper->item->fix_after_pullout(new_parent, &(upper->item));
......
...@@ -3411,7 +3411,7 @@ void SELECT_LEX::update_used_tables() ...@@ -3411,7 +3411,7 @@ void SELECT_LEX::update_used_tables()
while ((tl= ti++)) while ((tl= ti++))
{ {
TABLE_LIST *embedding; TABLE_LIST *embedding;
if (tl->table) if (tl->table && !tl->is_view_or_derived())
{ {
embedding= tl->embedding; embedding= tl->embedding;
for (embedding= tl->embedding; embedding; embedding=embedding->embedding) for (embedding= tl->embedding; embedding; embedding=embedding->embedding)
...@@ -3422,6 +3422,9 @@ void SELECT_LEX::update_used_tables() ...@@ -3422,6 +3422,9 @@ void SELECT_LEX::update_used_tables()
TABLE *tab= tl->table; TABLE *tab= tl->table;
tab->covering_keys= tab->s->keys_for_keyread; tab->covering_keys= tab->s->keys_for_keyread;
tab->covering_keys.intersect(tab->keys_in_use_for_query); tab->covering_keys.intersect(tab->keys_in_use_for_query);
tab->merge_keys.clear_all();
bitmap_clear_all(tab->read_set);
bitmap_clear_all(tab->vcol_set);
break; break;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment