MySQL 9.1.0
Source Code Documentation
index_range_scan.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_RANGE_OPTIMIZER_INDEX_RANGE_SCAN_H_
25#define SQL_RANGE_OPTIMIZER_INDEX_RANGE_SCAN_H_
26
27#include <sys/types.h>
28#include <memory>
29
30#include "my_bitmap.h"
31#include "my_inttypes.h"
32#include "sql/field.h"
33#include "sql/handler.h"
36
37class KEY_PART_INFO;
38class RANGE_OPT_PARAM;
39class SEL_ARG;
40class SEL_ROOT;
41class String;
42class THD;
43struct KEY_MULTI_RANGE;
44struct MEM_ROOT;
45struct TABLE;
46
47/*
48 MRR range sequence, array<QUICK_RANGE> implementation: sequence traversal
49 context.
50*/
55};
56
57/*
58 Quick select that does a range scan on a single key. The records are
59 returned in key order if ::need_sorted_output() has been called.
60*/
62 protected:
64
65 uint index; /* Index this quick select uses */
66
67 /* Members to deal with case when this quick select is a ROR-merged scan */
69
70 // TODO: pre-allocate space to avoid malloc/free for small number of columns.
72
74 friend range_seq_t quick_range_seq_init(void *init_param, uint n_ranges,
75 uint flags);
76 friend class IndexMergeIterator;
78
79 Bounds_checked_array<QUICK_RANGE *> ranges; /* ordered array of range ptrs */
80 bool free_file; /* TRUE <=> this->file is "owned" by this quick select */
81
82 /* Range pointers to be used when not using MRR interface */
83 QUICK_RANGE **cur_range; /* current element in ranges */
85
86 /* Members needed to use the MRR interface */
88
89 uint mrr_flags; /* Flags to be used with MRR interface */
90 uint mrr_buf_size; /* copy from thd->variables.read_rnd_buff_size */
91 HANDLER_BUFFER *mrr_buf_desc; /* the handler buffer */
92
93 /* Info about index we're scanning */
95
97 const bool reuse_handler;
98
99 private:
101 bool inited = false;
102 const double m_expected_rows;
104
107 bool row_in_ranges();
108 bool shared_init();
109 bool shared_reset();
111
112 public:
113 IndexRangeScanIterator(THD *thd, TABLE *table, ha_rows *examined_rows,
114 double expected_rows, uint index_arg,
116 MEM_ROOT *return_mem_root, uint mrr_flags,
117 uint mrr_buf_size,
119 ~IndexRangeScanIterator() override;
120
122
123 /* Default move ctor used by ReverseIndexRangeScanIterator */
125
126 bool Init() override;
127 int Read() override;
128 void UnlockRow() override {
129 // Override TableRowIterator::UnlockRow(), since we may use
130 // a different handler from m_table->file.
131 file->unlock_row();
132 }
133
134 uint get_mrr_flags() const { return mrr_flags; }
135 uchar *last_rowid() const override {
137 return file->ref;
138 }
139};
140
141bool InitIndexRangeScan(TABLE *table, handler *file, int index,
142 unsigned mrr_flags, bool in_ror_merged_scan,
143 MY_BITMAP *column_bitmap);
144
145range_seq_t quick_range_seq_init(void *init_param, uint, uint);
147
148#endif // SQL_RANGE_OPTIMIZER_INDEX_RANGE_SCAN_H_
A wrapper class which provides array bounds checking.
Definition: sql_array.h:47
Definition: index_merge.h:99
Definition: index_range_scan.h:61
friend uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range)
Definition: index_range_scan.cc:161
KEY_PART_INFO * key_part_info
Definition: index_range_scan.h:94
bool free_file
Definition: index_range_scan.h:80
uint index
Definition: index_range_scan.h:65
const double m_expected_rows
Definition: index_range_scan.h:102
uint mrr_buf_size
Definition: index_range_scan.h:90
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:57
MEM_ROOT * mem_root
Definition: index_range_scan.h:100
uchar * last_rowid() const override
Definition: index_range_scan.h:135
QUICK_RANGE_SEQ_CTX qr_traversal_ctx
Definition: index_range_scan.h:87
uint mrr_flags
Definition: index_range_scan.h:89
HANDLER_BUFFER * mrr_buf_desc
Definition: index_range_scan.h:91
bool Init() override
Initialize or reinitialize the iterator.
Definition: index_range_scan.cc:204
IndexRangeScanIterator(IndexRangeScanIterator &&)=default
bool shared_reset()
Definition: index_range_scan.cc:311
bool shared_init()
Definition: index_range_scan.cc:84
void UnlockRow() override
The default implementation of unlock-row method of RowIterator, used in all access methods except EQR...
Definition: index_range_scan.h:128
IndexRangeScanIterator(const IndexRangeScanIterator &)=delete
QUICK_RANGE * last_range
Definition: index_range_scan.h:84
uint get_mrr_flags() const
Definition: index_range_scan.h:134
Bounds_checked_array< QUICK_RANGE * > ranges
Definition: index_range_scan.h:79
int Read() override
Read a single row.
Definition: index_range_scan.cc:360
bool inited
Definition: index_range_scan.h:101
ha_rows * m_examined_rows
Definition: index_range_scan.h:103
bool row_in_ranges()
Definition: index_range_scan.cc:410
QUICK_RANGE ** cur_range
Definition: index_range_scan.h:83
const bool need_rows_in_rowid_order
Definition: index_range_scan.h:96
handler * file
Definition: index_range_scan.h:63
bool in_ror_merged_scan
Definition: index_range_scan.h:68
friend range_seq_t quick_range_seq_init(void *init_param, uint n_ranges, uint flags)
Definition: index_range_scan.cc:131
~IndexRangeScanIterator() override
Definition: index_range_scan.cc:101
bool init_ror_merged_scan()
Definition: rowid_ordered_retrieval.cc:80
int cmp_next(QUICK_RANGE *range)
Definition: index_range_scan.cc:437
MY_BITMAP column_bitmap
Definition: index_range_scan.h:71
int cmp_prev(QUICK_RANGE *range)
Definition: index_range_scan.cc:450
const bool reuse_handler
Definition: index_range_scan.h:97
Definition: key.h:57
super::const_iterator const_iterator
Definition: mem_root_array.h:433
Definition: range_optimizer.h:69
Definition: range_opt_param.h:29
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:36
Definition: rowid_ordered_retrieval.h:63
THD * thd() const
Definition: row_iterator.h:228
Definition: tree.h:465
A graph of (possible multiple) key ranges, represented as a red-black binary tree.
Definition: tree.h:68
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
TABLE * table() const
Definition: row_iterator.h:246
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4583
static int flags[50]
Definition: hp_test1.cc:40
uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range)
Definition: index_range_scan.cc:161
range_seq_t quick_range_seq_init(void *init_param, uint, uint)
Definition: index_range_scan.cc:131
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:259
my_off_t ha_rows
Definition: my_base.h:1141
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:52
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
Definition: os0file.h:89
void * range_seq_t
Definition: handler.h:3822
Definition: handler.h:3816
Definition: my_base.h:1132
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: my_bitmap.h:43
Definition: index_range_scan.h:51
Quick_ranges::const_iterator cur
Definition: index_range_scan.h:53
Quick_ranges::const_iterator last
Definition: index_range_scan.h:54
Quick_ranges::const_iterator first
Definition: index_range_scan.h:52
Definition: table.h:1421
Definition: gen_lex_token.cc:149