summaryrefslogtreecommitdiff
path: root/sql/item_sum.h
diff options
context:
space:
mode:
authorSergey Petrunia <psergey@askmonty.org>2009-06-10 01:11:33 +0400
committerSergey Petrunia <psergey@askmonty.org>2009-06-10 01:11:33 +0400
commitfd485ad9889f2d8db6a2de6c61efb720cb97e96a (patch)
treef462823874fbcb7842e5dabe052c8b376323d1c1 /sql/item_sum.h
parentcf028a54746d6b166e9ffe8fa1e2e08569fe0dc1 (diff)
downloadmariadb-git-fd485ad9889f2d8db6a2de6c61efb720cb97e96a.tar.gz
MWL#17: Table elimination
- Make elimination work with aggregate functions. The problem was that aggregate functions reported all table bits in used_tables(), and that prevented table elimination. Fixed by making aggregate functions return more correct value from used_tables(). mysql-test/r/ps_11bugs.result: MWL#17: Table elimination - Update test results. The difference is because of Item_ref change: outer references to constants are now recognized as constants, too. mysql-test/r/subselect.result: - Update test results. The difference is because of Item_ref change: outer references to constants are now recognized as constants, too. mysql-test/r/table_elim.result: MWL#17: Table elimination - Check that elimination works in presense of aggreagate functions mysql-test/t/table_elim.test: MWL#17: Table elimination - Check that elimination works in presense of aggreagate functions sql/item.h: MWL#17: Table elimination - Add Item_ref::const_item() which calls (*ref)->const_item(). Before this diff Item_ref used the default implementation of const_item(){ return used_tables()==0; }. This is no longer true, as COUNT(*) now has used_tables()==0 but const_item()==FALSE. sql/item_sum.cc: MWL#17: Table elimination - Make Item_sum() and it descendants not to return all bits in used_tables(). This is needed because otherwise table elimination can't work in presense of aggregate functions - COUNT(*) now has used_tables()==0 and const_item()==FALSE. Had to change Item_ref::const_item() to account for this. sql/item_sum.h: MWL#17: Table elimination - Add comments
Diffstat (limited to 'sql/item_sum.h')
-rw-r--r--sql/item_sum.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/sql/item_sum.h b/sql/item_sum.h
index d991327d847..aec5830f381 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -255,6 +255,12 @@ protected:
*/
Item **orig_args, *tmp_orig_args[2];
table_map used_tables_cache;
+
+ /*
+ TRUE <=> We've managed to calculate the value of this Item in
+ opt_sum_query(), hence it can be considered constant at all subsequent
+ steps.
+ */
bool forced_const;
public:
@@ -341,6 +347,14 @@ public:
virtual const char *func_name() const= 0;
virtual Item *result_item(Field *field)
{ return new Item_field(field); }
+ /*
+ Return bitmap of tables that are needed to evaluate the item.
+
+ The implementation takes into account the used strategy: items resolved
+ at optimization phase report 0.
+ Items that depend on the number of rows only, e.g. COUNT(*) will report
+ zero, but will still false from const_item().
+ */
table_map used_tables() const { return used_tables_cache; }
void update_used_tables ();
void cleanup()