MySQL 8.4.2
Source Code Documentation
Aggregator_distinct Class Reference

The distinct aggregator. More...

#include <item_sum.h>

Inheritance diagram for Aggregator_distinct:
[legend]

Public Member Functions

 Aggregator_distinct (Item_sum *sum)
 
 ~Aggregator_distinct () override
 
Aggregator_type Aggrtype () override
 
bool setup (THD *) override
 Called before feeding the first row. More...
 
void clear () override
 Invalidate calculated value and clear the distinct rows. More...
 
bool add () override
 Process incoming row. More...
 
void endup () override
 Calculate the aggregate function value. More...
 
my_decimalarg_val_decimal (my_decimal *value) override
 Decimal value of being-aggregated argument. More...
 
double arg_val_real () override
 Floating point value of being-aggregated argument. More...
 
bool arg_is_null (bool use_null_value) override
 NULLness of being-aggregated argument. More...
 
bool unique_walk_function (void *element)
 Aggregate a distinct row from the distinct hash table. More...
 
- Public Member Functions inherited from Aggregator
 Aggregator (Item_sum *arg)
 
virtual ~Aggregator ()=default
 

Static Public Member Functions

static int composite_key_cmp (const void *arg, const void *a, const void *b)
 Correctly compare composite keys. More...
 

Private Types

enum  Const_distinct { NOT_CONST = 0 , CONST_NULL , CONST_NOT_NULL }
 

Private Attributes

bool endup_done
 
TABLEtable
 
uint32field_lengths
 
Temp_table_paramtmp_table_param
 
Uniquetree
 
uint tree_key_length
 
enum Aggregator_distinct::Const_distinct const_distinct
 
bool use_distinct_values
 When feeding back the data in endup() from Unique/temp table back to Item_sum::add() methods we must read the data from Unique (and not recalculate the functions that are given as arguments to the aggregate function. More...
 

Friends

class Item_sum_sum
 

Additional Inherited Members

- Public Types inherited from Aggregator
enum  Aggregator_type { SIMPLE_AGGREGATOR , DISTINCT_AGGREGATOR }
 
- Protected Attributes inherited from Aggregator
Item_sumitem_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 Enumeration Documentation

◆ Const_distinct

Enumerator
NOT_CONST 
CONST_NULL 

Set to true if the result is known to be always NULL.

If set deactivates creation and usage of the temporary table (in the 'table' member) and the Unique instance (in the 'tree' member) as well as the calculation of the final value on the first call to Item_sum::val_xxx(), Item_avg::val_xxx(), Item_count::val_xxx().

CONST_NOT_NULL 

Set to true if count distinct is on only const items.

Distinct on a const value will always be the constant itself. And count distinct of the same would always be 1. Similar to CONST_NULL, it avoids creation of temporary table and the Unique instance.

Constructor & Destructor Documentation

◆ Aggregator_distinct()

Aggregator_distinct::Aggregator_distinct ( Item_sum sum)
inline

◆ ~Aggregator_distinct()

Aggregator_distinct::~Aggregator_distinct ( )
override

Member Function Documentation

◆ add()

bool Aggregator_distinct::add ( )
overridevirtual

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.

◆ Aggrtype()

Aggregator_type Aggregator_distinct::Aggrtype ( )
inlineoverridevirtual

Implements Aggregator.

◆ arg_is_null()

bool Aggregator_distinct::arg_is_null ( bool  use_null_value)
overridevirtual

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.

◆ arg_val_decimal()

my_decimal * Aggregator_distinct::arg_val_decimal ( my_decimal value)
overridevirtual

Decimal value of being-aggregated argument.

Implements Aggregator.

◆ arg_val_real()

double Aggregator_distinct::arg_val_real ( )
overridevirtual

Floating point value of being-aggregated argument.

Implements Aggregator.

◆ clear()

void Aggregator_distinct::clear ( )
overridevirtual

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.

◆ composite_key_cmp()

int Aggregator_distinct::composite_key_cmp ( const void *  arg,
const void *  a,
const void *  b 
)
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
aleft key image
bright key image
Returns
comparison result
Return values
<0if key1 < key2
=0if key1 = key2
>0if key1 > key2

◆ endup()

void Aggregator_distinct::endup ( )
overridevirtual

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.

◆ setup()

bool Aggregator_distinct::setup ( THD thd)
overridevirtual

Called before feeding the first row.

Used to allocate/setup the internal structures used for aggregation.

Parameters
thdThread descriptor
Returns
status
Return values
falsesuccess
truefailure

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.

◆ unique_walk_function()

bool Aggregator_distinct::unique_walk_function ( void *  element)

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

Friends And Related Function Documentation

◆ Item_sum_sum

friend class Item_sum_sum
friend

Member Data Documentation

◆ const_distinct

enum Aggregator_distinct::Const_distinct Aggregator_distinct::const_distinct
private

◆ endup_done

bool Aggregator_distinct::endup_done
private

◆ field_lengths

uint32* Aggregator_distinct::field_lengths
private

◆ table

TABLE* Aggregator_distinct::table
private

◆ tmp_table_param

Temp_table_param* Aggregator_distinct::tmp_table_param
private

◆ tree

Unique* Aggregator_distinct::tree
private

◆ tree_key_length

uint Aggregator_distinct::tree_key_length
private

◆ use_distinct_values

bool Aggregator_distinct::use_distinct_values
private

When feeding back the data in endup() from Unique/temp table back to Item_sum::add() methods we must read the data from Unique (and not recalculate the functions that are given as arguments to the aggregate function.

This flag is to tell the arg_*() methods to take the data from the Unique instead of calling the relevant val_..() method.


The documentation for this class was generated from the following files: