MySQL 9.1.0
Source Code Documentation
index_range_scan_plan.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_PLAN_H_
25#define SQL_RANGE_OPTIMIZER_INDEX_RANGE_SCAN_PLAN_H_
26
27#include <sys/types.h>
28
29#include "my_dbug.h"
30#include "sql/handler.h"
36#include "sql/sql_const.h"
37
39class RANGE_OPT_PARAM;
40class SEL_ROOT;
41class SEL_TREE;
42struct MEM_ROOT;
43
44bool get_ranges_from_tree(MEM_ROOT *return_mem_root, TABLE *table,
45 KEY_PART *key, uint keyno, SEL_ROOT *key_tree,
46 uint num_key_parts, unsigned *used_key_parts,
47 unsigned *num_exact_key_parts, Quick_ranges *ranges);
48
49/*
50 Get best "range" table read plan for given SEL_TREE, also update some info
51
52 SYNOPSIS
53 get_key_scans_params()
54 param Parameters from test_quick_select
55 tree Make range select for this SEL_TREE
56 index_read_must_be_used true <=> assume 'index only' option will be set
57 (except for clustered PK indexes)
58 update_tbl_stats true <=> update table->quick_* with information
59 about range scans we've evaluated.
60 interesting_order The sort order the range access method must be
61 able to provide. Three-value logic:
62 asc/desc/don't care
63 skip_records_in_range Same value as JOIN_TAB::skip_records_in_range().
64 cost_est Maximum cost. i.e. don't create read plans with
65 cost > cost_est.
66 ror_only true <=> consider only ROR scans.
67 needed_reg ptr to needed_reg argument
68 of test_quick_select().
69
70 DESCRIPTION
71 Find the best "range" table read plan for given SEL_TREE.
72 The side effects are
73 - tree->ror_scans is updated to indicate which scans are ROR scans.
74 - if update_tbl_stats=true then table->quick_* is updated with info
75 about every possible range scan.
76
77 RETURN
78 Best range read plan
79 NULL if no plan found or error occurred
80*/
81
83 SEL_TREE *tree, bool index_read_must_be_used,
84 bool update_tbl_stats,
85 enum_order interesting_order,
86 bool skip_records_in_range, double cost_est,
87 bool ror_only, Key_map *needed_reg);
88
89/*
90 Calculate estimate of number records that will be retrieved by a range
91 scan on given index using given SEL_ARG intervals tree.
92
93 SYNOPSIS
94 check_quick_select()
95 param Parameter from test_quick_select
96 idx Number of index to use in RANGE_OPT_PARAM::key
97 SEL_TREE::key
98 index_only true - assume only index tuples will be accessed
99 false - assume full table rows will be read
100 tree Transformed selection condition, tree->key[idx] holds
101 the intervals for the given index.
102 update_tbl_stats true <=> update table->quick_* with information
103 about range scan we've evaluated.
104 order_direction The sort order the range access method must be able
105 to provide. Three-value logic: asc/desc/don't care
106 skip_records_in_range Same value as JOIN_TAB::skip_records_in_range().
107 mrr_flags INOUT MRR access flags
108 cost OUT Scan cost
109 is_ror_scan OUT Set to reflect if the key scan is a ROR
110 (see is_key_scan_ror function for more info)
111 is_imerge_scan OUT Set to reflect if the key scan can be used for
112 index-merge-scan
113
114 NOTES
115 param->table->quick_*, param->range_count (and maybe others) are
116 updated with data of given key scan, see quick_range_seq_next for details.
117
118 RETURN
119 Estimate # of records to be retrieved.
120 HA_POS_ERROR if estimate calculation failed due to table handler problems.
121*/
122ha_rows check_quick_select(THD *thd, RANGE_OPT_PARAM *param, uint idx,
123 bool index_only, SEL_ROOT *tree,
124 bool update_tbl_stats, enum_order order_direction,
125 bool skip_records_in_range, uint *mrr_flags,
126 uint *bufsize, Cost_estimate *cost,
127 bool *is_ror_scan, bool *is_imerge_scan);
128
129#ifndef NDEBUG
130void dbug_dump_range(int indent, bool verbose, TABLE *table, int index,
131 KEY_PART *used_key_part,
133#endif
134
136 const RANGE_OPT_PARAM *param,
137 Opt_trace_object *trace_object);
138
139#endif // SQL_RANGE_OPTIMIZER_INDEX_RANGE_SCAN_PLAN_H_
Definition: sql_bitmap.h:154
A wrapper class which provides array bounds checking.
Definition: sql_array.h:47
Used to store optimizer cost estimates.
Definition: handler.h:3877
A JSON object (unordered set of key/value pairs).
Definition: opt_trace.h:802
Definition: range_opt_param.h:29
A graph of (possible multiple) key ranges, represented as a red-black binary tree.
Definition: tree.h:68
Definition: tree.h:871
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
ha_rows check_quick_select(THD *thd, RANGE_OPT_PARAM *param, uint idx, bool index_only, SEL_ROOT *tree, bool update_tbl_stats, enum_order order_direction, bool skip_records_in_range, uint *mrr_flags, uint *bufsize, Cost_estimate *cost, bool *is_ror_scan, bool *is_imerge_scan)
Definition: index_range_scan_plan.cc:568
void trace_basic_info_index_range_scan(THD *thd, const AccessPath *path, const RANGE_OPT_PARAM *param, Opt_trace_object *trace_object)
Definition: index_range_scan_plan.cc:796
AccessPath * get_key_scans_params(THD *thd, RANGE_OPT_PARAM *param, SEL_TREE *tree, bool index_read_must_be_used, bool update_tbl_stats, enum_order interesting_order, bool skip_records_in_range, double cost_est, bool ror_only, Key_map *needed_reg)
Definition: index_range_scan_plan.cc:822
void dbug_dump_range(int indent, bool verbose, TABLE *table, int index, KEY_PART *used_key_part, Bounds_checked_array< QUICK_RANGE * > ranges)
Definition: index_range_scan_plan.cc:1314
bool get_ranges_from_tree(MEM_ROOT *return_mem_root, TABLE *table, KEY_PART *key, uint keyno, SEL_ROOT *key_tree, uint num_key_parts, unsigned *used_key_parts, unsigned *num_exact_key_parts, Quick_ranges *ranges)
Definition: index_range_scan_plan.cc:774
enum_order
Definition: key_spec.h:65
my_off_t ha_rows
Definition: my_base.h:1141
static uint verbose
Definition: mysqlcheck.cc:66
static char * path
Definition: mysqldump.cc:149
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
required string key
Definition: replication_asynchronous_connection_failover.proto:60
File containing constants that can be used throughout the server.
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:227
Definition: range_optimizer.h:55
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: table.h:1421