Drizzled Public API Documentation

drizzled::optimizer::QuickIndexMergeSelect Class Reference

Inheritance diagram for drizzled::optimizer::QuickIndexMergeSelect:
drizzled::optimizer::QuickSelectInterface

List of all members.

Public Types

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
}

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)
bool push_quick_back (QuickRangeSelect *quick_sel_range)
int read_keys_and_merge ()
virtual void range_end ()
virtual int init_ror_merged_scan (bool)
virtual void save_last_pos ()

Public Attributes

std::vector< QuickRangeSelect * > quick_selects
QuickRangeSelectpk_quick_select
bool doing_pk_scan
memory::Root alloc
Sessionsession
ReadRecord read_record
bool sorted
ha_rows records
double read_time
Tablehead
uint32_t index
uint32_t max_used_key_length
uint32_t used_key_parts
unsigned char * last_rowid
unsigned char * record

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.


Member Function Documentation

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.

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.

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 192 of file quick_index_merge_select.cc.

int drizzled::optimizer::QuickIndexMergeSelect::get_type ( ) const [inline, virtual]

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.

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 57 of file quick_index_merge_select.cc.

virtual int drizzled::optimizer::QuickSelectInterface::init_ror_merged_scan ( bool  ) [inline, virtual, inherited]

Initialize this quick select as a merged scan inside a ROR-union or a ROR- intersection scan. The caller must not additionally call init() if this function is called.

Parameters:
Iftrue, the quick select may use table->Cursor, otherwise it must create and use a separate Cursor object.
Return values:
0Ok
otherError

Reimplemented in drizzled::optimizer::QuickRangeSelect, and drizzled::optimizer::QuickRorIntersectSelect.

Definition at line 226 of file range.h.

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 217 of file quick_index_merge_select.cc.

virtual void drizzled::optimizer::QuickSelectInterface::range_end ( ) [inline, virtual, inherited]

Range end should be called when we have looped over the whole index

Reimplemented in drizzled::optimizer::QuickRangeSelect.

Definition at line 190 of file range.h.

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 104 of file quick_index_merge_select.cc.

References drizzled::optimizer::QuickRangeSelect::get_next(), drizzled::optimizer::QuickRangeSelect::init(), drizzled::optimizer::QuickRangeSelect::range_end(), drizzled::optimizer::QuickSelectInterface::record, drizzled::Cursor::ref_length, drizzled::optimizer::QuickRangeSelect::reset(), and drizzled::Session::variables.

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 62 of file quick_index_merge_select.cc.

virtual void drizzled::optimizer::QuickSelectInterface::save_last_pos ( ) [inline, virtual, inherited]

Save ROWID of last retrieved row in file->ref. This used in ROR-merging.

Reimplemented in drizzled::optimizer::QuickRangeSelect.

Definition at line 235 of file range.h.

Referenced by drizzled::optimizer::QuickRorUnionSelect::get_next().


Member Data Documentation

Index this quick select uses, or MAX_KEY for quick selects that use several indexes

Definition at line 120 of file range.h.

Referenced by drizzled::best_access_path(), and drizzled::optimizer::Scan::getStats().

The rowid of last row retrieved by this quick select. This is used only when doing ROR-index_merge selects

Definition at line 138 of file range.h.

Referenced by drizzled::optimizer::QuickRorUnionSelect::get_next().

Total length of first used_key_parts parts of the key. Applicable if index!= MAX_KEY.

Definition at line 125 of file range.h.

time to perform this retrieval

Definition at line 114 of file range.h.

Referenced by drizzled::best_access_path(), and drizzled::make_join_statistics().

estimate of # of records to be retrieved

Definition at line 113 of file range.h.

Maximum number of (first) key parts this quick select uses for retrieval. eg. for "(key1p1=c1 AND key1p2=c2) OR key1p1=c2" used_key_parts == 2. Applicable if index!= MAX_KEY.

For QUICK_GROUP_MIN_MAX_SELECT it includes MIN/MAX argument keyparts.

Definition at line 133 of file range.h.


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