MySQL 9.0.0
Source Code Documentation
NestedLoopSemiJoinWithDuplicateRemovalIterator Class Referencefinal

An iterator that is semantically equivalent to a semijoin NestedLoopIterator immediately followed by a RemoveDuplicatesOnIndexIterator. More...

#include <composite_iterators.h>

Inheritance diagram for NestedLoopSemiJoinWithDuplicateRemovalIterator:
[legend]

Public Member Functions

 NestedLoopSemiJoinWithDuplicateRemovalIterator (THD *thd, unique_ptr_destroy_only< RowIterator > source_outer, unique_ptr_destroy_only< RowIterator > source_inner, const TABLE *table, KEY *key, size_t key_len)
 
bool Init () override
 Initialize or reinitialize the iterator. More...
 
int Read () override
 Read a single row. 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 EndPSIBatchModeIfStarted () override
 Ends performance schema batch mode, if started. More...
 
void UnlockRow () override
 
- 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 void StartPSIBatchMode ()
 Start performance schema batch mode, if supported (otherwise ignored). More...
 
virtual RowIteratorreal_iterator ()
 If this iterator is wrapping a different iterator (e.g. More...
 
virtual const RowIteratorreal_iterator () const
 

Private Attributes

unique_ptr_destroy_only< RowIterator > const m_source_outer
 
unique_ptr_destroy_only< RowIterator > const m_source_inner
 
const TABLEm_table_outer
 
KEYm_key
 
ucharm_key_buf
 
const size_t m_key_len
 
bool m_deduplicate_against_previous_row
 

Additional Inherited Members

- Protected Member Functions inherited from RowIterator
THDthd () const
 

Detailed Description

An iterator that is semantically equivalent to a semijoin NestedLoopIterator immediately followed by a RemoveDuplicatesOnIndexIterator.

It is used to implement the “loose scan” strategy in queries with multiple tables on the inside of a semijoin, like

... FROM t1 WHERE ... IN ( SELECT ... FROM t2 JOIN t3 ... )

In this case, the query tree without this iterator would ostensibly look like

-> Nested loop join -> Table scan on t1 -> Remove duplicates on t2_idx -> Nested loop semijoin -> Index scan on t2 using t2_idx -> Filter (e.g. t3.a = t2.a) -> Table scan on t3

(t3 will be marked as “first match” on t2 when implementing loose scan, thus the semijoin.)

First note that we can't put the duplicate removal directly on t2 in this case, as the first t2 row doesn't necessarily match anything in t3, so it needs to be above. However, this is wasteful, because once we find a matching t2/t3 pair, we should stop scanning t3 until we have a new t2.

NestedLoopSemiJoinWithDuplicateRemovalIterator solves the problem by doing exactly this; it gets a row from the outer side, gets exactly one row from the inner side, and then skips over rows from the outer side (without scanning the inner side) until its keypart changes.

Constructor & Destructor Documentation

◆ NestedLoopSemiJoinWithDuplicateRemovalIterator()

NestedLoopSemiJoinWithDuplicateRemovalIterator::NestedLoopSemiJoinWithDuplicateRemovalIterator ( THD thd,
unique_ptr_destroy_only< RowIterator source_outer,
unique_ptr_destroy_only< RowIterator source_inner,
const TABLE table,
KEY key,
size_t  key_len 
)

Member Function Documentation

◆ EndPSIBatchModeIfStarted()

void NestedLoopSemiJoinWithDuplicateRemovalIterator::EndPSIBatchModeIfStarted ( )
inlineoverridevirtual

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 from RowIterator.

◆ Init()

bool NestedLoopSemiJoinWithDuplicateRemovalIterator::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 NestedLoopSemiJoinWithDuplicateRemovalIterator::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.

◆ SetNullRowFlag()

void NestedLoopSemiJoinWithDuplicateRemovalIterator::SetNullRowFlag ( bool  is_null_row)
inlineoverridevirtual

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.

Implements RowIterator.

◆ UnlockRow()

void NestedLoopSemiJoinWithDuplicateRemovalIterator::UnlockRow ( )
inlineoverridevirtual

Implements RowIterator.

Member Data Documentation

◆ m_deduplicate_against_previous_row

bool NestedLoopSemiJoinWithDuplicateRemovalIterator::m_deduplicate_against_previous_row
private

◆ m_key

KEY* NestedLoopSemiJoinWithDuplicateRemovalIterator::m_key
private

◆ m_key_buf

uchar* NestedLoopSemiJoinWithDuplicateRemovalIterator::m_key_buf
private

◆ m_key_len

const size_t NestedLoopSemiJoinWithDuplicateRemovalIterator::m_key_len
private

◆ m_source_inner

unique_ptr_destroy_only<RowIterator> const NestedLoopSemiJoinWithDuplicateRemovalIterator::m_source_inner
private

◆ m_source_outer

unique_ptr_destroy_only<RowIterator> const NestedLoopSemiJoinWithDuplicateRemovalIterator::m_source_outer
private

◆ m_table_outer

const TABLE* NestedLoopSemiJoinWithDuplicateRemovalIterator::m_table_outer
private

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