MySQL 8.3.0
Source Code Documentation
index_skip_scan_plan.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_PLAN_H_
24#define SQL_RANGE_OPTIMIZER_INDEX_SKIP_SCAN_PLAN_H_
25
26#include <sys/types.h>
27
28#include "my_base.h"
30
31class KEY;
32class KEY_PART_INFO;
34class RANGE_OPT_PARAM;
35class SEL_ARG;
36class SEL_ROOT;
37class SEL_TREE;
38struct MEM_ROOT;
39
40/*
41 This is an array of array of equality constants with length
42 eq_prefix_key_parts.
43
44 For example, an equality predicate like "a IN (1, 2) AND b IN (2, 3, 4)",
45 eq_prefixes will contain:
46
47 [
48 { eq_key_prefixes = array[1, 2], cur_eq_prefix = ... },
49 { eq_key_prefixes = array[2, 3, 4], cur_eq_prefix = ... }
50 ]
51 */
52struct EQPrefix {
54
55 /*
56 During skip scan, we will have to iterate through all possible
57 equality prefixes. This is the product of all the elements in
58 eq_prefix_elements. In the above example, there are 2 x 3 = 6 possible
59 equality prefixes.
60
61 To track which prefix we are on, we use cur_eq_prefix. For example,
62 if both EQPrefixes have the value 1 here, it indicates that the current
63 equality prefix is (2, 3).
64 */
65 unsigned cur_eq_prefix;
66};
67
68/**
69 Logically a part of AccessPath::index_skip_scan(), but is too large,
70 so split out into its own struct.
71 */
73 KEY *index_info; ///< The index chosen for data access
74 uint eq_prefix_len; ///< Length of the equality prefix
75 uint eq_prefix_key_parts; ///< Number of key parts in the equality prefix
76 EQPrefix *eq_prefixes; ///< Array of equality constants (IN list)
77 KEY_PART_INFO *range_key_part; ///< The key part matching the range condition
78 uint used_key_parts; ///< Number of index keys used for skip scan
79 double read_cost; ///< Total cost of read
80 uint index; ///< Position of chosen index
81
89
90 // The sub-tree corresponding to the range condition
91 // (on key part C - for more details see description of get_best_skip_scan()).
92 //
93 // Does not necessarily live as long as the AccessPath, so used for tracing
94 // only.
96
97 SEL_ROOT *index_range_tree; ///< The sub-tree corresponding to index_info
98 bool has_aggregate_function; ///< TRUE if there are aggregate functions.
99};
100
102 RANGE_OPT_PARAM *param,
103 SEL_TREE *tree,
104 enum_order order_direction,
105 bool skip_records_in_range,
106 bool force_skip_scan);
108 enum_order order_direction,
109 bool skip_records_in_range,
110 bool force_skip_scan);
111
113 const RANGE_OPT_PARAM *param,
114 Opt_trace_object *trace_object);
115
116#ifndef NDEBUG
117void dbug_dump_index_skip_scan(int indent, bool verbose,
118 const AccessPath *path);
119#endif
120
121#endif // SQL_RANGE_OPTIMIZER_INDEX_SKIP_SCAN_PLAN_H_
A wrapper class which provides array bounds checking.
Definition: sql_array.h:46
Definition: key.h:56
Definition: key.h:112
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:425
A JSON object (unordered set of key/value pairs).
Definition: opt_trace.h:801
Definition: range_opt_param.h:28
Definition: tree.h:464
A graph of (possible multiple) key ranges, represented as a red-black binary tree.
Definition: tree.h:67
Definition: tree.h:870
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
void trace_basic_info_index_skip_scan(THD *thd, const AccessPath *path, const RANGE_OPT_PARAM *param, Opt_trace_object *trace_object)
Definition: index_skip_scan_plan.cc:70
void dbug_dump_index_skip_scan(int indent, bool verbose, const AccessPath *path)
Definition: index_skip_scan_plan.cc:803
Mem_root_array< AccessPath * > get_all_skip_scans(THD *thd, RANGE_OPT_PARAM *param, SEL_TREE *tree, enum_order order_direction, bool skip_records_in_range, bool force_skip_scan)
Test if skip scan is applicable and if so, construct a new AccessPath for each candidate index skip s...
Definition: index_skip_scan_plan.cc:141
AccessPath * get_best_skip_scan(THD *thd, RANGE_OPT_PARAM *param, SEL_TREE *tree, enum_order order_direction, bool skip_records_in_range, bool force_skip_scan)
Test if skip scan is applicable and if so, construct a new AccessPath.
Definition: index_skip_scan_plan.cc:210
enum_order
Definition: key_spec.h:64
This file includes constants used by all storage engines.
unsigned char uchar
Definition: my_inttypes.h:51
static uint verbose
Definition: mysqlcheck.cc:65
static char * path
Definition: mysqldump.cc:148
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:212
Definition: index_skip_scan_plan.h:52
Bounds_checked_array< uchar * > eq_key_prefixes
Definition: index_skip_scan_plan.h:53
unsigned cur_eq_prefix
Definition: index_skip_scan_plan.h:65
Logically a part of AccessPath::index_skip_scan(), but is too large, so split out into its own struct...
Definition: index_skip_scan_plan.h:72
double read_cost
Total cost of read.
Definition: index_skip_scan_plan.h:79
uint eq_prefix_len
Length of the equality prefix.
Definition: index_skip_scan_plan.h:74
uchar * min_range_key
Definition: index_skip_scan_plan.h:82
uint range_cond_flag
Definition: index_skip_scan_plan.h:86
KEY * index_info
The index chosen for data access.
Definition: index_skip_scan_plan.h:73
bool has_aggregate_function
TRUE if there are aggregate functions.
Definition: index_skip_scan_plan.h:98
uint num_output_rows
Definition: index_skip_scan_plan.h:88
uint range_key_len
Definition: index_skip_scan_plan.h:87
uchar * max_search_key
Definition: index_skip_scan_plan.h:85
uchar * max_range_key
Definition: index_skip_scan_plan.h:83
SEL_ROOT * index_range_tree
The sub-tree corresponding to index_info.
Definition: index_skip_scan_plan.h:97
uint used_key_parts
Number of index keys used for skip scan.
Definition: index_skip_scan_plan.h:78
uint eq_prefix_key_parts
Number of key parts in the equality prefix.
Definition: index_skip_scan_plan.h:75
uchar * min_search_key
Definition: index_skip_scan_plan.h:84
KEY_PART_INFO * range_key_part
The key part matching the range condition.
Definition: index_skip_scan_plan.h:77
EQPrefix * eq_prefixes
Array of equality constants (IN list)
Definition: index_skip_scan_plan.h:76
const SEL_ARG * range_part_tracing_only
Definition: index_skip_scan_plan.h:95
uint index
Position of chosen index.
Definition: index_skip_scan_plan.h:80
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82