MySQL 8.0.39
Source Code Documentation
index_skip_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_SKIP_SCAN_H_
25#define SQL_RANGE_OPTIMIZER_INDEX_SKIP_SCAN_H_
26
27#include <sys/types.h>
28
29#include "my_alloc.h"
30#include "my_base.h"
31#include "my_bitmap.h"
32#include "my_inttypes.h"
33#include "sql/field.h" // Field
34#include "sql/key.h"
35#include "sql/malloc_allocator.h" // IWYU pragma: keep
38
39class Cost_estimate;
40class JOIN;
41class SEL_ARG;
42class SEL_ROOT;
43class String;
44struct TABLE;
45
46/*
47 Index scan for range queries that can use skip scans.
48
49 This class provides a specialized index access method for the queries
50 of the forms:
51
52 SELECT A_1,...,A_k, B_1,...,B_m, C
53 FROM T
54 WHERE
55 EQ(A_1,...,A_k)
56 AND RNG(C);
57
58 where all selected fields are parts of the same index.
59 The class of queries that can be processed by this quick select is fully
60 specified in the description of get_best_skip_scan() in opt_range.cc.
61
62 Since one of the requirements is that all select fields are part of the same
63 index, this class produces only index keys, and not complete records.
64*/
65
67 private:
68 uint index; /* Index this quick select uses */
69 KEY *index_info; /* Index for skip scan */
70 MY_BITMAP column_bitmap; /* Map of key parts to be read */
71
72 const uint eq_prefix_len; /* Total length of the equality prefix. */
73 uint eq_prefix_key_parts; /* A number of keyparts in skip scan prefix */
75 uchar *eq_prefix; /* Storage for current equality prefix. */
76
77 // Total length of first used_key_parts parts of the key.
79
80 // Max. number of (first) key parts this quick select uses for retrieval.
81 // eg. for "(key1p1=c1 AND key1p2=c2) OR key1p1=c2" used_key_parts == 2.
83
84 uchar *distinct_prefix; /* Storage for prefix A_1, ... B_m. */
87
90 /*
91 Denotes whether the first key for the current equality prefix was
92 retrieved.
93 */
95
96 /* Storage for full lookup key for use with handler::read_range_first/next */
102
105
107
108 bool next_eq_prefix();
109
110 public:
114 MEM_ROOT *temp_mem_root, bool has_aggregate_function,
118 ~IndexSkipScanIterator() override;
119 bool Init() override;
120 int Read() override;
121};
122
123#endif // SQL_RANGE_OPTIMIZER_INDEX_SKIP_SCAN_H_
Used to store optimizer cost estimates.
Definition: handler.h:3706
Definition: index_skip_scan.h:66
EQPrefix * eq_prefixes
Definition: index_skip_scan.h:74
bool has_aggregate_function
Definition: index_skip_scan.h:106
uchar *const max_range_key
Definition: index_skip_scan.h:98
bool next_eq_prefix()
Increments cur_prefix and sets what the next equality prefix should be.
Definition: index_skip_scan.cc:195
uchar *const max_search_key
Definition: index_skip_scan.h:100
IndexSkipScanIterator(THD *thd, TABLE *table, KEY *index_info, uint index, uint eq_prefix_len, uint eq_prefix_key_parts, EQPrefix *eq_prefixes, uint used_key_parts, MEM_ROOT *temp_mem_root, bool has_aggregate_function, uchar *min_range_key, uchar *max_range_key, uchar *min_search_key, uchar *max_search_key, uint range_cond_flag, uint range_key_len)
Construct new quick select for queries that can do skip scans.
Definition: index_skip_scan.cc:69
uchar * distinct_prefix
Definition: index_skip_scan.h:84
key_range start_key
Definition: index_skip_scan.h:103
const uint range_cond_flag
Definition: index_skip_scan.h:101
uint distinct_prefix_key_parts
Definition: index_skip_scan.h:86
uchar *const min_range_key
Definition: index_skip_scan.h:97
~IndexSkipScanIterator() override
Definition: index_skip_scan.cc:121
MY_BITMAP column_bitmap
Definition: index_skip_scan.h:70
uint index
Definition: index_skip_scan.h:68
uint max_used_key_length
Definition: index_skip_scan.h:78
int Read() override
Get the next row for skip scan.
Definition: index_skip_scan.cc:262
bool Init() override
Initialize or reinitialize the iterator.
Definition: index_skip_scan.cc:126
const uint eq_prefix_len
Definition: index_skip_scan.h:72
uchar * eq_prefix
Definition: index_skip_scan.h:75
key_range end_key
Definition: index_skip_scan.h:104
bool seen_first_key
Definition: index_skip_scan.h:94
uint distinct_prefix_len
Definition: index_skip_scan.h:85
const uint range_key_len
Definition: index_skip_scan.h:89
uchar *const min_search_key
Definition: index_skip_scan.h:99
uint used_key_parts
Definition: index_skip_scan.h:82
uint eq_prefix_key_parts
Definition: index_skip_scan.h:73
MEM_ROOT * mem_root
Definition: index_skip_scan.h:88
KEY * index_info
Definition: index_skip_scan.h:69
Definition: sql_optimizer.h:133
Definition: key.h:113
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:168
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
Definition: row_iterator.h:234
TABLE * table() const
Definition: row_iterator.h:246
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
This file includes constants used by all storage engines.
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:52
Definition: index_skip_scan_plan.h:53
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: table.h:1399
Definition: my_base.h:1124
unsigned int uint
Definition: uca9-dump.cc:75