diff options
author | unknown <gkodinov/kgeorge@macbook.local> | 2007-03-20 19:46:02 +0200 |
---|---|---|
committer | unknown <gkodinov/kgeorge@macbook.local> | 2007-03-20 19:46:02 +0200 |
commit | 9c89dd654e90d85fefc2459711063b680ed10f24 (patch) | |
tree | 910911efb4f7c49f4623fc917f9e7d62b984a2c7 /sql/opt_range.cc | |
parent | a30830460794651c0e9fc5ec4779cf77680514ee (diff) | |
download | mariadb-git-9c89dd654e90d85fefc2459711063b680ed10f24.tar.gz |
Bug #24484:
To correctly decide which predicates can be evaluated with a given table
the optimizer must know the exact set of tables that a predicate depends
on. If that mask is too wide (refer to non-existing tables) the optimizer
can erroneously skip a predicate.
One such case of wrong table usage mask were the aggregate functions.
The have a all-1 mask (meaning depend on all tables, including non-existent
ones).
Fixed by making a real used_tables mask for the aggregates. The mask is
constructed in the following way :
1. OR the table dependency masks of all the arguments of the aggregate.
2. If all the arguments of the function are from the local name resolution
context and it is evaluated in the same name resolution
context where it is referenced all the tables from that name resolution
context are OR-ed to the dependency mask. This is to denote that an
aggregate function depends on the number of rows it processes.
3. Handle correctly the case of an aggregate function optimization (such that
the aggregate function can be pre-calculated and made a constant).
Made sure that an aggregate function is never a constant (unless subject of a
specific optimization and pre-calculation).
One other flaw was revealed and fixed in the process : references were
not calling the recalculation method for used_tables of their targets.
mysql-test/r/subselect3.result:
Bug #24484: test case
mysql-test/t/subselect3.test:
Bug #24484: test case
sql/item.h:
Bug #24484: Item_ref must update the used tables.
sql/item_sum.cc:
Bug #24484: correct calculation of used_tables for aggregates.
sql/item_sum.h:
Bug #24484: correct calculation of used_tables for aggregates.
sql/opt_range.cc:
Bug #24484: fixed ref resolution in loose index scan
sql/sql_base.cc:
Bug #24484: moved counting of leaf tables inside
setup_tables_and_check_access.
sql/sql_class.h:
Bug #24484: changed table count to more narrow type.
sql/sql_insert.cc:
Bug #24484: moved counting of leaf tables inside
setup_tables_and_check_access. Substract the first
table (and its subtables) of an INSERT statement
from leaf_count.
sql/sql_select.cc:
Bug #24484: correct check for aggregates
Diffstat (limited to 'sql/opt_range.cc')
-rw-r--r-- | sql/opt_range.cc | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/sql/opt_range.cc b/sql/opt_range.cc index f0af4b7db2a..8985561dd30 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -7516,7 +7516,8 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree) else DBUG_RETURN(NULL); - Item *expr= min_max_item->args[0]; /* The argument of MIN/MAX. */ + /* The argument of MIN/MAX. */ + Item *expr= min_max_item->args[0]->real_item(); if (expr->type() == Item::FIELD_ITEM) /* Is it an attribute? */ { if (! min_max_arg_item) @@ -7894,6 +7895,7 @@ check_group_min_max_predicates(COND *cond, Item_field *min_max_arg_item, DBUG_ENTER("check_group_min_max_predicates"); DBUG_ASSERT(cond && min_max_arg_item); + cond= cond->real_item(); Item::Type cond_type= cond->type(); if (cond_type == Item::COND_ITEM) /* 'AND' or 'OR' */ { @@ -7931,7 +7933,7 @@ check_group_min_max_predicates(COND *cond, Item_field *min_max_arg_item, DBUG_PRINT("info", ("Analyzing: %s", pred->func_name())); for (uint arg_idx= 0; arg_idx < pred->argument_count (); arg_idx++) { - cur_arg= arguments[arg_idx]; + cur_arg= arguments[arg_idx]->real_item(); DBUG_PRINT("info", ("cur_arg: %s", cur_arg->full_name())); if (cur_arg->type() == Item::FIELD_ITEM) { |