diff options
author | Sergey Petrunya <psergey@askmonty.org> | 2013-03-01 11:44:10 +0400 |
---|---|---|
committer | Sergey Petrunya <psergey@askmonty.org> | 2013-03-01 11:44:10 +0400 |
commit | 1a998ee23980bac0e7985a66763a4ed044356257 (patch) | |
tree | ed40e9d3c7cec084725e0dcc3dcf303812a9cb7f | |
parent | 9d72bbf84ccfe6b671cc5aa72109b0025929399e (diff) | |
parent | 4ad2fd7cdf1b95b73081f9fe61eae590504e455e (diff) | |
download | mariadb-git-1a998ee23980bac0e7985a66763a4ed044356257.tar.gz |
Merge 5.3->5.5
-rw-r--r-- | mysql-test/r/derived_view.result | 51 | ||||
-rw-r--r-- | mysql-test/t/derived_view.test | 34 | ||||
-rw-r--r-- | sql/item_cmpfunc.h | 12 | ||||
-rw-r--r-- | sql/sql_select.cc | 2 |
4 files changed, 93 insertions, 6 deletions
diff --git a/mysql-test/r/derived_view.result b/mysql-test/r/derived_view.result index 95ff464918c..8630087ba72 100644 --- a/mysql-test/r/derived_view.result +++ b/mysql-test/r/derived_view.result @@ -2164,6 +2164,57 @@ a set optimizer_switch=@save3912_optimizer_switch; drop table t1, t2, t3; # +# MDEV-4209: equi-join on BLOB column from materialized view +# or derived table +# +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='derived_with_keys=on'; +CREATE TABLE t1 (c1 text, c2 int); +INSERT INTO t1 VALUES ('a',1), ('c',3), ('g',7), ('d',4), ('c',3); +CREATE TABLE t2 (c1 text, c2 int); +INSERT INTO t2 VALUES ('b',2), ('c',3); +CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1; +EXPLAIN EXTENDED +SELECT v1.c1, v1.c2 FROM v1, t2 WHERE v1.c1=t2.c1 AND v1.c2=t2.c2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY <derived2> ref key0 key0 5 test.t2.c2 2 100.00 Using where +2 DERIVED t1 ALL NULL NULL NULL NULL 5 100.00 +Warnings: +Note 1003 select `v1`.`c1` AS `c1`,`v1`.`c2` AS `c2` from `test`.`v1` join `test`.`t2` where ((`v1`.`c1` = `test`.`t2`.`c1`) and (`v1`.`c2` = `test`.`t2`.`c2`)) +SELECT v1.c1, v1.c2 FROM v1, t2 WHERE v1.c1=t2.c1 AND v1.c2=t2.c2; +c1 c2 +c 3 +c 3 +EXPLAIN EXTENDED +SELECT t2.c1, t2.c2 FROM (SELECT c1 g, MAX(c2) m FROM t1 GROUP BY c1) t, t2 +WHERE t.g=t2.c1 AND t.m=t2.c2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY <derived2> ref key0 key0 5 test.t2.c2 2 100.00 Using where +2 DERIVED t1 ALL NULL NULL NULL NULL 5 100.00 Using temporary; Using filesort +Warnings: +Note 1003 select `test`.`t2`.`c1` AS `c1`,`test`.`t2`.`c2` AS `c2` from (select `test`.`t1`.`c1` AS `g`,max(`test`.`t1`.`c2`) AS `m` from `test`.`t1` group by `test`.`t1`.`c1`) `t` join `test`.`t2` where ((`t`.`g` = `test`.`t2`.`c1`) and (`t`.`m` = `test`.`t2`.`c2`)) +SELECT t2.c1, t2.c2 FROM (SELECT c1 g, MAX(c2) m FROM t1 GROUP BY c1) t, t2 +WHERE t.g=t2.c1 AND t.m=t2.c2; +c1 c2 +c 3 +EXPLAIN EXTENDED +SELECT v1.c1, v1.c2, t2.c1, t2.c2 FROM v1, t2 WHERE v1.c1=t2.c1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join) +2 DERIVED t1 ALL NULL NULL NULL NULL 5 100.00 +Warnings: +Note 1003 select `v1`.`c1` AS `c1`,`v1`.`c2` AS `c2`,`test`.`t2`.`c1` AS `c1`,`test`.`t2`.`c2` AS `c2` from `test`.`v1` join `test`.`t2` where (`v1`.`c1` = `test`.`t2`.`c1`) +SELECT v1.c1, v1.c2, t2.c1, t2.c2 FROM v1, t2 WHERE v1.c1=t2.c1; +c1 c2 c1 c2 +c 3 c 3 +c 3 c 3 +DROP VIEW v1; +DROP TABLE t1,t2; +set optimizer_switch=@save_optimizer_switch; +# # end of 5.3 tests # set optimizer_switch=@exit_optimizer_switch; diff --git a/mysql-test/t/derived_view.test b/mysql-test/t/derived_view.test index c7705294ef2..4b7e76e11ca 100644 --- a/mysql-test/t/derived_view.test +++ b/mysql-test/t/derived_view.test @@ -1512,6 +1512,40 @@ set optimizer_switch=@save3912_optimizer_switch; drop table t1, t2, t3; --echo # +--echo # MDEV-4209: equi-join on BLOB column from materialized view +--echo # or derived table +--echo # + +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='derived_with_keys=on'; + +CREATE TABLE t1 (c1 text, c2 int); +INSERT INTO t1 VALUES ('a',1), ('c',3), ('g',7), ('d',4), ('c',3); +CREATE TABLE t2 (c1 text, c2 int); +INSERT INTO t2 VALUES ('b',2), ('c',3); +CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1; + +EXPLAIN EXTENDED +SELECT v1.c1, v1.c2 FROM v1, t2 WHERE v1.c1=t2.c1 AND v1.c2=t2.c2; +SELECT v1.c1, v1.c2 FROM v1, t2 WHERE v1.c1=t2.c1 AND v1.c2=t2.c2; + +EXPLAIN EXTENDED +SELECT t2.c1, t2.c2 FROM (SELECT c1 g, MAX(c2) m FROM t1 GROUP BY c1) t, t2 + WHERE t.g=t2.c1 AND t.m=t2.c2; +SELECT t2.c1, t2.c2 FROM (SELECT c1 g, MAX(c2) m FROM t1 GROUP BY c1) t, t2 + WHERE t.g=t2.c1 AND t.m=t2.c2; + +EXPLAIN EXTENDED +SELECT v1.c1, v1.c2, t2.c1, t2.c2 FROM v1, t2 WHERE v1.c1=t2.c1; +SELECT v1.c1, v1.c2, t2.c1, t2.c2 FROM v1, t2 WHERE v1.c1=t2.c1; + +DROP VIEW v1; +DROP TABLE t1,t2; + +set optimizer_switch=@save_optimizer_switch; + + +--echo # --echo # end of 5.3 tests --echo # diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index cbff4db3d0f..cad8d7d34ac 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -1804,7 +1804,7 @@ public: from the list when performing an iteration. */ -template <template<class> class LI, class T> class Item_equal_iterator +template <template<class> class LI, typename T> class Item_equal_iterator : public LI<T> { protected: @@ -1842,13 +1842,14 @@ public: } }; +typedef Item_equal_iterator<List_iterator_fast,Item > Item_equal_iterator_fast; class Item_equal_fields_iterator - :public Item_equal_iterator<List_iterator_fast,Item > + :public Item_equal_iterator_fast { public: Item_equal_fields_iterator(Item_equal &item_eq) - :Item_equal_iterator<List_iterator_fast,Item>(item_eq) + :Item_equal_iterator_fast(item_eq) { } Item ** ref() { @@ -1856,13 +1857,14 @@ public: } }; +typedef Item_equal_iterator<List_iterator,Item > Item_equal_iterator_iterator_slow; class Item_equal_fields_iterator_slow - :public Item_equal_iterator<List_iterator,Item > + :public Item_equal_iterator_iterator_slow { public: Item_equal_fields_iterator_slow(Item_equal &item_eq) - :Item_equal_iterator<List_iterator,Item>(item_eq) + :Item_equal_iterator_iterator_slow(item_eq) { } void remove() { diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 8792be20915..96ec6881d96 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4022,7 +4022,7 @@ add_key_field(JOIN *join, !(field->table->pos_in_table_list->is_materialized_derived() && field->table->created)) || (field->table->pos_in_table_list->is_materialized_derived() && - !field->table->created))) + !field->table->created && !(field->flags & BLOB_FLAG)))) { optimize= KEY_OPTIMIZE_EQ; } |