MySQL 8.0.39
Source Code Documentation
|
The distinct aggregator. More...
#include <item_sum.h>
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_decimal * | arg_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 |
TABLE * | table |
uint32 * | field_lengths |
Temp_table_param * | tmp_table_param |
Unique * | tree |
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_sum * | item_sum |
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
|
private |
|
inline |
|
override |
|
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.
false | success |
true | failure |
Implements Aggregator.
|
inlineoverridevirtual |
Implements Aggregator.
|
overridevirtual |
NULLness of being-aggregated argument.
use_null_value | Optimization: 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.
|
overridevirtual |
Decimal value of being-aggregated argument.
Implements Aggregator.
|
overridevirtual |
Floating point value of being-aggregated argument.
Implements Aggregator.
|
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.
|
static |
Correctly compare composite keys.
Used by the Unique class to compare keys. Will do correct comparisons for composite keys with various field types.
arg | Pointer to the relevant Aggregator_distinct instance |
a | left key image |
b | right key image |
<0 | if key1 < key2 |
=0 | if key1 = key2 |
>0 | if key1 > key2 |
|
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.
|
overridevirtual |
Called before feeding the first row.
Used to allocate/setup the internal structures used for aggregation.
thd | Thread descriptor |
false | success |
true | failure |
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.
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).
element | pointer to the row data. |
false | success |
true | failure |
|
friend |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
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.