MySQL  8.0.20
Source Code Documentation
MultiRangeRowIterator Class Referencefinal

The iterator actually doing the reads from the inner table during BKA. More...

#include <bka_iterator.h>

Inheritance diagram for MultiRangeRowIterator:
TableRowIterator RowIterator

Public Member Functions

 MultiRangeRowIterator (THD *thd, Item *cache_idx_cond, TABLE *table, bool keep_current_rowid, TABLE_REF *ref, int mrr_flags)
 
void set_outer_input_tables (JOIN *join, qep_tab_map outer_input_tables)
 Tell the MRR iterator which tables are on the left side of the BKA join (the MRR iterator is always alone on the right side). More...
 
void set_join_type (JoinType join_type)
 Tell the MRR iterator what kind of BKA join it is part of. More...
 
void set_rows (const hash_join_buffer::BufferRow *begin, const hash_join_buffer::BufferRow *end)
 Specify which outer rows to read inner rows for. More...
 
void set_mrr_buffer (uchar *ptr, size_t size)
 Specify an unused chunk of memory MRR can use for the returned inner rows. More...
 
void set_match_flag_buffer (uchar *ptr)
 Specify an unused chunk of memory that we can use to mark which inner rows have been read (by the parent BKA iterator) or not. More...
 
void MarkLastRowAsRead ()
 Mark that the BKA iterator has seen the last row we returned from Read(). More...
 
bool RowHasBeenRead (const hash_join_buffer::BufferRow *row) const
 Check whether the given row has been marked as read (using MarkLastRowAsRead()) or not. More...
 
bool Init () override
 Do the actual multi-range read with the rows given by set_rows() and using the temporary buffer given in set_mrr_buffer(). More...
 
int Read () override
 Read another inner row (if any) and load the appropriate outer row(s) into the associated table buffers. 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...
 
- 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 Member Functions

range_seq_t MrrInitCallback (uint n_ranges, uint flags)
 
uint MrrNextCallback (KEY_MULTI_RANGE *range)
 
bool MrrSkipIndexTuple (char *range_info)
 
bool MrrSkipRecord (char *range_info)
 

Static Private Member Functions

static range_seq_t MrrInitCallbackThunk (void *init_params, uint n_ranges, uint flags)
 
static uint MrrNextCallbackThunk (void *init_params, KEY_MULTI_RANGE *range)
 
static bool MrrSkipIndexTupleCallbackThunk (range_seq_t seq, char *range_info)
 
static bool MrrSkipRecordCallbackThunk (range_seq_t seq, char *range_info, uchar *)
 

Private Attributes

Item *const m_cache_idx_cond
 There are certain conditions that would normally be pushed down to indexes, but that depend on the values of outer tables in the BKA join (ie., they are join conditions), which are not set when we actually read the inner row. More...
 
const bool m_keep_current_rowid
 See constructor. More...
 
TABLE *const m_table
 The table we are reading from. More...
 
handler *const m_file
 Handler for the table we are reading from. More...
 
TABLE_REF *const m_ref
 The index condition. More...
 
const int m_mrr_flags
 Flags passed on to MRR. More...
 
const hash_join_buffer::BufferRowm_begin
 Current outer rows to read inner rows for. Set by set_rows(). More...
 
const hash_join_buffer::BufferRowm_end
 
const hash_join_buffer::BufferRowm_current_pos
 Which row we are at in the [m_begin, m_end) range. More...
 
const hash_join_buffer::BufferRowm_last_row_returned
 What row we last returned from Read() (used for MarkLastRowAsRead()). More...
 
HANDLER_BUFFER m_mrr_buffer
 Temporary space for storing inner rows, used by MRR. More...
 
ucharm_match_flag_buffer = nullptr
 See set_match_flag_buffer(). More...
 
hash_join_buffer::TableCollection m_outer_input_tables
 Tables and columns needed for each outer row. More...
 
JoinType m_join_type = JoinType::INNER
 The join type of the BKA join we are part of. More...
 

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

The iterator actually doing the reads from the inner table during BKA.

See file comment.

Constructor & Destructor Documentation

◆ MultiRangeRowIterator()

