Commit 0e4d88f1 authored by Igor Babaev's avatar Igor Babaev

Merge.

parents 29c3debd 945f12cf
......@@ -1504,4 +1504,34 @@ a b c
20 r r
DROP VIEW v1;
DROP TABLE t1,t2,t3;
#
# LP bug #877316: query over a view with correlated subquery in WHERE
#
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a)) ;
INSERT INTO t1 VALUES (18,2), (19,9);
CREATE TABLE t2 (a int, b int) ;
INSERT INTO t2 VALUES (10,8), (5,10);
CREATE VIEW v1 AS SELECT * FROM t1;
SELECT t1.a FROM t1
WHERE EXISTS (SELECT t2.a FROM t2 WHERE t2.b < t1.b);
a
19
EXPLAIN
SELECT t1.a FROM t1
WHERE EXISTS (SELECT t2.a FROM t2 WHERE t2.b < t1.b);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
SELECT v1.a FROM v1
WHERE EXISTS (SELECT t2.a FROM t2 WHERE t2.b < v1.b);
a
19
EXPLAIN
SELECT v1.a FROM v1
WHERE EXISTS (SELECT t2.a FROM t2 WHERE t2.b < v1.b);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
DROP VIEW v1;
DROP TABLE t1,t2;
set optimizer_switch=@exit_optimizer_switch;
......@@ -946,6 +946,32 @@ SELECT * FROM t3
DROP VIEW v1;
DROP TABLE t1,t2,t3;
--echo #
--echo # LP bug #877316: query over a view with correlated subquery in WHERE
--echo #
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a)) ;
INSERT INTO t1 VALUES (18,2), (19,9);
CREATE TABLE t2 (a int, b int) ;
INSERT INTO t2 VALUES (10,8), (5,10);
CREATE VIEW v1 AS SELECT * FROM t1;
SELECT t1.a FROM t1
WHERE EXISTS (SELECT t2.a FROM t2 WHERE t2.b < t1.b);
EXPLAIN
SELECT t1.a FROM t1
WHERE EXISTS (SELECT t2.a FROM t2 WHERE t2.b < t1.b);
SELECT v1.a FROM v1
WHERE EXISTS (SELECT t2.a FROM t2 WHERE t2.b < v1.b);
EXPLAIN
SELECT v1.a FROM v1
WHERE EXISTS (SELECT t2.a FROM t2 WHERE t2.b < v1.b);
DROP VIEW v1;
DROP TABLE t1,t2;
# The following command must be the last one the file
set optimizer_switch=@exit_optimizer_switch;
......@@ -2172,6 +2172,12 @@ bool Item_field::enumerate_field_refs_processor(uchar *arg)
return FALSE;
}
bool Item_field::covering_keys_processor(uchar *arg)
{
if (field && field->table)
field->table->covering_keys.intersect(field->part_of_key);
return FALSE;
}
const char *Item_ident::full_name() const
{
......
......@@ -1018,6 +1018,7 @@ public:
virtual bool mark_as_eliminated_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 covering_keys_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 clear_sum_processor(uchar *opt_arg) { return 0; }
......@@ -1832,6 +1833,7 @@ public:
bool vcol_in_partition_func_processor(uchar *bool_arg);
bool check_vcol_func_processor(uchar *arg) { return FALSE;}
bool enumerate_field_refs_processor(uchar *arg);
bool covering_keys_processor(uchar *arg);
void cleanup();
Item_equal *get_item_equal() { return item_equal; }
void set_item_equal(Item_equal *item_eq) { item_equal= item_eq; }
......
......@@ -492,6 +492,7 @@ void Item_subselect::recalc_used_tables(st_select_lex *new_parent,
upper->item->walk(&Item::enumerate_field_refs_processor, FALSE,
(uchar*)&fixer);
used_tables_cache |= fixer.used_tables;
upper->item->walk(&Item::covering_keys_processor, FALSE, NULL);
/*
if (after_pullout)
upper->item->fix_after_pullout(new_parent, &(upper->item));
......
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