Drizzled Public API Documentation

sum.cc File Reference
#include <config.h>
#include <drizzled/sql_select.h>
#include <drizzled/item/sum.h>
#include <drizzled/item/cmpfunc.h>
#include <drizzled/optimizer/sum.h>
#include <drizzled/plugin/storage_engine.h>
#include <drizzled/table_list.h>
#include <drizzled/key.h>
#include <drizzled/error.h>

Go to the source code of this file.

Namespaces

 drizzled
 TODO: Rename this file - func.h is stupid.
 

Functions

static bool drizzled::find_key_for_maxmin (bool max_fl, table_reference_st *ref, Field *field, COND *cond, uint32_t *range_fl, uint32_t *key_prefix_length)
 
static int drizzled::reckey_in_range (bool max_fl, table_reference_st *ref, Field *field, COND *cond, uint32_t range_fl, uint32_t prefix_len)
 
static int drizzled::maxmin_in_range (bool max_fl, Field *field, COND *cond)
 
static uint64_t drizzled::get_exact_record_count (TableList *tables)
 
static bool drizzled::matching_cond (bool max_fl, table_reference_st *ref, KeyInfo *keyinfo, KeyPartInfo *field_part, COND *cond, key_part_map *key_part_used, uint32_t *range_fl, uint32_t *prefix_len)
 

Detailed Description

Optimising of MIN(), MAX() and COUNT(*) queries without 'group by' clause by replacing the aggregate expression with a constant.

Given a table with a compound key on columns (a,b,c), the following types of queries are optimised (assuming the table handler supports the required methods)

SELECT COUNT(*) FROM t1[,t2,t3,...]
SELECT MIN(b) FROM t1 WHERE a=const
SELECT MAX(c) FROM t1 WHERE a=const AND b=const
SELECT MAX(b) FROM t1 WHERE a=const AND b<const
SELECT MIN(b) FROM t1 WHERE a=const AND b>const
SELECT MIN(b) FROM t1 WHERE a=const AND b BETWEEN const AND const
SELECT MAX(b) FROM t1 WHERE a=const AND b BETWEEN const AND const

Instead of '<' one can use '<=', '>', '>=' and '=' as well. Instead of 'a=const' the condition 'a IS NULL' can be used.

If all selected fields are replaced then we will also remove all involved tables and return the answer without any join. Thus, the following query will be replaced with a row of two constants:

SELECT MAX(b), MIN(d) FROM t1,t2
  WHERE a=const AND b<const AND d>const

(assuming a index for column d of table t2 is defined)

Definition in file sum.cc.