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