MySQL 8.0.40
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 (const TermArray &terms, string *trace)
 
 AggregateRowEstimator (const AggregateRowEstimator &)=delete
 
AggregateRowEstimatoroperator= (const AggregateRowEstimator &)=delete
 
double MakeNextEstimate ()
 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

const TermArraym_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 {current_thd->mem_root}
 The index prefixes we found for 'm_terms'. More...
 
string * m_trace
 Optimizer trace text. 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 ( const TermArray terms,
string *  trace 
)
Parameters
termsThe aggregation terms.
traceAppend optimizer trace text to this if non-null.

◆ 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 ( )

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 {current_thd->mem_root}
private

The index prefixes we found for 'm_terms'.

◆ m_terms

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

The aggregation terms.

◆ m_trace

string* anonymous_namespace{cost_model.cc}::AggregateRowEstimator::m_trace
private

Optimizer trace text.


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