drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
drizzled::optimizer::QuickIndexMergeSelect Class Reference
Inheritance diagram for drizzled::optimizer::QuickIndexMergeSelect:
[legend]
Collaboration diagram for drizzled::optimizer::QuickIndexMergeSelect:
[legend]

Public Member Functions

 QuickIndexMergeSelect (Session *session, Table *table)
int init ()
int reset (void)
int get_next ()
bool reverse_sorted () const
bool unique_key_range () const
int get_type () const
void add_keys_and_lengths (std::string *key_names, std::string *used_lengths)
void add_info_string (std::string *str)
bool is_keys_used (const boost::dynamic_bitset<> &fields)
void push_quick_back (QuickRangeSelect *quick_sel_range)
int read_keys_and_merge ()
Public Member Functions inherited from drizzled::optimizer::QuickSelectInterface
virtual void range_end ()
virtual int init_ror_merged_scan (bool)
virtual void save_last_pos ()

Public Attributes

std::vector< QuickRangeSelect * > quick_selects
QuickRangeSelect * pk_quick_select
bool doing_pk_scan
memory::Root alloc
Session * session
ReadRecord read_record
Public Attributes inherited from drizzled::optimizer::QuickSelectInterface
bool sorted
ha_rows records
double read_time
Table * head
uint32_t index
uint32_t max_used_key_length
uint32_t used_key_parts
unsigned char * last_rowid
unsigned char * record

Additional Inherited Members

Public Types inherited from drizzled::optimizer::QuickSelectInterface
enum  {
  QS_TYPE_RANGE = 0 , QS_TYPE_INDEX_MERGE = 1 , QS_TYPE_RANGE_DESC = 2 , QS_TYPE_ROR_INTERSECT = 4 ,
  QS_TYPE_ROR_UNION = 5 , QS_TYPE_GROUP_MIN_MAX = 6
}

Detailed Description

access method quick select.

QuickIndexMergeSelect uses QuickRangeSelects to get rows Unique class to remove duplicate rows

INDEX MERGE OPTIMIZER Current implementation doesn't detect all cases where index_merge could be used, in particular: index_merge will never be used if range scan is possible (even if range scan is more expensive)

index_merge+'using index' is not supported (this the consequence of the above restriction)

If WHERE part contains complex nested AND and OR conditions, some ways to retrieve rows using index_merge will not be considered. The choice of read plan may depend on the order of conjuncts/disjuncts in WHERE part of the query, see comments near imerge_list_or_list and SEL_IMERGE::or_sel_tree_with_checks functions for details.

There is no "index_merge_ref" method (but index_merge on non-first table in join is possible with 'range checked for each record').

See comments around SEL_IMERGE class and test_quick_select for more details.

ROW RETRIEVAL ALGORITHM

index_merge uses Unique class for duplicates removal. index_merge takes advantage of Clustered Primary Key (CPK) if the table has one. The index_merge algorithm consists of two phases:

Phase 1 (implemented in QuickIndexMergeSelect::prepare_unique): prepare() { activate 'index only'; while(retrieve next row for non-CPK scan) { if (there is a CPK scan and row will be retrieved by it) skip this row; else put its rowid into Unique; } deactivate 'index only'; }

Phase 2 (implemented as sequence of QuickIndexMergeSelect::get_next calls):

fetch() { retrieve all rows from row pointers stored in Unique; free Unique; retrieve all rows for CPK scan; }

Definition at line 92 of file quick_index_merge_select.h.

Constructor & Destructor Documentation

◆ QuickIndexMergeSelect()

drizzled::optimizer::QuickIndexMergeSelect::QuickIndexMergeSelect ( Session * session,
Table * table )

Definition at line 44 of file quick_index_merge_select.cc.

◆ ~QuickIndexMergeSelect()

drizzled::optimizer::QuickIndexMergeSelect::~QuickIndexMergeSelect ( )

Definition at line 83 of file quick_index_merge_select.cc.

Member Function Documentation

◆ add_info_string()

void drizzled::optimizer::QuickIndexMergeSelect::add_info_string ( std::string * )
virtual

Append text representation of quick select structure (what and how is merged) to str. The result is added to "Extra" field in EXPLAIN output.

Note

This function is implemented only by quick selects that merge other quick selects output and/or can produce output suitable for merging.

Reimplemented from drizzled::optimizer::QuickSelectInterface.

Definition at line 218 of file quick_index_merge_select.cc.

◆ add_keys_and_lengths()

void drizzled::optimizer::QuickIndexMergeSelect::add_keys_and_lengths ( std::string * key_names,
std::string * used_lengths )
virtual

Append comma-separated list of keys this quick select uses to key_names; append comma-separated list of corresponding used lengths to used_lengths.

