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) |
void | 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 |
QuickRangeSelect * | pk_quick_select |
bool | doing_pk_scan |
memory::Root | alloc |
Session * | session |
ReadRecord | read_record |
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 |
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.
|
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.
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.
References drizzled::optimizer::QuickRangeSelect::add_info_string().
|
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.
Implements drizzled::optimizer::QuickSelectInterface.
Definition at line 239 of file quick_index_merge_select.cc.
References drizzled::optimizer::QuickSelectInterface::index, and drizzled::optimizer::QuickSelectInterface::max_used_key_length.
|
virtual |
Get next row for index_merge. NOTES The rows are read from
Implements drizzled::optimizer::QuickSelectInterface.
Definition at line 182 of file quick_index_merge_select.cc.
|
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.
|
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.
0 | OK |
other | Error code |
Implements drizzled::optimizer::QuickSelectInterface.
Definition at line 56 of file quick_index_merge_select.cc.
|
inlinevirtualinherited |
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.
If | true, the quick select may use table->Cursor, otherwise it must create and use a separate Cursor object. |
0 | Ok |
other | Error |
Reimplemented in drizzled::optimizer::QuickRangeSelect, and drizzled::optimizer::QuickRorIntersectSelect.
Definition at line 212 of file range.h.
Referenced by drizzled::optimizer::QuickRorUnionSelect::reset().
|
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.
References drizzled::optimizer::QuickSelectInterface::index.
|
inlinevirtualinherited |
Range end should be called when we have looped over the whole index
Reimplemented in drizzled::optimizer::QuickRangeSelect.
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
0 | OK |
other | error |
Definition at line 94 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.
|
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
0 | OK |
other | Error code |
Implements drizzled::optimizer::QuickSelectInterface.
Definition at line 61 of file quick_index_merge_select.cc.
|
inlinevirtualinherited |
Save ROWID of last retrieved row in file->ref. This used in ROR-merging.
Reimplemented in drizzled::optimizer::QuickRangeSelect.
Definition at line 221 of file range.h.
Referenced by drizzled::optimizer::QuickRorUnionSelect::get_next(), and drizzled::optimizer::QuickRorUnionSelect::reset().
|
inherited |
Index this quick select uses, or MAX_KEY for quick selects that use several indexes
Definition at line 106 of file range.h.
Referenced by drizzled::optimizer::QuickRorIntersectSelect::add_info_string(), drizzled::optimizer::QuickRorIntersectSelect::add_keys_and_lengths(), add_keys_and_lengths(), drizzled::best_access_path(), drizzled::optimizer::Scan::getStats(), drizzled::optimizer::QuickRorIntersectSelect::is_keys_used(), is_keys_used(), drizzled::optimizer::QuickGroupMinMaxSelect::reset(), drizzled::test_if_skip_sort_order(), and drizzled::update_query().
|
inherited |
The rowid of last row retrieved by this quick select. This is used only when doing ROR-index_merge selects
Definition at line 124 of file range.h.
Referenced by drizzled::optimizer::QuickRorUnionSelect::get_next().
|
inherited |
Total length of first used_key_parts parts of the key. Applicable if index!= MAX_KEY.
Definition at line 111 of file range.h.
Referenced by drizzled::optimizer::QuickRorIntersectSelect::add_keys_and_lengths(), add_keys_and_lengths(), drizzled::optimizer::QuickGroupMinMaxSelect::add_keys_and_lengths(), drizzled::optimizer::QuickGroupMinMaxSelect::adjust_prefix_ranges(), and drizzled::optimizer::QuickGroupMinMaxSelect::update_key_stat().
|
inherited |
time to perform this retrieval
Definition at line 100 of file range.h.
Referenced by drizzled::best_access_path(), and drizzled::make_join_statistics().
|
inherited |
Table record buffer used by this quick select.
Reimplemented in drizzled::optimizer::QuickGroupMinMaxSelect.
Definition at line 129 of file range.h.
Referenced by drizzled::optimizer::QuickRorUnionSelect::get_next(), drizzled::optimizer::QuickRorIntersectSelect::get_next(), and read_keys_and_merge().
|
inherited |
estimate of # of records to be retrieved
Definition at line 99 of file range.h.
Referenced by drizzled::FileSort::run().
|
inherited |
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.
Reimplemented in drizzled::optimizer::QuickSelectDescending.
Definition at line 119 of file range.h.
Referenced by drizzled::test_if_skip_sort_order(), and drizzled::optimizer::QuickGroupMinMaxSelect::update_key_stat().