MySQL 8.4.2
Source Code Documentation
anonymous_namespace{cost_model.cc}::AggregateRowEstimator Class Reference

This class finds disjoint sets of aggregation terms that form prefixes of some non-hash index, and makes row estimates for those sets based on index metadata. More...

Classes

struct  Prefix
 A prefix of some key where each key_part corresponds to an aggregation term. More...
 

Public Member Functions

 AggregateRowEstimator (THD *thd, TermArray terms)
 
 AggregateRowEstimator (const AggregateRowEstimator &)=delete
 
AggregateRowEstimatoroperator= (const AggregateRowEstimator &)=delete
 
double MakeNextEstimate (THD *thd)
 Get the next row estimate. More...
 
const MutableOverflowBitsetGetConsumedTerms () const
 Get the set of terms for which we have found an index. More...
 

Static Public Attributes

static constexpr double kNoEstimate = -1.0
 Used to indicate that no more suitable indexes could be found. More...
 

Private Member Functions

TermArray::const_iterator FindField (const Field *field) const
 Find an Item_field pointing to 'field' in 'm_terms', if there is one. More...
 

Private Attributes

TermArray m_terms
 The aggregation terms. More...
 
MutableOverflowBitset m_consumed_terms
 The set of terms mapped to an index so far. More...
 
Mem_root_array< Prefix * > m_prefixes
 The index prefixes we found for 'm_terms'. More...
 

Detailed Description

This class finds disjoint sets of aggregation terms that form prefixes of some non-hash index, and makes row estimates for those sets based on index metadata.

Constructor & Destructor Documentation

◆ AggregateRowEstimator() [1/2]

anonymous_namespace{cost_model.cc}::AggregateRowEstimator::AggregateRowEstimator ( THD thd,
TermArray  terms 
)
Parameters
thdCurrent thread.
termsThe aggregation terms.

◆ AggregateRowEstimator() [2/2]

anonymous_namespace{cost_model.cc}::AggregateRowEstimator::AggregateRowEstimator ( const AggregateRowEstimator )
delete

Member Function Documentation

◆ FindField()

TermArray::const_iterator anonymous_namespace{cost_model.cc}::AggregateRowEstimator::FindField ( const Field field) const
inlineprivate

Find an Item_field pointing to 'field' in 'm_terms', if there is one.

Parameters
fieldThe field we look for.
Returns
An iterator to the position of 'field' in m_terms, or m_terms.cend().

◆ GetConsumedTerms()

const MutableOverflowBitset & anonymous_namespace{cost_model.cc}::AggregateRowEstimator::GetConsumedTerms ( ) const
inline

Get the set of terms for which we have found an index.

Bit number corresponds to position in the 'terms' argument to the constructor.

◆ MakeNextEstimate()

double anonymous_namespace{cost_model.cc}::AggregateRowEstimator::MakeNextEstimate ( THD thd)

Get the next row estimate.

We make the estimate as follows:

  1. Find the (non-hash) index where the remaining aggregation terms form the longest prefix of the index fields. For example, if we have aggregation terms [a,b,c,d] and we have indexes ix1 on [a,b], ix2 on [d,c,b,e], we pick ix2.
  2. Make an estimate of the number of distinct values for those fields (i.e. [d,c,b]) using index statistics. This is the row estimate.
  3. Remove those fields from the set of remaining terms. (In the example above, only [a] would now remain.
  4. Return the row estimate to the caller.
Returns
The estimate, or kNoEstimate if no more suitable indexes could be found.

◆ operator=()

AggregateRowEstimator & anonymous_namespace{cost_model.cc}::AggregateRowEstimator::operator= ( const AggregateRowEstimator )
delete

Member Data Documentation

◆ kNoEstimate

constexpr double anonymous_namespace{cost_model.cc}::AggregateRowEstimator::kNoEstimate = -1.0
staticconstexpr

Used to indicate that no more suitable indexes could be found.

◆ m_consumed_terms

MutableOverflowBitset anonymous_namespace{cost_model.cc}::AggregateRowEstimator::m_consumed_terms
private

The set of terms mapped to an index so far.

◆ m_prefixes

Mem_root_array<Prefix *> anonymous_namespace{cost_model.cc}::AggregateRowEstimator::m_prefixes
private

The index prefixes we found for 'm_terms'.

◆ m_terms

TermArray anonymous_namespace{cost_model.cc}::AggregateRowEstimator::m_terms
private

The aggregation terms.


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