Commit 48039ab2 authored by unknown's avatar unknown

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
parents cc76701e e0444ba4
......@@ -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;
......@@ -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`;
......
......@@ -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;
......@@ -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.
#
......
......@@ -277,7 +277,11 @@ class Item_in_subselect :public Item_exists_subselect
{
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
......
......@@ -541,6 +541,7 @@ class st_select_lex_unit: public st_select_lex_node {
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 @@ class st_select_lex: public st_select_lex_node
};
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)
......
......@@ -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;
}
......
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