MySQL  8.0.19
Source Code Documentation
RowIterator Class Referenceabstract

A context for reading through a single table using a chosen access method: index read, scan, etc, use of cache, etc. More...

#include <row_iterator.h>

Inheritance diagram for RowIterator:
AggregateIterator AlternativeIterator AppendIterator BKAIterator BufferingWindowingIterator CacheInvalidatorIterator FakeSingleRowIterator FilterIterator HashJoinIterator LimitOffsetIterator MaterializeInformationSchemaTableIterator NestedLoopIterator NestedLoopSemiJoinWithDuplicateRemovalIterator PrecomputedAggregateIterator RemoveDuplicatesIterator SortingIterator TableRowIterator TableValueConstructorIterator TimingIterator< RealIterator > UnqualifiedCountIterator WeedoutIterator WindowingIterator ZeroRowsAggregatedIterator ZeroRowsIterator

Classes

struct  Child
 

Public Member Functions

 RowIterator (THD *thd)
 
virtual ~RowIterator ()
 
virtual bool Init ()=0
 Initialize or reinitialize the iterator. More...
 
virtual int Read ()=0
 Read a single row. More...
 
virtual void SetNullRowFlag (bool is_null_row)=0
 Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag is true, you'll get only NULLs no matter what is actually in the buffer (typically some old leftover row). More...
 
virtual void UnlockRow ()=0
 
virtual std::vector< Childchildren () const
 List of zero or more iterators which are direct children of this one. More...
 
virtual std::vector< std::string > DebugString () const =0
 Returns a short string (used for EXPLAIN FORMAT=tree) with user-readable information for this iterator. More...
 
virtual std::string TimingString () const
 
JOINjoin_for_explain () const
 
void set_join_for_explain (JOIN *join)
 
virtual void StartPSIBatchMode ()
 Start performance schema batch mode, if supported (otherwise ignored). More...
 
virtual void EndPSIBatchModeIfStarted ()
 Ends performance schema batch mode, if started. More...
 
void set_estimated_cost (double estimated_cost)
 
double estimated_cost () const
 
void set_expected_rows (double expected_rows)
 
double expected_rows () const
 
