Commit 3daaa8d5 authored by unknown's avatar unknown

Remove redundant code in opt_sum_query()

parent a0f7e755
...@@ -123,8 +123,11 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) ...@@ -123,8 +123,11 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
If the storage manager of 'tl' gives exact row count, compute the total If the storage manager of 'tl' gives exact row count, compute the total
number of rows. If there are no outer table dependencies, this count number of rows. If there are no outer table dependencies, this count
may be used as the real count. may be used as the real count.
Schema tables are filled after this function is invoked, so we can't
get row count
*/ */
if (tl->table->file->table_flags() & HA_NOT_EXACT_COUNT) if ((tl->table->file->table_flags() & HA_NOT_EXACT_COUNT) ||
tl->schema_table)
{ {
is_exact_count= FALSE; is_exact_count= FALSE;
count= 1; // ensure count != 0 count= 1; // ensure count != 0
...@@ -149,32 +152,16 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) ...@@ -149,32 +152,16 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
switch (item_sum->sum_func()) { switch (item_sum->sum_func()) {
case Item_sum::COUNT_FUNC: case Item_sum::COUNT_FUNC:
/* /*
If the expr in count(expr) can never be null we can change this If the expr in COUNT(expr) can never be null we can change this
to the number of rows in the tables if this number is exact and to the number of rows in the tables if this number is exact and
there are no outer joins. there are no outer joins.
*/ */
if (!conds && !((Item_sum_count*) item)->args[0]->maybe_null && if (!conds && !((Item_sum_count*) item)->args[0]->maybe_null &&
!outer_tables && is_exact_count) !outer_tables && is_exact_count)
{
longlong count= 1;
TABLE_LIST *table;
for (table= tables; table; table= table->next_leaf)
{
if (outer_tables || (table->table->file->table_flags() &
HA_NOT_EXACT_COUNT) || table->schema_table)
{
const_result= 0; // Can't optimize left join
break;
}
tables->table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
count*= table->table->file->records;
}
if (!table)
{ {
((Item_sum_count*) item)->make_const(count); ((Item_sum_count*) item)->make_const(count);
recalc_const_item= 1; recalc_const_item= 1;
} }
}
else else
const_result= 0; const_result= 0;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment