My Project
Public Member Functions | Static Public Member Functions | Friends
Aggregator_distinct Class Reference

#include <item_sum.h>

Inheritance diagram for Aggregator_distinct:
Aggregator Sql_alloc

List of all members.

Public Member Functions

 Aggregator_distinct (Item_sum *sum)
Aggregator_type Aggrtype ()
bool setup (THD *)
void clear ()
bool add ()
void endup ()
virtual my_decimalarg_val_decimal (my_decimal *value)
virtual double arg_val_real ()
virtual bool arg_is_null (bool use_null_value)
bool unique_walk_function (void *element)

Static Public Member Functions

static int composite_key_cmp (void *arg, uchar *key1, uchar *key2)

Friends

class Item_sum_sum

Detailed Description

The distinct aggregator. Implements AGGFN (DISTINCT ..) Collects all the data into an Unique (similarly to what Item_sum_distinct does currently) and then (if applicable) iterates over the list of unique values and pumps them back into its object


Member Function Documentation

bool Aggregator_distinct::add ( ) [virtual]

Process incoming row.

Add it to Unique/temp hash table if it's unique. Skip the row if not unique. Prepare Aggregator_distinct to process the incoming stream. Create the temporary table and the Unique class if needed. Called by Item_sum::aggregator_add(). To actually get the result value in item_sum's buffers Aggregator_distinct::endup() must be called.

Returns:
status
Return values:
FALSEsuccess
TRUEfailure

Implements Aggregator.

bool Aggregator_distinct::arg_is_null ( bool  use_null_value) [virtual]

NULLness of being-aggregated argument.

Parameters:
use_null_valueOptimization: to determine if the argument is NULL we must, in the general case, call is_null() on it, which itself might call val_*() on it, which might be costly. If you just have called arg_val*(), you can pass use_null_value=true; this way, arg_is_null() might avoid is_null() and instead do a cheap read of the Item's null_value (updated by arg_val*()).

Implements Aggregator.

Decimal value of being-aggregated argument

Implements Aggregator.

double Aggregator_distinct::arg_val_real ( ) [virtual]

Floating point value of being-aggregated argument

Implements Aggregator.

void Aggregator_distinct::clear ( ) [virtual]

Invalidate calculated value and clear the distinct rows.

Frees space used by the internal data structures. Removes the accumulated distinct rows. Invalidates the calculated result.

Implements Aggregator.

int Aggregator_distinct::composite_key_cmp ( void *  arg,
uchar *  key1,
uchar *  key2 
) [static]

Correctly compare composite keys.

Used by the Unique class to compare keys. Will do correct comparisons for composite keys with various field types.

Parameters:
argPointer to the relevant Aggregator_distinct instance
key1left key image
key2right key image
Returns:
comparison result
Return values:
<0if key1 < key2
=0if key1 = key2
>0if key1 > key2
void Aggregator_distinct::endup ( ) [virtual]

Calculate the aggregate function value.

Since Distinct_aggregator::add() just collects the distinct rows, we must go over the distinct rows and feed them to the aggregation function before returning its value. This is what endup () does. It also sets the result validity flag endup_done to TRUE so it will not recalculate the aggregate value again if the Item_sum hasn't been reset.

Implements Aggregator.

C_MODE_END bool Aggregator_distinct::setup ( THD *  thd) [virtual]

Called before feeding the first row. Used to allocate/setup the internal structures used for aggregation.

Parameters:
thdThread descriptor
Returns:
status
Return values:
FALSEsuccess
TRUEfaliure

Prepares Aggregator_distinct to process the incoming stream. Creates the temporary table and the Unique class if needed. Called by Item_sum::aggregator_setup()

Create a table with an unique key over all parameters. If the list contains only const values, const_distinct is set to CONST_NOT_NULL to avoid creation of temp table and thereby counting as count(distinct of const values) will always be 1. If any of these const values is null, const_distinct is set to CONST_NULL to ensure aggregation does not happen.

Implements Aggregator.

Aggregate a distinct row from the distinct hash table.

Called for each row into the hash table 'Aggregator_distinct::table'. Includes the current distinct row into the calculation of the aggregate value. Uses the Field classes to get the value from the row. This function is used for AVG/SUM(DISTINCT). For COUNT(DISTINCT) it's called only when there are no blob arguments and the data don't fit into memory (so Unique makes persisted trees on disk).

Parameters:
elementpointer to the row data.
Returns:
status
Return values:
FALSEsuccess
TRUEfailure

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines