Skip to content

Commit 9823918

Browse files
committed
auto up-merge (11827369)
2 parents 9c2eb00 + a6b7e21 commit 9823918

File tree

7 files changed

+24
-12
lines changed

7 files changed

+24
-12
lines changed

mysql-test/r/heap.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ EXPLAIN SELECT col_int_nokey FROM t2
771771
WHERE ('h', 0) NOT IN ( SELECT * FROM v1);
772772
id select_type table type possible_keys key key_len ref rows Extra
773773
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
774-
2 DEPENDENT SUBQUERY <derived3> index_subquery <auto_key0> <auto_key0> 12 const,const 2 Using index; Using where
774+
2 DEPENDENT SUBQUERY <derived3> ref_or_null <auto_key0> <auto_key0> 12 const,const 2 Using where; Using index
775775
3 DERIVED t1 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Using where
776776
DROP TABLE t1,t2,h1;
777777
DROP VIEW v1;

mysql-test/r/subquery_mat.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
13461346
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (Block Nested Loop)
13471347
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where
13481348
Warnings:
1349-
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`a`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` `t3` where (<if>(outer_field_is_not_null, ((<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`) or <cache>(isnull(`test`.`t3`.`a`))), true) and <if>(outer_field_is_not_null, ((<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`) or <cache>(isnull(`test`.`t3`.`a`))), true)) having (<if>(outer_field_is_not_null, <is_not_null_test>(`test`.`t3`.`a`), true) and <if>(outer_field_is_not_null, <is_not_null_test>(`test`.`t3`.`a`), true)))) AS `(t2.a,t2.a) in (select a,a from t2 as t3)` from `test`.`t1` left join `test`.`t2` on(((`test`.`t1`.`a` + `test`.`t2`.`a`) = 1000)) where 1
1349+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`a`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` `t3` where (<if>(outer_field_is_not_null, ((<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`) or <cache>(isnull(`test`.`t3`.`a`))), true) and <if>(outer_field_is_not_null, ((<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`) or <cache>(isnull(`test`.`t3`.`a`))), true)) having (<if>(outer_field_is_not_null, <cache>(<is_not_null_test>(`test`.`t3`.`a`)), true) and <if>(outer_field_is_not_null, <cache>(<is_not_null_test>(`test`.`t3`.`a`)), true)))) AS `(t2.a,t2.a) in (select a,a from t2 as t3)` from `test`.`t1` left join `test`.`t2` on(((`test`.`t1`.`a` + `test`.`t2`.`a`) = 1000)) where 1
13501350
select t1.a, t2.a, (t2.a,t2.a) in (select a,a from t2 as t3)
13511351
from t1 left join t2 on t1.a+t2.a=1000;
13521352
a a (t2.a,t2.a) in (select a,a from t2 as t3)

mysql-test/r/subquery_mat_all.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
13551355
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (Block Nested Loop)
13561356
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where
13571357
Warnings:
1358-
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`a`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` `t3` where (<if>(outer_field_is_not_null, ((<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`) or <cache>(isnull(`test`.`t3`.`a`))), true) and <if>(outer_field_is_not_null, ((<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`) or <cache>(isnull(`test`.`t3`.`a`))), true)) having (<if>(outer_field_is_not_null, <is_not_null_test>(`test`.`t3`.`a`), true) and <if>(outer_field_is_not_null, <is_not_null_test>(`test`.`t3`.`a`), true)))) AS `(t2.a,t2.a) in (select a,a from t2 as t3)` from `test`.`t1` left join `test`.`t2` on(((`test`.`t1`.`a` + `test`.`t2`.`a`) = 1000)) where 1
1358+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`a`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` `t3` where (<if>(outer_field_is_not_null, ((<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`) or <cache>(isnull(`test`.`t3`.`a`))), true) and <if>(outer_field_is_not_null, ((<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`) or <cache>(isnull(`test`.`t3`.`a`))), true)) having (<if>(outer_field_is_not_null, <cache>(<is_not_null_test>(`test`.`t3`.`a`)), true) and <if>(outer_field_is_not_null, <cache>(<is_not_null_test>(`test`.`t3`.`a`)), true)))) AS `(t2.a,t2.a) in (select a,a from t2 as t3)` from `test`.`t1` left join `test`.`t2` on(((`test`.`t1`.`a` + `test`.`t2`.`a`) = 1000)) where 1
13591359
select t1.a, t2.a, (t2.a,t2.a) in (select a,a from t2 as t3)
13601360
from t1 left join t2 on t1.a+t2.a=1000;
13611361
a a (t2.a,t2.a) in (select a,a from t2 as t3)

mysql-test/r/subquery_mat_none.result

+4-4
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
13171317
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 NULL
13181318
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
13191319
Warnings:
1320-
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`a`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` where ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`)) having (<is_not_null_test>(`test`.`t2`.`a`) and <is_not_null_test>(`test`.`t2`.`a`)))) AS `(a,a) in (select a,a from t2)` from `test`.`t1`
1320+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`a`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` where ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`)) having 1)) AS `(a,a) in (select a,a from t2)` from `test`.`t1`
13211321
select a, (a,a) in (select a,a from t2) from t1;
13221322
a (a,a) in (select a,a from t2)
13231323
1 1
@@ -1331,7 +1331,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
13311331
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (Block Nested Loop)
13321332
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where
13331333
Warnings:
1334-
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`a`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` `t3` where ((<cache>(`test`.`t1`.`a`) = `test`.`t3`.`a`) and (<cache>(`test`.`t1`.`a`) = `test`.`t3`.`a`)) having (<is_not_null_test>(`test`.`t3`.`a`) and <is_not_null_test>(`test`.`t3`.`a`)))) AS `(t1.a,t1.a) in (select a,a from t2 as t3)` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`a` + `test`.`t2`.`a`) = 1000)
1334+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`a`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` `t3` where ((<cache>(`test`.`t1`.`a`) = `test`.`t3`.`a`) and (<cache>(`test`.`t1`.`a`) = `test`.`t3`.`a`)) having 1)) AS `(t1.a,t1.a) in (select a,a from t2 as t3)` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`a` + `test`.`t2`.`a`) = 1000)
13351335
select t1.a, t2.a, (t1.a,t1.a) in (select a,a from t2 as t3)
13361336
from t1 join t2 on t1.a+t2.a=1000;
13371337
a a (t1.a,t1.a) in (select a,a from t2 as t3)
@@ -1345,7 +1345,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
13451345
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (Block Nested Loop)
13461346
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where
13471347
Warnings:
1348-
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`a`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` `t3` where (<if>(outer_field_is_not_null, ((<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`) or <cache>(isnull(`test`.`t3`.`a`))), true) and <if>(outer_field_is_not_null, ((<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`) or <cache>(isnull(`test`.`t3`.`a`))), true)) having (<if>(outer_field_is_not_null, <is_not_null_test>(`test`.`t3`.`a`), true) and <if>(outer_field_is_not_null, <is_not_null_test>(`test`.`t3`.`a`), true)))) AS `(t2.a,t2.a) in (select a,a from t2 as t3)` from `test`.`t1` left join `test`.`t2` on(((`test`.`t1`.`a` + `test`.`t2`.`a`) = 1000)) where 1
1348+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`a`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` `t3` where (<if>(outer_field_is_not_null, ((<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`) or <cache>(isnull(`test`.`t3`.`a`))), true) and <if>(outer_field_is_not_null, ((<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`) or <cache>(isnull(`test`.`t3`.`a`))), true)) having (<if>(outer_field_is_not_null, <cache>(<is_not_null_test>(`test`.`t3`.`a`)), true) and <if>(outer_field_is_not_null, <cache>(<is_not_null_test>(`test`.`t3`.`a`)), true)))) AS `(t2.a,t2.a) in (select a,a from t2 as t3)` from `test`.`t1` left join `test`.`t2` on(((`test`.`t1`.`a` + `test`.`t2`.`a`) = 1000)) where 1
13491349
select t1.a, t2.a, (t2.a,t2.a) in (select a,a from t2 as t3)
13501350
from t1 left join t2 on t1.a+t2.a=1000;
13511351
a a (t2.a,t2.a) in (select a,a from t2 as t3)
@@ -1398,7 +1398,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
13981398
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (Block Nested Loop)
13991399
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where
14001400
Warnings:
1401-
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where ((not(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`a`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` `t3` where ((<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`) and (<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`)) having (<is_not_null_test>(`test`.`t3`.`a`) and <is_not_null_test>(`test`.`t3`.`a`)))))) and ((`test`.`t1`.`a` + `test`.`t2`.`a`) = 3))
1401+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where ((not(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`a`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` `t3` where ((<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`) and (<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`)) having 1)))) and ((`test`.`t1`.`a` + `test`.`t2`.`a`) = 3))
14021402
select t1.a, t2.a
14031403
from t1 join t2 on t1.a+t2.a=3
14041404
where (t2.a,t2.a) not in (select a,a from t2 as t3);