Note
This is used by during explain plan.

Implements drizzled::optimizer::QuickSelectInterface.

Definition at line 239 of file quick_index_merge_select.cc.

◆ get_next()

int drizzled::optimizer::QuickIndexMergeSelect::get_next ( )
virtual

Get next row for index_merge. NOTES The rows are read from

  1. rowids stored in Unique.
  2. QuickRangeSelect with clustered primary key (if any). The sets of rows retrieved in 1) and 2) are guaranteed to be disjoint.

Implements drizzled::optimizer::QuickSelectInterface.

Definition at line 182 of file quick_index_merge_select.cc.

◆ get_type()

int drizzled::optimizer::QuickIndexMergeSelect::get_type ( ) const
inlinevirtual

Returns the type of this quick select - one of the QS_TYPE_* values

Implements drizzled::optimizer::QuickSelectInterface.

Definition at line 123 of file quick_index_merge_select.h.

◆ init()

int drizzled::optimizer::QuickIndexMergeSelect::init ( )
virtual

Do post-constructor initialization.

Performs initializations that should have been in constructor if it was possible to return errors from constructors. The join optimizer may create and then delete quick selects without retrieving any rows so init() must not contain any IO or CPU intensive code.

If init() call fails the only valid action is to delete this quick select, reset() and get_next() must not be called.

Return values
0OK
otherError code

Implements drizzled::optimizer::QuickSelectInterface.

Definition at line 56 of file quick_index_merge_select.cc.

◆ is_keys_used()

bool drizzled::optimizer::QuickIndexMergeSelect::is_keys_used ( const boost::dynamic_bitset<> & fields)
virtual

Returns true if any index used by this quick select uses field which is marked in passed bitmap.

Reimplemented from drizzled::optimizer::QuickSelectInterface.

Definition at line 207 of file quick_index_merge_select.cc.

◆ push_quick_back()

void drizzled::optimizer::QuickIndexMergeSelect::push_quick_back ( optimizer::QuickRangeSelect * quick_sel_range)

Definition at line 66 of file quick_index_merge_select.cc.

◆ read_keys_and_merge()

int drizzled::optimizer::QuickIndexMergeSelect::read_keys_and_merge ( )

Perform key scans for all used indexes (except CPK), get rowids and merge them into an ordered non-recurrent sequence of rowids.

The merge/duplicate removal is performed using Unique class. We put all rowids into Unique, get the sorted sequence and destroy the Unique.

If table has a clustered primary key that covers all rows (true for bdb and innodb currently) and one of the index_merge scans is a scan on PK, then rows that will be retrieved by PK scan are not put into Unique and primary key scan is not performed here, it is performed later separately.

RETURN

Return values
0OK
othererror

Definition at line 94 of file quick_index_merge_select.cc.

◆ reset()

int drizzled::optimizer::QuickIndexMergeSelect::reset ( void )
virtual

Initializes quick select for row retrieval.

Should be called when it is certain that row retrieval will be necessary. This call may do heavyweight initialization like buffering first N records etc. If reset() call fails get_next() must not be called. Note that reset() may be called several times if

  • the quick select is executed in a subselect
  • a JOIN buffer is used
Return values
0OK
otherError code

Implements drizzled::optimizer::QuickSelectInterface.

Definition at line 61 of file quick_index_merge_select.cc.

◆ reverse_sorted()

bool drizzled::optimizer::QuickIndexMergeSelect::reverse_sorted ( ) const
inlinevirtual

◆ unique_key_range()

bool drizzled::optimizer::QuickIndexMergeSelect::unique_key_range ( ) const
inlinevirtual

Reimplemented from drizzled::optimizer::QuickSelectInterface.

Definition at line 118 of file quick_index_merge_select.h.

Member Data Documentation

◆ alloc

memory::Root drizzled::optimizer::QuickIndexMergeSelect::alloc

Definition at line 143 of file quick_index_merge_select.h.

◆ doing_pk_scan

bool drizzled::optimizer::QuickIndexMergeSelect::doing_pk_scan

Definition at line 141 of file quick_index_merge_select.h.

◆ pk_quick_select

QuickRangeSelect* drizzled::optimizer::QuickIndexMergeSelect::pk_quick_select

Definition at line 138 of file quick_index_merge_select.h.

◆ quick_selects

std::vector<QuickRangeSelect *> drizzled::optimizer::QuickIndexMergeSelect::quick_selects

Definition at line 135 of file quick_index_merge_select.h.

◆ read_record

ReadRecord drizzled::optimizer::QuickIndexMergeSelect::read_record

Definition at line 165 of file quick_index_merge_select.h.

◆ session

Session* drizzled::optimizer::QuickIndexMergeSelect::session

Definition at line 144 of file quick_index_merge_select.h.


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