MultiRangeRowIterator::MultiRangeRowIterator ( THD thd,
Item cache_idx_cond,
TABLE table,
bool  keep_current_rowid,
TABLE_REF ref,
int  mrr_flags 
)
Parameters
thdThread handle.
cache_idx_condSee m_cache_idx_cond.
tableThe inner table to scan.
keep_current_rowidIf true, get the row ID on the inner table for each row that we return. (Row IDs for outer tables will be controlled by outer_input_tables.)
refThe index condition we are looking up on.
mrr_flagsFlags passed on to MRR.

Member Function Documentation

◆ DebugString()

vector< string > MultiRangeRowIterator::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 MultiRangeRowIterator::Init ( )
overridevirtual

Do the actual multi-range read with the rows given by set_rows() and using the temporary buffer given in set_mrr_buffer().

We don't send a set of rows directly to MRR; instead, we give it a set of function pointers to iterate over the rows, and a pointer to ourselves. The handler will call our callbacks as follows:

  1. MrrInitCallback at the start, to initialize iteration.
  2. MrrNextCallback is called to yield ranges to scan, until it returns 1.
  3. If we have dependent index conditions (see the comment on m_cache_idx_cond), MrrSkipIndexTuple will be called back for each range that returned an inner row, and can choose to discard the row there and then if it doesn't match the dependent index condition.

Implements RowIterator.

◆ MarkLastRowAsRead()

void MultiRangeRowIterator::MarkLastRowAsRead ( )
inline

Mark that the BKA iterator has seen the last row we returned from Read().

(It could have been discarded by a FilterIterator before it reached them.) Will be a no-op for inner joins; see set_match_flag_buffer()..

◆ MrrInitCallback()

range_seq_t MultiRangeRowIterator::MrrInitCallback ( uint  n_ranges,
uint  flags 
)
private

◆ MrrInitCallbackThunk()

static range_seq_t MultiRangeRowIterator::MrrInitCallbackThunk ( void *  init_params,
uint  n_ranges,
uint  flags 
)
inlinestaticprivate

◆ MrrNextCallback()

uint MultiRangeRowIterator::MrrNextCallback ( KEY_MULTI_RANGE range)
private

◆ MrrNextCallbackThunk()

static uint MultiRangeRowIterator::MrrNextCallbackThunk ( void *  init_params,
KEY_MULTI_RANGE range 
)
inlinestaticprivate

◆ MrrSkipIndexTuple()

bool MultiRangeRowIterator::MrrSkipIndexTuple ( char *  range_info)
private

◆ MrrSkipIndexTupleCallbackThunk()

static bool MultiRangeRowIterator::MrrSkipIndexTupleCallbackThunk ( range_seq_t  seq,
char *  range_info 
)
inlinestaticprivate

◆ MrrSkipRecord()

bool MultiRangeRowIterator::MrrSkipRecord ( char *  range_info)
private

◆ MrrSkipRecordCallbackThunk()

static bool MultiRangeRowIterator::MrrSkipRecordCallbackThunk ( range_seq_t  seq,
char *  range_info,
uchar  
)
inlinestaticprivate

◆ Read()

int MultiRangeRowIterator::Read ( )
overridevirtual

Read another inner row (if any) and load the appropriate outer row(s) into the associated table buffers.

Implements RowIterator.

◆ RowHasBeenRead()

bool MultiRangeRowIterator::RowHasBeenRead ( const hash_join_buffer::BufferRow row) const
inline

Check whether the given row has been marked as read (using MarkLastRowAsRead()) or not.

Used internally when doing semijoins, and also by the BKAIterator when synthesizing NULL-complemented rows for outer joins or antijoins.

◆ set_join_type()

void MultiRangeRowIterator::set_join_type ( JoinType  join_type)
inline

Tell the MRR iterator what kind of BKA join it is part of.

Must be called exactly once, before first Init(). Set by BKAIterator's constructor; it's not easily available at the point where we construct MultiRangeRowIterator.

◆ set_match_flag_buffer()

void MultiRangeRowIterator::set_match_flag_buffer ( uchar ptr)
inline

Specify an unused chunk of memory that we can use to mark which inner rows have been read (by the parent BKA iterator) or not.

This is used for outer joins to know which rows need NULL-complemented versions, and for semijoins and antijoins to avoid matching the same inner row more than once.

Must be called before Init() for semijoins, outer joins and antijoins, and never called otherwise. There must be room at least for one bit per row given in set_rows().

◆ set_mrr_buffer()

void MultiRangeRowIterator::set_mrr_buffer ( uchar ptr,
size_t  size 
)
inline