sql/item.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -600,7 +600,7 @@ Item::Item(THD *thd, Item *item):
600600
fixed(item->fixed),
601601
collation(item->collation),
602602
cmp_context(item->cmp_context),
603-
with_subselect(item->with_subselect),
603+
with_subselect(item->has_subquery()),
604604
with_stored_program(item->with_stored_program),
605605
tables_locked_cache(item->tables_locked_cache)
606606
{

sql/item.h

+4
Original file line numberDiff line numberDiff line change
@@ -3175,6 +3175,10 @@ class Item_ref :public Item_ident
31753175
Field *get_tmp_table_field()
31763176
{ return result_field ? result_field : (*ref)->get_tmp_table_field(); }
31773177
Item *get_tmp_table_item(THD *thd);
3178+
bool const_item() const
3179+
{
3180+
return (*ref)->const_item() && (used_tables() == 0);
3181+
}
31783182
table_map used_tables() const
31793183
{
31803184
return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();

sql/item_cmpfunc.cc

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -5183,7 +5183,7 @@ longlong Item_func_isnull::val_int()
51835183
Handle optimization if the argument can't be null
51845184
This has to be here because of the test in update_used_tables().
51855185
*/
5186-
if (!used_tables_cache && !with_subselect && !with_stored_program)
5186+
if (const_item_cache)
51875187
return cached_value;
51885188
return args[0]->is_null() ? 1: 0;
51895189
}
@@ -5192,7 +5192,7 @@ longlong Item_is_not_null_test::val_int()
51925192
{
51935193
DBUG_ASSERT(fixed == 1);
51945194
DBUG_ENTER("Item_is_not_null_test::val_int");
5195-
if (!used_tables_cache && !with_subselect && !with_stored_program)
5195+
if (const_item_cache)
51965196
{
51975197
owner->was_null|= (!cached_value);
51985198
DBUG_PRINT("info", ("cached: %ld", (long) cached_value));
@@ -5215,9 +5215,11 @@ void Item_is_not_null_test::update_used_tables()
52155215
{
52165216
const table_map initial_pseudo_tables= get_initial_pseudo_tables();
52175217
used_tables_cache= initial_pseudo_tables;
5218+
const_item_cache= false;
52185219
if (!args[0]->maybe_null)
52195220
{
52205221
cached_value= 1;
5222+
const_item_cache= true;
52215223
return;
52225224
}
52235225
args[0]->update_used_tables();
@@ -5226,8 +5228,11 @@ void Item_is_not_null_test::update_used_tables()
52265228
used_tables_cache|= args[0]->used_tables();
52275229
if (used_tables_cache == initial_pseudo_tables && !with_subselect &&
52285230
!with_stored_program)
5231+
{
52295232
/* Remember if the value is always NULL or never NULL */
52305233
cached_value= !args[0]->is_null();
5234+
const_item_cache= true;
5235+
}
52315236
}
52325237

52335238

@@ -5478,6 +5483,9 @@ Item_func_regex::fix_fields(THD *thd, Item **ref)
54785483
args[1]->fix_fields(thd, args + 1)) || args[1]->check_cols(1))
54795484
return TRUE; /* purecov: inspected */
54805485
with_sum_func=args[0]->with_sum_func || args[1]->with_sum_func;
5486+
with_subselect= args[0]->has_subquery() || args[1]->has_subquery();
5487+
with_stored_program= args[0]->has_stored_program() ||
5488+
args[1]->has_stored_program();
54815489
max_length= 1;
54825490
decimals= 0;
54835491

0 commit comments

Comments
 (0)