diff options
author | unknown <gkodinov/kgeorge@magare.gmz> | 2007-04-20 12:06:52 +0300 |
---|---|---|
committer | unknown <gkodinov/kgeorge@magare.gmz> | 2007-04-20 12:06:52 +0300 |
commit | 48039ab277838024be85836cc3378a903ad2794b (patch) | |
tree | 503df238204acc944162c36965213aa279fba89c | |
parent | cc76701e8f47ca52ca209150f49ba665a215c1d0 (diff) | |
parent | e0444ba436798b25c16bfe0097b87cc1d39a7b9a (diff) | |
download | mariadb-git-48039ab277838024be85836cc3378a903ad2794b.tar.gz |
Merge magare.gmz:/home/kgeorge/mysql/work/B27786-5.0-opt
into magare.gmz:/home/kgeorge/mysql/work/B27786-addon-5.1-opt
mysql-test/r/subselect3.result:
Auto merged
mysql-test/r/view.result:
Auto merged
sql/item_subselect.h:
Auto merged
sql/sql_view.cc:
Auto merged
mysql-test/t/view.test:
fixed testcase merge 5.0->5.1
sql/sql_lex.h:
merge fixes : 5.0->5.1
-rw-r--r-- | mysql-test/r/subselect3.result | 19 | ||||
-rw-r--r-- | mysql-test/r/view.result | 35 | ||||
-rw-r--r-- | mysql-test/t/subselect3.test | 18 | ||||
-rw-r--r-- | mysql-test/t/view.test | 16 | ||||
-rw-r--r-- | sql/item_subselect.h | 6 | ||||
-rw-r--r-- | sql/sql_lex.h | 7 | ||||
-rw-r--r-- | sql/sql_view.cc | 9 |
7 files changed, 107 insertions, 3 deletions
diff --git a/mysql-test/r/subselect3.result b/mysql-test/r/subselect3.result index 18feb7cb6b9..981f59e9787 100644 --- a/mysql-test/r/subselect3.result +++ b/mysql-test/r/subselect3.result @@ -692,3 +692,22 @@ a MAX(b) test 2 3 h 3 4 i DROP TABLE t1, t2; +CREATE TABLE t1 (a int); +CREATE TABLE t2 (b int, PRIMARY KEY(b)); +INSERT INTO t1 VALUES (1), (NULL), (4); +INSERT INTO t2 VALUES (3), (1),(2), (5), (4), (7), (6); +EXPLAIN EXTENDED +SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using index +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t1`.`a`) and (not(<in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 AS `Not_used` from `test`.`t1` where ((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`)) having <is_not_null_test>(`test`.`t1`.`a`)))))) +SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1)); +a +SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1 WHERE a > 4)); +a +1 +4 +DROP TABLE t1,t2; diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index a542d3270a2..8ebf4d40067 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -3311,6 +3311,41 @@ lgid clid 2 YES DROP VIEW v1; DROP table t1,t2; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3); +CREATE VIEW v1 AS SELECT a FROM t1 ORDER BY a; +SELECT * FROM t1 UNION SELECT * FROM v1; +a +1 +2 +3 +EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +2 UNION t1 ALL NULL NULL NULL NULL 3 +NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL +SELECT * FROM v1 UNION SELECT * FROM t1; +a +1 +2 +3 +EXPLAIN SELECT * FROM v1 UNION SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +2 UNION t1 ALL NULL NULL NULL NULL 3 +NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL +SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a; +a +1 +2 +3 +EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +2 UNION t1 ALL NULL NULL NULL NULL 3 +NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL Using filesort +DROP VIEW v1; +DROP TABLE t1; End of 5.0 tests. DROP DATABASE IF EXISTS `d-1`; CREATE DATABASE `d-1`; diff --git a/mysql-test/t/subselect3.test b/mysql-test/t/subselect3.test index 11468cd6759..dfe09968fa2 100644 --- a/mysql-test/t/subselect3.test +++ b/mysql-test/t/subselect3.test @@ -528,3 +528,21 @@ SELECT a, MAX(b), DROP TABLE t1, t2; + + +# +# Bug #27870: crash of an equijoin query with WHERE condition containing +# a subquery predicate of the form <join attr> NOT IN (SELECT ...) +# + +CREATE TABLE t1 (a int); +CREATE TABLE t2 (b int, PRIMARY KEY(b)); +INSERT INTO t1 VALUES (1), (NULL), (4); +INSERT INTO t2 VALUES (3), (1),(2), (5), (4), (7), (6); + +EXPLAIN EXTENDED +SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1)); +SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1)); +SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1 WHERE a > 4)); + +DROP TABLE t1,t2; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 620f292bc12..a599f948c1e 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -3197,6 +3197,22 @@ SELECT * FROM v1; DROP VIEW v1; DROP table t1,t2; +# +# Bug#27786: Inconsistent Operation Performing UNION On View With ORDER BY +# +CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1),(2),(3); +CREATE VIEW v1 AS SELECT a FROM t1 ORDER BY a; + +SELECT * FROM t1 UNION SELECT * FROM v1; +EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1; +SELECT * FROM v1 UNION SELECT * FROM t1; +EXPLAIN SELECT * FROM v1 UNION SELECT * FROM t1; +SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a; +EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a; + +DROP VIEW v1; +DROP TABLE t1; + --echo End of 5.0 tests. # diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 37264f2136f..7c21eac6ec3 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -277,7 +277,11 @@ public: { return pushed_cond_guards ? pushed_cond_guards + i : NULL; } - void set_cond_guard_var(int i, bool v) { pushed_cond_guards[i]= v; } + void set_cond_guard_var(int i, bool v) + { + if ( pushed_cond_guards) + pushed_cond_guards[i]= v; + } bool have_guarded_conds() { return test(pushed_cond_guards); } Item_func_not_all *upper_item; // point on NOT/NOP before ALL/SOME subquery diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 850586c6098..5a0e6bfdd0c 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -541,6 +541,7 @@ public: bool change_result(select_subselect *result, select_subselect *old_result); void set_limit(st_select_lex *values); void set_thd(THD *thd_arg) { thd= thd_arg; } + inline bool is_union (); friend void lex_start(THD *thd, const char *buf, uint length); friend int subselect_union_engine::exec(); @@ -795,6 +796,12 @@ private: }; typedef class st_select_lex SELECT_LEX; +inline bool st_select_lex_unit::is_union () +{ + return first_select()->next_select() && + first_select()->next_select()->linkage == UNION_TYPE; +} + #define ALTER_ADD_COLUMN (1L << 0) #define ALTER_DROP_COLUMN (1L << 1) #define ALTER_CHANGE_COLUMN (1L << 2) diff --git a/sql/sql_view.cc b/sql/sql_view.cc index f84847f2f9c..ee99a2974f4 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -1270,13 +1270,18 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, unit->slave= save_slave; // fix include_down initialisation } + /* + We can safely ignore the VIEW's ORDER BY if we merge into union + branch, as order is not important there. + */ + if (!table->select_lex->master_unit()->is_union()) + table->select_lex->order_list.push_back(&lex->select_lex.order_list); /* This SELECT_LEX will be linked in global SELECT_LEX list to make it processed by mysql_handle_derived(), but it will not be included to SELECT_LEX tree, because it will not be executed - */ - table->select_lex->order_list.push_back(&lex->select_lex.order_list); + */ goto ok; } |