virtual RowIteratorreal_iterator ()
 If this iterator is wrapping a different iterator (e.g. More...
 
virtual const RowIteratorreal_iterator () const
 

Protected Member Functions

THDthd () const
 

Private Attributes

THD *const m_thd
 
JOINm_join_for_explain = nullptr
 
double m_estimated_cost = -1.0
 
double m_expected_rows = -1.0
 

Detailed Description

A context for reading through a single table using a chosen access method: index read, scan, etc, use of cache, etc.

. It is mostly meant as an interface, but also contains some private member functions that are useful for many implementations, such as error handling.

A RowIterator is a simple iterator; you initialize it, and then read one record at a time until Read() returns EOF. A RowIterator can read from other Iterators if you want to, e.g., SortingIterator, which takes in records from another RowIterator and sorts them.

The abstraction is not completely tight. In particular, it still leaves some specifics to TABLE, such as which columns to read (the read_set). This means it would probably be hard as-is to e.g. sort a join of two tables.

Use by:

unique_ptr<RowIterator> iterator(new ...);
if (iterator->Init())
return true;
while (iterator->Read() == 0) {
...
}

Constructor & Destructor Documentation

◆ RowIterator()

RowIterator::RowIterator ( THD thd)
inline

◆ ~RowIterator()

virtual RowIterator::~RowIterator ( )
inlinevirtual

Member Function Documentation

◆ children()

virtual std::vector<Child> RowIterator::children ( ) const
inlinevirtual

◆ DebugString()

virtual std::vector<std::string> RowIterator::DebugString ( ) const
pure virtual

Returns a short string (used for EXPLAIN FORMAT=tree) with user-readable information for this iterator.

When implementing these, try to avoid internal jargon (e.g. “eq_ref”); prefer things that read like normal, technical English (e.g. “single-row index lookup”).

For certain complex operations, such as MaterializeIterator, there can be multiple strings. If so, they are interpreted as nested operations, with the outermost, last-done operation first and the other ones indented as if they were child iterators.

Callers should use FullDebugString() below, which adds costs (see set_estimated_cost() etc.) if present.

Implemented in AppendIterator, MaterializeInformationSchemaTableIterator, BufferingWindowingIterator, WindowingIterator, NestedLoopSemiJoinWithDuplicateRemovalIterator, RemoveDuplicatesIterator, WeedoutIterator, MaterializedTableFunctionIterator, TemptableAggregateIterator, StreamingIterator, MaterializeIterator, TableValueConstructorIterator, CacheInvalidatorIterator, FollowTailIterator, NestedLoopIterator, ZeroRowsAggregatedIterator, ZeroRowsIterator, PrecomputedAggregateIterator, UnqualifiedCountIterator, FakeSingleRowIterator, SortFileIndirectIterator, MultiRangeRowIterator, AlternativeIterator, SortFileIterator< Packed_addon_fields >, AggregateIterator, PushedJoinRefIterator, SortBufferIndirectIterator, HashJoinIterator, SortBufferIterator< Packed_addon_fields >, DynamicRangeIterator, FullTextSearchIterator, LimitOffsetIterator, IndexRangeScanIterator, ConstIterator, BKAIterator, IndexScanIterator< Reverse >, EQRefIterator, SortingIterator, FilterIterator, RefOrNullIterator, TableScanIterator, TimingIterator< RealIterator >, and RefIterator< Reverse >.

◆ EndPSIBatchModeIfStarted()

virtual void RowIterator::EndPSIBatchModeIfStarted ( )
inlinevirtual

Ends performance schema batch mode, if started.

It's always safe to call this.

Iterators that have children (composite iterators) must forward the EndPSIBatchModeIfStarted() call to every iterator they could conceivably have called StartPSIBatchMode() on. This ensures that after such a call to on the root iterator, all handlers are out of batch mode.

Reimplemented in AppendIterator, MaterializeInformationSchemaTableIterator, BufferingWindowingIterator, WindowingIterator, NestedLoopSemiJoinWithDuplicateRemovalIterator, RemoveDuplicatesIterator, WeedoutIterator, MaterializedTableFunctionIterator, TemptableAggregateIterator, StreamingIterator, MaterializeIterator, NestedLoopIterator, PrecomputedAggregateIterator, TableRowIterator, AggregateIterator, HashJoinIterator, LimitOffsetIterator, BKAIterator, FilterIterator, and TimingIterator< RealIterator >.

◆ estimated_cost()

double RowIterator::estimated_cost ( ) const
inline

◆ expected_rows()

double RowIterator::expected_rows ( ) const
inline

◆ Init()

virtual bool RowIterator::Init ( )
pure virtual

Initialize or reinitialize the iterator.

You must always call Init() before trying a Read() (but Init() does not imply Read()).

You can call Init() multiple times; subsequent calls will rewind the iterator (or reposition it, depending on whether the iterator takes in e.g. a TABLE_REF) and allow you to read the records anew.

Implemented in AppendIterator, MaterializeInformationSchemaTableIterator, BufferingWindowingIterator, WindowingIterator, NestedLoopSemiJoinWithDuplicateRemovalIterator, RemoveDuplicatesIterator, WeedoutIterator, MaterializedTableFunctionIterator, TemptableAggregateIterator, StreamingIterator, MaterializeIterator, TableValueConstructorIterator, CacheInvalidatorIterator, FollowTailIterator, NestedLoopIterator, ZeroRowsAggregatedIterator, ZeroRowsIterator, UnqualifiedCountIterator, PrecomputedAggregateIterator, FakeSingleRowIterator, SortFileIndirectIterator, MultiRangeRowIterator, AlternativeIterator, SortFileIterator< Packed_addon_fields >, SortFileIterator< false >, SortFileIterator< true >, PushedJoinRefIterator, AggregateIterator, SortBufferIndirectIterator, HashJoinIterator, SortBufferIterator< Packed_addon_fields >, DynamicRangeIterator, SortBufferIterator< false >, SortBufferIterator< true >, FullTextSearchIterator, IndexRangeScanIterator, LimitOffsetIterator, ConstIterator, BKAIterator, IndexScanIterator< Reverse >, EQRefIterator, SortingIterator, FilterIterator, RefOrNullIterator, TableScanIterator, RefIterator< Reverse >, and TimingIterator< RealIterator >.

◆ join_for_explain()

JOIN* RowIterator::join_for_explain ( ) const
inline

◆ Read()

◆ real_iterator() [1/2]

virtual RowIterator* RowIterator::real_iterator ( )
inlinevirtual

If this iterator is wrapping a different iterator (e.g.

TimingIterator<T>) and you need to down_cast<> to a specific iterator type, this allows getting at the wrapped iterator.

Reimplemented in TimingIterator< RealIterator >.

◆ real_iterator() [2/2]

virtual const RowIterator* RowIterator::real_iterator ( ) const
inlinevirtual

Reimplemented in TimingIterator< RealIterator >.

◆ set_estimated_cost()

void RowIterator::set_estimated_cost ( double  estimated_cost)
inline

◆ set_expected_rows()

void RowIterator::set_expected_rows ( double  expected_rows)
inline

◆ set_join_for_explain()

void RowIterator::set_join_for_explain ( JOIN join)
inline

◆ SetNullRowFlag()

virtual void RowIterator::SetNullRowFlag ( bool  is_null_row)
pure virtual

Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag is true, you'll get only NULLs no matter what is actually in the buffer (typically some old leftover row).

This is used for outer joins, when an iterator hasn't produced any rows and we need to produce a NULL-complemented row. Init() or Read() won't necessarily reset this flag, so if you ever set is to true, make sure to also set it to false when needed.

Note that this can be called without Init() having been called first. For example, NestedLoopIterator can hit EOF immediately on the outer iterator, which means the inner iterator doesn't get an Init() call, but will still forward SetNullRowFlag to both inner and outer iterators.

TODO: We shouldn't need this. See the comments on AggregateIterator for a bit more discussion on abstracting out a row interface.

Implemented in TableValueConstructorIterator, ZeroRowsAggregatedIterator, ZeroRowsIterator, UnqualifiedCountIterator, FakeSingleRowIterator, AppendIterator, MaterializeInformationSchemaTableIterator, BufferingWindowingIterator, WindowingIterator, NestedLoopSemiJoinWithDuplicateRemovalIterator, RemoveDuplicatesIterator, WeedoutIterator, MaterializedTableFunctionIterator, TemptableAggregateIterator, MaterializeIterator, CacheInvalidatorIterator, NestedLoopIterator, PrecomputedAggregateIterator, TableRowIterator, AlternativeIterator, AggregateIterator, HashJoinIterator, LimitOffsetIterator, BKAIterator, SortingIterator, FilterIterator, and TimingIterator< RealIterator >.

◆ StartPSIBatchMode()

virtual void RowIterator::StartPSIBatchMode ( )
inlinevirtual

Start performance schema batch mode, if supported (otherwise ignored).

PFS batch mode is a mitigation to reduce the overhead of performance schema, typically applied at the innermost table of the entire join. If you start it before scanning the table and then end it afterwards, the entire set of handler calls will be timed only once, as a group, and the costs will be distributed evenly out. This reduces timer overhead.

If you start PFS batch mode, you must also take care to end it at the end of the scan, one way or the other. Do note that this is true even if the query ends abruptly (LIMIT is reached, or an error happens). The easiest workaround for this is to simply call EndPSIBatchModeIfStarted() on the root iterator at the end of the scan. See the PFSBatchMode class for a useful helper.

The rules for starting batch and ending mode are:

  1. If you are an iterator with exactly one child (FilterIterator etc.), forward any StartPSIBatchMode() calls to it.
  2. If you drive an iterator (read rows from it using a for loop or similar), use PFSBatchMode as described above.
  3. If you have multiple children, ignore the call and do your own handling of batch mode as appropriate. For materialization, #2 would typically apply. For joins, it depends on the join type (e.g., NestedLoopIterator applies batch mode only when scanning the innermost table).

The upshot of this is that when scanning a single table, batch mode will typically be activated for that table (since we call StartPSIBatchMode() on the root iterator, and it will trickle all the way down to the table iterator), but for a join, the call will be ignored and the join iterator will activate batch mode by itself as needed.

Reimplemented in AppendIterator, MaterializeInformationSchemaTableIterator, BufferingWindowingIterator, WindowingIterator, RemoveDuplicatesIterator, MaterializedTableFunctionIterator, StreamingIterator, MaterializeIterator, PrecomputedAggregateIterator, TableRowIterator, AggregateIterator, LimitOffsetIterator, EQRefIterator, FilterIterator, and TimingIterator< RealIterator >.

◆ thd()

THD* RowIterator::thd ( ) const
inlineprotected

◆ TimingString()

virtual std::string RowIterator::TimingString ( ) const
inlinevirtual

Reimplemented in TimingIterator< RealIterator >.

◆ UnlockRow()

Member Data Documentation

◆ m_estimated_cost

double RowIterator::m_estimated_cost = -1.0
private

◆ m_expected_rows

double RowIterator::m_expected_rows = -1.0
private

◆ m_join_for_explain

JOIN* RowIterator::m_join_for_explain = nullptr
private

◆ m_thd

THD* const RowIterator::m_thd
private

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