Commit 3984062b authored by Igor Babaev's avatar Igor Babaev

Merge.

parents c9e969b6 3f7d51d0
...@@ -4246,3 +4246,34 @@ a MIN(b) ...@@ -4246,3 +4246,34 @@ a MIN(b)
7 78 7 78
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1,t2; DROP TABLE t1,t2;
#
# LP bug #804686: query over a derived table using a view
# with a degenerated where condition
#
CREATE TABLE t1 (a int, b int);
INSERT INTO t1 VALUES (0,0), (1,0), (0,0), (1,1), (1,0);
CREATE VIEW v1 AS SELECT a,b FROM t1;
CREATE VIEW v2 AS SELECT a, MAX(b) AS b FROM t1 GROUP BY a;
SELECT * FROM (SELECT b FROM v1 WHERE b = 0) t WHERE b<>0;
b
SELECT * FROM (SELECT b FROM v2 WHERE b = 0) t WHERE b<>0;
b
SELECT * FROM (SELECT b FROM v1 WHERE b = 0) t WHERE b;
b
SELECT * FROM (SELECT b FROM v2 WHERE b = 0) t WHERE b;
b
EXPLAIN EXTENDED
SELECT * FROM (SELECT b FROM v1 WHERE b = 0) t WHERE b;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
Warnings:
Note 1003 select `test`.`t1`.`b` AS `b` from `test`.`t1` where 0
EXPLAIN EXTENDED
SELECT * FROM (SELECT b FROM v2 WHERE b = 0) t WHERE b;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
3 DERIVED t1 ALL NULL NULL NULL NULL 5 100.00 Using temporary; Using filesort
Warnings:
Note 1003 select `v2`.`b` AS `b` from `test`.`v2` where 0
DROP VIEW v1,v2;
DROP TABLE t1;
...@@ -4192,3 +4192,24 @@ SELECT a, MIN(b) FROM v1 GROUP BY a; ...@@ -4192,3 +4192,24 @@ SELECT a, MIN(b) FROM v1 GROUP BY a;
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1,t2; DROP TABLE t1,t2;
--echo #
--echo # LP bug #804686: query over a derived table using a view
--echo # with a degenerated where condition
--echo #
CREATE TABLE t1 (a int, b int);
INSERT INTO t1 VALUES (0,0), (1,0), (0,0), (1,1), (1,0);
CREATE VIEW v1 AS SELECT a,b FROM t1;
CREATE VIEW v2 AS SELECT a, MAX(b) AS b FROM t1 GROUP BY a;
SELECT * FROM (SELECT b FROM v1 WHERE b = 0) t WHERE b<>0;
SELECT * FROM (SELECT b FROM v2 WHERE b = 0) t WHERE b<>0;
SELECT * FROM (SELECT b FROM v1 WHERE b = 0) t WHERE b;
SELECT * FROM (SELECT b FROM v2 WHERE b = 0) t WHERE b;
EXPLAIN EXTENDED
SELECT * FROM (SELECT b FROM v1 WHERE b = 0) t WHERE b;
EXPLAIN EXTENDED
SELECT * FROM (SELECT b FROM v2 WHERE b = 0) t WHERE b;
DROP VIEW v1,v2;
DROP TABLE t1;
...@@ -6883,40 +6883,6 @@ bool Item_direct_ref::get_date(MYSQL_TIME *ltime,uint fuzzydate) ...@@ -6883,40 +6883,6 @@ bool Item_direct_ref::get_date(MYSQL_TIME *ltime,uint fuzzydate)
} }
Item* Item_direct_ref_to_ident::transform(Item_transformer transformer,
uchar *argument)
{
DBUG_ASSERT(!current_thd->is_stmt_prepare());
Item *new_item= ident->transform(transformer, argument);
if (!new_item)
return 0;
DBUG_ASSERT(new_item->type() == FIELD_ITEM || new_item->type() == REF_ITEM);
if (ident != new_item)
current_thd->change_item_tree((Item**)&ident, new_item);
return (this->*transformer)(argument);
}
Item* Item_direct_ref_to_ident::compile(Item_analyzer analyzer, uchar **arg_p,
Item_transformer transformer,
uchar *arg_t)
{
if (!(this->*analyzer)(arg_p))
return 0;
uchar *arg_v= *arg_p;
Item *new_item= ident->compile(analyzer, &arg_v, transformer, arg_t);
if (new_item && ident != new_item)
{
DBUG_ASSERT(new_item->type() == FIELD_ITEM || new_item->type() == REF_ITEM);
current_thd->change_item_tree((Item**)&ident, new_item);
}
return (this->*transformer)(arg_t);
}
Item_cache_wrapper::~Item_cache_wrapper() Item_cache_wrapper::~Item_cache_wrapper()
{ {
DBUG_ASSERT(expr_cache == 0); DBUG_ASSERT(expr_cache == 0);
......
...@@ -2570,8 +2570,8 @@ public: ...@@ -2570,8 +2570,8 @@ public:
Field *get_tmp_table_field() Field *get_tmp_table_field()
{ return result_field ? result_field : (*ref)->get_tmp_table_field(); } { return result_field ? result_field : (*ref)->get_tmp_table_field(); }
Item *get_tmp_table_item(THD *thd); Item *get_tmp_table_item(THD *thd);
inline table_map used_tables() const; table_map used_tables() const;
inline void update_used_tables(); void update_used_tables();
bool const_item() const bool const_item() const
{ {
return (*ref)->const_item(); return (*ref)->const_item();
...@@ -2713,9 +2713,6 @@ public: ...@@ -2713,9 +2713,6 @@ public:
virtual void print(String *str, enum_query_type query_type) virtual void print(String *str, enum_query_type query_type)
{ ident->print(str, query_type); } { ident->print(str, query_type); }
virtual Item* transform(Item_transformer transformer, uchar *arg);
virtual Item* compile(Item_analyzer analyzer, uchar **arg_p,
Item_transformer transformer, uchar *arg_t);
}; };
......
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