MySQL  8.0.20
Source Code Documentation
FollowTailIterator Class Referencefinal

FollowTailIterator is a special version of TableScanIterator that is used as part of WITH RECURSIVE queries. More...

#include <basic_row_iterators.h>

Inheritance diagram for FollowTailIterator:
TableRowIterator RowIterator

Public Member Functions

 FollowTailIterator (THD *thd, TABLE *table, QEP_TAB *qep_tab, ha_rows *examined_rows)
 
 ~FollowTailIterator () override
 
bool Init () override
 Initialize or reinitialize the iterator. More...
 
int Read () override
 Read a single row. More...
 
std::vector< std::string > DebugString () const override
 Returns a short string (used for EXPLAIN FORMAT=tree) with user-readable information for this iterator. More...
 
void set_stored_rows_pointer (ha_rows *stored_rows)
 Signal where we can expect to find the number of generated rows for this materialization (this points into the MaterializeIterator's data). More...
 
bool RepositionCursorAfterSpillToDisk ()
 Signal to the iterator that the underlying table was closed and replaced with an InnoDB table with the same data, due to a spill-to-disk (e.g. More...
 
- Public Member Functions inherited from TableRowIterator
 TableRowIterator (THD *thd, TABLE *table)
 
void UnlockRow () override
 The default implementation of unlock-row method of RowIterator, used in all access methods except EQRefIterator. More...
 
void SetNullRowFlag (bool is_null_row) override
 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...
 
void StartPSIBatchMode () override
 Start performance schema batch mode, if supported (otherwise ignored). More...
 
void EndPSIBatchModeIfStarted () override
 Ends performance schema batch mode, if started. More...
 
- Public Member Functions inherited from RowIterator
 RowIterator (THD *thd)
 
virtual ~RowIterator ()
 
virtual std::vector< Childchildren () const
 List of zero or more iterators which are direct children of this one. More...
 
virtual std::string TimingString () const
 
JOINjoin_for_explain () const
 
void set_join_for_explain (JOIN *join)
 
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
 

Private Attributes

uchar *const m_record
 
QEP_TAB *const m_qep_tab
 
ha_rows *const m_examined_rows
 
ha_rows m_read_rows
 
ha_rows m_end_of_current_iteration
 
unsigned m_recursive_iteration_count
 
ha_rowsm_stored_rows = nullptr
 

Additional Inherited Members

- Protected Member Functions inherited from TableRowIterator
int HandleError (int error)
 
void PrintError (int error)
 
TABLEtable () const
 
- Protected Member Functions inherited from RowIterator
THDthd () const
 

Detailed Description

FollowTailIterator is a special version of TableScanIterator that is used as part of WITH RECURSIVE queries.

It is designed to read from a temporary table at the same time as MaterializeIterator writes to the same table, picking up new records in the order they come in – it follows the tail, much like the UNIX tool “tail -f”.

Furthermore, when materializing a recursive query expression consisting of multiple query blocks, MaterializeIterator needs to run each block several times until convergence. (For a single query block, one iteration suffices, since the iterator sees new records as they come in.) Each such run, the recursive references should see only rows that were added since the last iteration, even though Init() is called anew. FollowTailIterator is thus different from TableScanIterator in that subsequent calls to Init() do not move the cursor back to the start.

In addition, FollowTailIterator implements the WITH RECURSIVE iteration limit. This is not specified in terms of Init() calls, since one run can encompass many iterations. Instead, it keeps track of the number of records in the table at the start of iteration, and when it has read all of those records, the next iteration is deemed to have begun. If the iteration counter is above the user-set limit, it raises an error to stop runaway queries with infinite recursion.

Constructor & Destructor Documentation

◆ FollowTailIterator()

FollowTailIterator::FollowTailIterator ( THD thd,
TABLE table,
QEP_TAB qep_tab,
ha_rows examined_rows 
)

◆ ~FollowTailIterator()

FollowTailIterator::~FollowTailIterator ( )
override

Member Function Documentation

◆ DebugString()

vector< string > FollowTailIterator::DebugString ( ) const
overridevirtual

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.

Implements RowIterator.

◆ Init()

bool FollowTailIterator::Init ( )
overridevirtual

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.

Implements RowIterator.

◆ Read()

int FollowTailIterator::Read ( )
overridevirtual

Read a single row.

The row data is not actually returned from the function; it is put in the table's (or tables', in case of a join) record buffer, ie., table->records[0].

Return values
0OK
-1End of records
1Error

Implements RowIterator.

◆ RepositionCursorAfterSpillToDisk()

bool FollowTailIterator::RepositionCursorAfterSpillToDisk ( )

Signal to the iterator that the underlying table was closed and replaced with an InnoDB table with the same data, due to a spill-to-disk (e.g.

the table used to be MEMORY and now is InnoDB). This is required so that Read() can continue scanning from the right place. Called by MaterializeIterator::MaterializeRecursive().

◆ set_stored_rows_pointer()

void FollowTailIterator::set_stored_rows_pointer ( ha_rows stored_rows)
inline

Signal where we can expect to find the number of generated rows for this materialization (this points into the MaterializeIterator's data).

This must be called when we start materializing the CTE, before Init() runs.

Member Data Documentation

◆ m_end_of_current_iteration

ha_rows FollowTailIterator::m_end_of_current_iteration
private

◆ m_examined_rows

ha_rows* const FollowTailIterator::m_examined_rows
private

◆ m_qep_tab

QEP_TAB* const FollowTailIterator::m_qep_tab
private

◆ m_read_rows

ha_rows FollowTailIterator::m_read_rows
private

◆ m_record

uchar* const FollowTailIterator::m_record
private

◆ m_recursive_iteration_count

unsigned FollowTailIterator::m_recursive_iteration_count
private

◆ m_stored_rows

ha_rows* FollowTailIterator::m_stored_rows = nullptr
private

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