MySQL 8.3.0
Source Code Documentation
reverse_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_REVERSE_INDEX_RANGE_SCAN_H_
24#define SQL_RANGE_OPTIMIZER_REVERSE_INDEX_RANGE_SCAN_H_
25
26#include <sys/types.h>
27
30#include "sql/sql_list.h"
31
32/**
33 An iterator much like IndexRangeScanIterator, but it scans in the reverse
34 order. This makes it at times more complicated, but since it doesn't support
35 being a part of a ROR scan, it is also less complicated in many ways.
36
37 One could argue that this and IndexRangeScanIterator should be factored into
38 a common base class with separate _ASC and _DESC classes, but they don't
39 actually duplicate that much code.
40 */
42 public:
44 double expected_rows, int index,
45 MEM_ROOT *return_mem_root, uint mrr_flags,
47 bool using_extended_key_parts);
49 int Read() override;
50 bool Init() override;
51
52 private:
53 static range_seq_t quick_range_rev_seq_init(void *init_param, uint, uint);
54
55 const uint m_index; /* Index this quick select uses */
58
60 bool inited = false;
61
62 // TODO: pre-allocate space to avoid malloc/free for small number of columns.
64
65 uint m_mrr_flags; /* Flags to be used with MRR interface */
66
67 Bounds_checked_array<QUICK_RANGE *> ranges; /* ordered array of range ptrs */
68 /* Members needed to use the MRR interface */
70
71 QUICK_RANGE *last_range; // The range we are currently scanning, or nullptr.
73
74 /* Info about index we're scanning */
76
77 // Whether this reverse scan uses extended keyparts (in case of Innodb,
78 // secondary index is extended to include primary key).
80
83};
84
85#endif // SQL_RANGE_OPTIMIZER_REVERSE_INDEX_RANGE_SCAN_H_
A wrapper class which provides array bounds checking.
Definition: sql_array.h:46
Definition: key.h:56
Definition: range_optimizer.h:68
An iterator much like IndexRangeScanIterator, but it scans in the reverse order.
Definition: reverse_index_range_scan.h:41
~ReverseIndexRangeScanIterator() override
Definition: reverse_index_range_scan.cc:64
KEY_PART_INFO * key_part_info
Definition: reverse_index_range_scan.h:75
uint m_mrr_flags
Definition: reverse_index_range_scan.h:65
int cmp_prev(QUICK_RANGE *range)
Definition: reverse_index_range_scan.cc:271
bool m_using_extended_key_parts
Definition: reverse_index_range_scan.h:79
static range_seq_t quick_range_rev_seq_init(void *init_param, uint, uint)
Definition: reverse_index_range_scan.cc:281
QUICK_RANGE * last_range
Definition: reverse_index_range_scan.h:71
MEM_ROOT * mem_root
Definition: reverse_index_range_scan.h:59
Bounds_checked_array< QUICK_RANGE * > ranges
Definition: reverse_index_range_scan.h:67
int Read() override
Read a single row.
Definition: reverse_index_range_scan.cc:122
const uint m_index
Definition: reverse_index_range_scan.h:55
ha_rows m_expected_rows
Definition: reverse_index_range_scan.h:56
bool inited
Definition: reverse_index_range_scan.h:60
ReverseIndexRangeScanIterator(THD *thd, TABLE *table, ha_rows *examined_rows, double expected_rows, int index, MEM_ROOT *return_mem_root, uint mrr_flags, Bounds_checked_array< QUICK_RANGE * > ranges, bool using_extended_key_parts)
Definition: reverse_index_range_scan.cc:34
int current_range_idx
Definition: reverse_index_range_scan.h:72
QUICK_RANGE_SEQ_CTX qr_traversal_ctx
Definition: reverse_index_range_scan.h:69
bool range_reads_after_key(QUICK_RANGE *range)
Definition: reverse_index_range_scan.cc:258
MY_BITMAP column_bitmap
Definition: reverse_index_range_scan.h:63
ha_rows * m_examined_rows
Definition: reverse_index_range_scan.h:57
bool Init() override
Initialize or reinitialize the iterator.
Definition: reverse_index_range_scan.cc:70
THD * thd() const
Definition: row_iterator.h:227
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
Definition: row_iterator.h:233
TABLE * table() const
Definition: row_iterator.h:245
my_off_t ha_rows
Definition: my_base.h:1140
void * range_seq_t
Definition: handler.h:3785
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
Definition: table.h:1403
Definition: gen_lex_token.cc:148