MySQL 9.0.0
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:
[legend]

Public Member Functions

 FollowTailIterator (THD *thd, TABLE *table, double expected_rows, ha_rows *examined_rows)
 
 ~FollowTailIterator () override
 
bool Init () override
 Initialize or reinitialize the iterator. More...
 
int Read () override
 Read a single row. 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 ()=default
 
 RowIterator (const RowIterator &)=delete
 
 RowIterator (RowIterator &&)=default
 
virtual const IteratorProfilerGetProfiler () const
 Get profiling data for this iterator (for 'EXPLAIN ANALYZE'). More...
 
virtual void SetOverrideProfiler ([[maybe_unused]] const IteratorProfiler *profiler)
 
virtual RowIteratorreal_iterator ()
 If this iterator is wrapping a different iterator (e.g. More...
 
virtual const RowIteratorreal_iterator () const
 

Private Attributes

bool m_inited = false
 
uchar *const m_record
 
const double m_expected_rows
 
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,
double  expected_rows,
ha_rows examined_rows 
)

◆ ~FollowTailIterator()

FollowTailIterator::~FollowTailIterator ( )
override

Member Function Documentation

◆ 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 Index_lookup) 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_expected_rows

const double FollowTailIterator::m_expected_rows
private

◆ m_inited

bool FollowTailIterator::m_inited = false
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: