summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorSergey Petrunya <psergey@askmonty.org>2011-10-27 00:23:48 +0400
committerSergey Petrunya <psergey@askmonty.org>2011-10-27 00:23:48 +0400
commit53b11ef2f47ed976c6fc2e6d16928f8684029ee2 (patch)
treedf5eb5e242225e9332c7f2d99225a3a8c387dd15 /sql
parent08115a80e5c5c150ff39813e61f57619a323fa53 (diff)
downloadmariadb-git-53b11ef2f47ed976c6fc2e6d16928f8684029ee2.tar.gz
Post-merge fixes: Fix problems in table_elim.test and enable it.
Diffstat (limited to 'sql')
-rw-r--r--sql/item_cmpfunc.cc9
-rw-r--r--sql/item_sum.cc19
2 files changed, 21 insertions, 7 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 3e7cc24dfd8..c0d3b14b71b 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -1424,7 +1424,11 @@ bool Item_in_optimizer::fix_left(THD *thd, Item **ref)
cache->setup(args[0]);
if (cache->cols() == 1)
{
- if ((used_tables_cache= args[0]->used_tables()))
+ /*
+ Note: there can be cases when used_tables()==0 && !const_item(). See
+ Item_sum::update_used_tables for details.
+ */
+ if ((used_tables_cache= args[0]->used_tables()) || !args[0]->const_item())
cache->set_used_tables(OUTER_REF_TABLE_BIT);
else
cache->set_used_tables(0);
@@ -1434,7 +1438,8 @@ bool Item_in_optimizer::fix_left(THD *thd, Item **ref)
uint n= cache->cols();
for (uint i= 0; i < n; i++)
{
- if (args[0]->element_index(i)->used_tables())
+ Item *element=args[0]->element_index(i);
+ if (element->used_tables() || !element->const_item())
((Item_cache *)cache->element_index(i))->set_used_tables(OUTER_REF_TABLE_BIT);
else
((Item_cache *)cache->element_index(i))->set_used_tables(0);
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index d60eb1415b9..0b8ae2d1d54 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -550,11 +550,20 @@ void Item_sum::update_used_tables ()
args[i]->update_used_tables();
used_tables_cache|= args[i]->used_tables();
}
-
- used_tables_cache&= PSEUDO_TABLE_BITS;
-
- /* the aggregate function is aggregated into its local context */
- used_tables_cache |= (1 << aggr_sel->join->table_count) - 1;
+ /*
+ MariaDB: don't run the following {
+
+ used_tables_cache&= PSEUDO_TABLE_BITS;
+
+ // the aggregate function is aggregated into its local context
+ used_tables_cache |= (1 << aggr_sel->join->table_count) - 1;
+
+ } because if we do it, table elimination will assume that
+ - constructs like "COUNT(*)" use columns from all tables
+ - so, it is not possible to eliminate any table
+ our solution for COUNT(*) is that it has
+ item->used_tables() == 0 && !item->const_item()
+ */
}
}