MySQL 8.1.0
Source Code Documentation
index_range_scan.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef SQL_RANGE_OPTIMIZER_INDEX_RANGE_SCAN_H_
24#define SQL_RANGE_OPTIMIZER_INDEX_RANGE_SCAN_H_
25
26#include <sys/types.h>
27#include <memory>
28
29#include "my_bitmap.h"
30#include "my_inttypes.h"
31#include "sql/field.h"
32#include "sql/handler.h"
35
36class KEY_PART_INFO;
37class RANGE_OPT_PARAM;
38class SEL_ARG;
39class SEL_ROOT;
40class String;
41class THD;
42struct KEY_MULTI_RANGE;
43struct MEM_ROOT;
44struct TABLE;
45
46/*
47 MRR range sequence, array<QUICK_RANGE> implementation: sequence traversal
48 context.
49*/
54};
55
56/*
57 Quick select that does a range scan on a single key. The records are
58 returned in key order if ::need_sorted_output() has been called.
59*/
61 protected:
63
64 uint index; /* Index this quick select uses */
65
66 /* Members to deal with case when this quick select is a ROR-merged scan */
68
69 // TODO: pre-allocate space to avoid malloc/free for small number of columns.
71
73 friend range_seq_t quick_range_seq_init(void *init_param, uint n_ranges,
74 uint flags);
75 friend class IndexMergeIterator;
77
78 Bounds_checked_array<QUICK_RANGE *> ranges; /* ordered array of range ptrs */
79 bool free_file; /* TRUE <=> this->file is "owned" by this quick select */
80
81 /* Range pointers to be used when not using MRR interface */
82 QUICK_RANGE **cur_range; /* current element in ranges */
84
85 /* Members needed to use the MRR interface */
87
88 uint mrr_flags; /* Flags to be used with MRR interface */
89 uint mrr_buf_size; /* copy from thd->variables.read_rnd_buff_size */
90 HANDLER_BUFFER *mrr_buf_desc; /* the handler buffer */
91
92 /* Info about index we're scanning */
94
96 const bool reuse_handler;
97
98 private:
100 bool inited = false;
101 const bool m_expected_rows;
103
106 bool row_in_ranges();
107 bool shared_init();
108 bool shared_reset();
110
111 public:
112 IndexRangeScanIterator(THD *thd, TABLE *table, ha_rows *examined_rows,
113 double expected_rows, uint index_arg,
115 MEM_ROOT *return_mem_root, uint mrr_flags,
116 uint mrr_buf_size,
118 ~IndexRangeScanIterator() override;
119
121
122 /* Default move ctor used by ReverseIndexRangeScanIterator */
124
125 bool Init() override;
126 int Read() override;
127 void UnlockRow() override {
128 // Override TableRowIterator::UnlockRow(), since we may use
129 // a different handler from m_table->file.
130 file->unlock_row();
131 }
132
133 uint get_mrr_flags() const { return mrr_flags; }
134 uchar *last_rowid() const override {
136 return file->ref;
137 }
138};
139
140bool InitIndexRangeScan(TABLE *table, handler *file, int index,
141 unsigned mrr_flags, bool in_ror_merged_scan,
142 MY_BITMAP *column_bitmap);
143
144range_seq_t quick_range_seq_init(void *init_param, uint, uint);
146
147#endif // SQL_RANGE_OPTIMIZER_INDEX_RANGE_SCAN_H_
A wrapper class which provides array bounds checking.
Definition: sql_array.h:46
Definition: index_merge.h:98
Definition: index_range_scan.h:60
friend uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range)
Definition: index_range_scan.cc:159
KEY_PART_INFO * key_part_info
Definition: index_range_scan.h:93
bool free_file
Definition: index_range_scan.h:79
uint index
Definition: index_range_scan.h:64
uint mrr_buf_size
Definition: index_range_scan.h:89
IndexRangeScanIterator(THD *thd, TABLE *table, ha_rows *examined_rows, double expected_rows, uint index_arg, bool need_rows_in_rowid_order, bool reuse_handler, MEM_ROOT *return_mem_root, uint mrr_flags, uint mrr_buf_size, Bounds_checked_array< QUICK_RANGE * > ranges)
Definition: index_range_scan.cc:55
MEM_ROOT * mem_root
Definition: index_range_scan.h:99
const bool m_expected_rows
Definition: index_range_scan.h:101
uchar * last_rowid() const override
Definition: index_range_scan.h:134
QUICK_RANGE_SEQ_CTX qr_traversal_ctx
Definition: index_range_scan.h:86
uint mrr_flags
Definition: index_range_scan.h:88
HANDLER_BUFFER * mrr_buf_desc
Definition: index_range_scan.h:90
bool Init() override
Initialize or reinitialize the iterator.
Definition: index_range_scan.cc:203
IndexRangeScanIterator(IndexRangeScanIterator &&)=default
bool shared_reset()
Definition: index_range_scan.cc:302
bool shared_init()
Definition: index_range_scan.cc:82
void UnlockRow() override
The default implementation of unlock-row method of RowIterator, used in all access methods except EQR...
Definition: index_range_scan.h:127
IndexRangeScanIterator(const IndexRangeScanIterator &)=delete
QUICK_RANGE * last_range
Definition: index_range_scan.h:83
uint get_mrr_flags() const
Definition: index_range_scan.h:133
Bounds_checked_array< QUICK_RANGE * > ranges
Definition: index_range_scan.h:78
int Read() override
Read a single row.
Definition: index_range_scan.cc:351
bool inited
Definition: index_range_scan.h:100
ha_rows * m_examined_rows
Definition: index_range_scan.h:102
bool row_in_ranges()
Definition: index_range_scan.cc:401
QUICK_RANGE ** cur_range
Definition: index_range_scan.h:82
const bool need_rows_in_rowid_order
Definition: index_range_scan.h:95
handler * file
Definition: index_range_scan.h:62
bool in_ror_merged_scan
Definition: index_range_scan.h:67
friend range_seq_t quick_range_seq_init(void *init_param, uint n_ranges, uint flags)
Definition: index_range_scan.cc:129
~IndexRangeScanIterator() override
Definition: index_range_scan.cc:99
bool init_ror_merged_scan()
Definition: rowid_ordered_retrieval.cc:78
int cmp_next(QUICK_RANGE *range)
Definition: index_range_scan.cc:428
MY_BITMAP column_bitmap
Definition: index_range_scan.h:70
int cmp_prev(QUICK_RANGE *range)
Definition: index_range_scan.cc:441
const bool reuse_handler
Definition: index_range_scan.h:96
Definition: key.h:56
super::const_iterator const_iterator
Definition: mem_root_array.h:432
Definition: range_optimizer.h:68
Definition: range_opt_param.h:28
An interface for RowIterators that have a given row ID, ie., they can be children in ROR (rowid-order...
Definition: rowid_capable_row_iterator.h:35
Definition: rowid_ordered_retrieval.h:62
THD * thd() const
Definition: row_iterator.h:227
Definition: tree.h:464
A graph of (possible multiple) key ranges, represented as a red-black binary tree.
Definition: tree.h:67
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:166
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
TABLE * table() const
Definition: row_iterator.h:245
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4460
static int flags[50]
Definition: hp_test1.cc:39
uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range)
Definition: index_range_scan.cc:159
range_seq_t quick_range_seq_init(void *init_param, uint, uint)
Definition: index_range_scan.cc:129
bool InitIndexRangeScan(TABLE *table, handler *file, int index, unsigned mrr_flags, bool in_ror_merged_scan, MY_BITMAP *column_bitmap)
Definition: index_range_scan.cc:250
my_off_t ha_rows
Definition: my_base.h:1139
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:51
static PFS_engine_table_share_proxy table
Definition: pfs.cc:60
Definition: os0file.h:85
void * range_seq_t
Definition: handler.h:3697
Definition: handler.h:3691
Definition: my_base.h:1130
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: my_bitmap.h:42
Definition: index_range_scan.h:50
Quick_ranges::const_iterator cur
Definition: index_range_scan.h:52
Quick_ranges::const_iterator last
Definition: index_range_scan.h:53
Quick_ranges::const_iterator first
Definition: index_range_scan.h:51
Definition: table.h:1394
Definition: gen_lex_token.cc:148