286
258
struct st_qsel_param;
260
class QuickRangeSelect;
289
* MRR range sequence, array<QUICK_RANGE> implementation: sequence traversal
263
* MRR range sequence, array<QuickRange> implementation: sequence traversal
292
266
typedef struct st_quick_range_seq_ctx
297
} QUICK_RANGE_SEQ_CTX;
271
} QuickRangeSequenceContext;
299
273
range_seq_t quick_range_seq_init(void *init_param, uint32_t n_ranges, uint32_t flags);
300
275
uint32_t quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range);
303
* Quick select that does a range scan on a single key.
305
* The records are returned in key order.
308
class QUICK_RANGE_SELECT : public QUICK_SELECT_I
312
DYNAMIC_ARRAY ranges; /**< ordered array of range ptrs */
314
/** Members to deal with case when this quick select is a ROR-merged scan */
315
bool in_ror_merged_scan;
316
MyBitmap column_bitmap;
317
MyBitmap *save_read_set;
318
MyBitmap *save_write_set;
319
bool free_file; /**< True when this->file is "owned" by this quick select */
321
/* Range pointers to be used when not using MRR interface */
322
QUICK_RANGE **cur_range; /**< current element in ranges */
323
QUICK_RANGE *last_range;
325
/** Members needed to use the MRR interface */
326
QUICK_RANGE_SEQ_CTX qr_traversal_ctx;
327
uint32_t mrr_buf_size; /**< copy from session->variables.read_rnd_buff_size */
328
HANDLER_BUFFER *mrr_buf_desc; /**< the Cursor buffer */
330
/** Info about index we're scanning */
332
KEY_PART_INFO *key_part_info;
334
bool dont_free; /**< Used by QUICK_SELECT_DESC */
336
int cmp_next(QUICK_RANGE *range);
337
int cmp_prev(QUICK_RANGE *range);
338
bool row_in_ranges();
340
uint32_t mrr_flags; /**< Flags to be used with MRR interface */
343
QUICK_RANGE_SELECT(Session *session,
347
MEM_ROOT *parent_alloc,
349
~QUICK_RANGE_SELECT();
355
int get_next_prefix(uint32_t prefix_length,
356
key_part_map keypart_map,
357
unsigned char *cur_prefix);
358
bool reverse_sorted()
362
bool unique_key_range();
363
int init_ror_merged_scan(bool reuse_handler);
364
void save_last_pos();
367
return QS_TYPE_RANGE;
369
void add_keys_and_lengths(String *key_names, String *used_lengths);
370
void add_info_string(String *str);
376
/* Used only by QUICK_SELECT_DESC */
377
QUICK_RANGE_SELECT(const QUICK_RANGE_SELECT& org) : QUICK_SELECT_I()
379
memmove(this, &org, sizeof(*this));
381
Use default MRR implementation for reverse scans. No table engine
382
currently can do an MRR scan with output in reverse index order.
385
mrr_flags|= HA_MRR_USE_DEFAULT_IMPL;
388
friend class ::TRP_ROR_INTERSECT;
390
QUICK_RANGE_SELECT *get_quick_select_for_ref(Session *session, Table *table,
391
struct table_reference_st *ref,
393
friend bool get_quick_keys(PARAM *param, QUICK_RANGE_SELECT *quick,
394
KEY_PART *key, SEL_ARG *key_tree,
395
unsigned char *min_key, uint32_t min_key_flag,
396
unsigned char *max_key, uint32_t max_key_flag);
397
friend QUICK_RANGE_SELECT *get_quick_select(PARAM*,uint32_t idx,
400
uint32_t mrr_buf_size,
402
friend class QUICK_SELECT_DESC;
403
friend class QUICK_INDEX_MERGE_SELECT;
404
friend class QUICK_ROR_INTERSECT_SELECT;
405
friend class QUICK_GROUP_MIN_MAX_SELECT;
406
friend uint32_t quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range);
407
friend range_seq_t quick_range_seq_init(void *init_param,
408
uint32_t n_ranges, uint32_t flags);
409
friend void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
410
bool distinct,const char *message);
414
QUICK_INDEX_MERGE_SELECT - index_merge access method quick select.
416
QUICK_INDEX_MERGE_SELECT uses
417
* QUICK_RANGE_SELECTs to get rows
418
* Unique class to remove duplicate rows
420
INDEX MERGE OPTIMIZER
421
Current implementation doesn't detect all cases where index_merge could
422
be used, in particular:
423
* index_merge will never be used if range scan is possible (even if
424
range scan is more expensive)
426
* index_merge+'using index' is not supported (this the consequence of
427
the above restriction)
429
* If WHERE part contains complex nested AND and OR conditions, some ways
430
to retrieve rows using index_merge will not be considered. The choice
431
of read plan may depend on the order of conjuncts/disjuncts in WHERE
432
part of the query, see comments near imerge_list_or_list and
433
SEL_IMERGE::or_sel_tree_with_checks functions for details.
435
* There is no "index_merge_ref" method (but index_merge on non-first
436
table in join is possible with 'range checked for each record').
438
See comments around SEL_IMERGE class and test_quick_select for more
441
ROW RETRIEVAL ALGORITHM
443
index_merge uses Unique class for duplicates removal. index_merge takes
444
advantage of Clustered Primary Key (CPK) if the table has one.
445
The index_merge algorithm consists of two phases:
447
Phase 1 (implemented in QUICK_INDEX_MERGE_SELECT::prepare_unique):
450
activate 'index only';
451
while(retrieve next row for non-CPK scan)
453
if (there is a CPK scan and row will be retrieved by it)
456
put its rowid into Unique;
458
deactivate 'index only';
461
Phase 2 (implemented as sequence of QUICK_INDEX_MERGE_SELECT::get_next
466
retrieve all rows from row pointers stored in Unique;
468
retrieve all rows for CPK scan;
471
class QUICK_INDEX_MERGE_SELECT : public QUICK_SELECT_I
474
QUICK_INDEX_MERGE_SELECT(Session *session, Table *table);
475
~QUICK_INDEX_MERGE_SELECT();
480
bool reverse_sorted()
484
bool unique_key_range()
490
return QS_TYPE_INDEX_MERGE;
492
void add_keys_and_lengths(String *key_names, String *used_lengths);
493
void add_info_string(String *str);
494
bool is_keys_used(const MyBitmap *fields);
496
bool push_quick_back(QUICK_RANGE_SELECT *quick_sel_range);
498
/* range quick selects this index_merge read consists of */
499
List<QUICK_RANGE_SELECT> quick_selects;
501
/* quick select that uses clustered primary key (NULL if none) */
502
QUICK_RANGE_SELECT* pk_quick_select;
504
/* true if this select is currently doing a clustered PK scan */
509
int read_keys_and_merge();
511
/* used to get rows collected in Unique */
512
READ_RECORD read_record;
517
279
Rowid-Ordered Retrieval (ROR) index intersection quick select.
518
280
This quick select produces intersection of row sequences returned
519
by several QUICK_RANGE_SELECTs it "merges".
281
by several QuickRangeSelects it "merges".
521
All merged QUICK_RANGE_SELECTs must return rowids in rowid order.
283
All merged QuickRangeSelects must return rowids in rowid order.
522
284
QUICK_ROR_INTERSECT_SELECT will return rows in rowid order, too.
524
286
All merged quick selects retrieve {rowid, covered_fields} tuples (not full