Specify an unused chunk of memory MRR can use for the returned inner rows.

Must be called before Init(), and must be at least big enough to hold one inner row.

◆ set_outer_input_tables()

void MultiRangeRowIterator::set_outer_input_tables ( JOIN join,
qep_tab_map  outer_input_tables 
)

Tell the MRR iterator which tables are on the left side of the BKA join (the MRR iterator is always alone on the right side).

This is needed so that it can unpack the rows into the right tables, with the right format.

Must be called exactly once, before first Init(). Set by BKAIterator's constructor; it's not easily available at the point where we construct MultiRangeRowIterator.

◆ set_rows()

void MultiRangeRowIterator::set_rows ( const hash_join_buffer::BufferRow begin,
const hash_join_buffer::BufferRow end 
)
inline

Specify which outer rows to read inner rows for.

Must be called before Init(), and be valid until the last Read().

Member Data Documentation

◆ m_begin

const hash_join_buffer::BufferRow* MultiRangeRowIterator::m_begin
private

Current outer rows to read inner rows for. Set by set_rows().

◆ m_cache_idx_cond

Item* const MultiRangeRowIterator::m_cache_idx_cond
private

There are certain conditions that would normally be pushed down to indexes, but that depend on the values of outer tables in the BKA join (ie., they are join conditions), which are not set when we actually read the inner row.

[1] Thus, we cannot push them all the way down to the handler; however, MRR gives us a similar mechanism that we can use. Specifically, if we set “skip_index_tuple” to a function pointer, we will be called back for each row, and can load the outer table row(s) we need to evaluate the condition. This allows us to reject the rows based on the index entry alone, without loading the row itself.

It is unclear how much benefit this gives us over simply not pushing these conditions at all. The case of a join condition that is satisfiable using the index tuple but not simply pushable down into the ref is rare; it has to either be on a keypart we couldn't use (e.g., an index on A,B,C where we join A and C but not B – A then becomes part of our ref, but C needs to be an index condition) or a condition that needs to be rechecked, which happens only when mixing PAD SPACE / NO PAD in a join (e.g. looking up in a CHAR column, but wanting the comparison as NO PAD). Especially the latter case would seem unlikely to filter away a significant amount of rows.

[1] In the DebugString output, we call such conditions “dependent index conditions”, since they depend on values from other tables, analogous to dependent subqueries. Internally, they are called cache_idx_cond, presumably because BKA originated in join buffering, also known as join cache.

◆ m_current_pos

const hash_join_buffer::BufferRow* MultiRangeRowIterator::m_current_pos
private

Which row we are at in the [m_begin, m_end) range.

Used during the MRR callbacks.

◆ m_end

const hash_join_buffer::BufferRow* MultiRangeRowIterator::m_end
private

◆ m_file

handler* const MultiRangeRowIterator::m_file
private

Handler for the table we are reading from.

◆ m_join_type

JoinType MultiRangeRowIterator::m_join_type = JoinType::INNER
private

The join type of the BKA join we are part of.

Same as m_join_type in the corresponding BKAIterator.

◆ m_keep_current_rowid

const bool MultiRangeRowIterator::m_keep_current_rowid
private

See constructor.

◆ m_last_row_returned

const hash_join_buffer::BufferRow* MultiRangeRowIterator::m_last_row_returned
private

What row we last returned from Read() (used for MarkLastRowAsRead()).

◆ m_match_flag_buffer

uchar* MultiRangeRowIterator::m_match_flag_buffer = nullptr
private

See set_match_flag_buffer().

◆ m_mrr_buffer

HANDLER_BUFFER MultiRangeRowIterator::m_mrr_buffer
private

Temporary space for storing inner rows, used by MRR.

Set by set_mrr_buffer().

◆ m_mrr_flags

const int MultiRangeRowIterator::m_mrr_flags
private

Flags passed on to MRR.

◆ m_outer_input_tables

hash_join_buffer::TableCollection MultiRangeRowIterator::m_outer_input_tables
private

Tables and columns needed for each outer row.

Same as m_outer_input_tables in the corresponding BKAIterator.

◆ m_ref

TABLE_REF* const MultiRangeRowIterator::m_ref
private

The index condition.

◆ m_table

TABLE* const MultiRangeRowIterator::m_table
private

The table we are reading from.


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