summaryrefslogtreecommitdiff
path: root/sql/opt_sum.cc
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2010-05-26 13:18:18 -0700
committerIgor Babaev <igor@askmonty.org>2010-05-26 13:18:18 -0700
commit709a0a131021135e9fb7a2095fcfcbc223dfb126 (patch)
tree9f8143ae3fa17bac5ab74140da692228d73c283f /sql/opt_sum.cc
parentcb325eb2b2f738b63d162fb0d46cf335e4ae84a4 (diff)
downloadmariadb-git-709a0a131021135e9fb7a2095fcfcbc223dfb126.tar.gz
MWL#106: Backport optimizations for derived tables and views.
The main consolidated patch.
Diffstat (limited to 'sql/opt_sum.cc')
-rw-r--r--sql/opt_sum.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index cefb507a61e..370fa9a6904 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -74,10 +74,12 @@ static int maxmin_in_range(bool max_fl, Field* field, COND *cond);
# Multiplication of number of rows in all tables
*/
-static ulonglong get_exact_record_count(TABLE_LIST *tables)
+static ulonglong get_exact_record_count(List<TABLE_LIST> &tables)
{
ulonglong count= 1;
- for (TABLE_LIST *tl= tables; tl; tl= tl->next_leaf)
+ TABLE_LIST *tl;
+ List_iterator<TABLE_LIST> ti(tables);
+ while ((tl= ti++))
{
ha_rows tmp= tl->table->file->records();
if ((tmp == HA_POS_ERROR))
@@ -110,9 +112,11 @@ static ulonglong get_exact_record_count(TABLE_LIST *tables)
HA_ERR_... if a deadlock or a lock wait timeout happens, for example
*/
-int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
+int opt_sum_query(List<TABLE_LIST> &tables, List<Item> &all_fields,COND *conds)
{
List_iterator_fast<Item> it(all_fields);
+ List_iterator<TABLE_LIST> ti(tables);
+ TABLE_LIST *tl;
int const_result= 1;
bool recalc_const_item= 0;
ulonglong count= 1;
@@ -120,7 +124,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
table_map removed_tables= 0, outer_tables= 0, used_tables= 0;
table_map where_tables= 0;
Item *item;
- int error;
+ int error= 0;
if (conds)
where_tables= conds->used_tables();
@@ -129,7 +133,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
Analyze outer join dependencies, and, if possible, compute the number
of returned rows.
*/
- for (TABLE_LIST *tl= tables; tl; tl= tl->next_leaf)
+ while ((tl= ti++))
{
TABLE_LIST *embedded;
for (embedded= tl ; embedded; embedded= embedded->embedding)
@@ -170,6 +174,14 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
is_exact_count= FALSE;
count= 1; // ensure count != 0
}
+ else if (tl->is_materialized_derived())
+ {
+ /*
+ Can't remove a derived table as it's number of rows is just an
+ estimate.
+ */
+ return 0;
+ }
else
{
error= tl->table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);