MySQL 8.1.0
Source Code Documentation
rowid_ordered_retrieval_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_ROWID_ORDERED_RETRIEVAL_PLAN_H_
24#define SQL_RANGE_OPTIMIZER_ROWID_ORDERED_RETRIEVAL_PLAN_H_
25
26#include <sys/types.h>
27
28#include "my_base.h"
29#include "sql/handler.h"
33
35class RANGE_OPT_PARAM;
36class SEL_ROOT;
37class SEL_TREE;
38struct MEM_ROOT;
39
40// TODO(sgunders): Consider whether we can create INDEX_RANGE_SCAN AccessPaths
41// directly, instead of first creating this structure and then creating
42// AccessPaths from it.
44 uint idx; ///< # of used key in param->keys
45 uint keynr; ///< # of used key in table
46 ha_rows records; ///< estimate of # records this scan will return
47
48 /** Set of intervals over key fields that will be used for row retrieval. */
50
51 /** Fields used in the query and covered by this ROR scan. */
53
54 /**
55 Cost of reading all index records with values in sel_arg intervals set
56 (assuming there is no need to access full table records)
57 */
59
60 /**
61 The ranges to scan for this index. Must be allocated on the return_mem_root.
62 */
65};
66
67// Planning related information when picking the best combination
68// of rowid ordered scans for a ROR-Intersect plan.
70 public:
71 ROR_intersect_plan(const RANGE_OPT_PARAM *param, size_t num_fields);
74
75 bool add(OverflowBitset needed_fields, ROR_SCAN_INFO *ror_scan,
76 bool is_cpk_scan, Opt_trace_object *trace_costs, bool ignore_cost);
77 double get_scan_selectivity(const ROR_SCAN_INFO *scan) const;
78 size_t num_scans() const { return m_ror_scans.size(); }
79
80 public:
81 /// Range optimizer parameter
83 /// Rowid ordered scans that are part of this plan.
85 /// Whether this plan with the chosen rowid ordered scans is covering or not.
86 bool m_is_covering{false};
87 /// Output rows for this plan.
88 double m_out_rows;
89 /// Total cost for the plan - m_index_read_cost + disk_sweep_cost
91
92 private:
93 /// Bitmap of fields covered by the scans in the plan.
95 /// Number of rows to be read from indexes that are used for rowid ordered
96 /// scans
98 /// Total cost for reading the indexes picked in the plan.
100};
101
103 TABLE *table,
104 bool index_merge_intersect_allowed,
105 SEL_TREE *tree, double cost_est,
106 bool force_index_merge_result,
107 bool reuse_handler);
108
110 const RANGE_OPT_PARAM *param,
111 Opt_trace_object *trace_object);
112
114 const RANGE_OPT_PARAM *param,
115 Opt_trace_object *trace_object);
116
118 String *key_names,
119 String *used_lengths);
120
122 String *used_lengths);
123
125
126ROR_SCAN_INFO *make_ror_scan(const RANGE_OPT_PARAM *param, int idx,
127 SEL_ROOT *sel_root, OverflowBitset needed_fields);
128
130 OverflowBitset needed_fields, MEM_ROOT *mem_root);
131
133 TABLE *table,
134 KEY_PART *used_key_part,
135 bool reuse_handler,
137
138#ifndef NDEBUG
139void dbug_dump_rowid_intersection(int indent, bool verbose,
140 const Mem_root_array<AccessPath *> &children);
141
142void dbug_dump_rowid_union(int indent, bool verbose,
143 const Mem_root_array<AccessPath *> &children);
144#endif
145
146#endif // SQL_RANGE_OPTIMIZER_ROWID_ORDERED_RETRIEVAL_PLAN_H_
A wrapper class which provides array bounds checking.
Definition: sql_array.h:46
Used to store optimizer cost estimates.
Definition: handler.h:3752
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:798
Definition: overflow_bitset.h:76
Definition: range_opt_param.h:28
Definition: rowid_ordered_retrieval_plan.h:69
Cost_estimate m_total_cost
Total cost for the plan - m_index_read_cost + disk_sweep_cost.
Definition: rowid_ordered_retrieval_plan.h:90
double get_scan_selectivity(const ROR_SCAN_INFO *scan) const
Definition: rowid_ordered_retrieval_plan.cc:369
ROR_intersect_plan(const ROR_intersect_plan &)=delete
ha_rows m_index_records
Number of rows to be read from indexes that are used for rowid ordered scans.
Definition: rowid_ordered_retrieval_plan.h:97
OverflowBitset m_covered_fields
Bitmap of fields covered by the scans in the plan.
Definition: rowid_ordered_retrieval_plan.h:94
ROR_intersect_plan & operator=(const ROR_intersect_plan &plan)
Definition: rowid_ordered_retrieval_plan.cc:254
bool m_is_covering
Whether this plan with the chosen rowid ordered scans is covering or not.
Definition: rowid_ordered_retrieval_plan.h:86
ROR_intersect_plan(const RANGE_OPT_PARAM *param, size_t num_fields)
Definition: rowid_ordered_retrieval_plan.cc:246
double m_out_rows
Output rows for this plan.
Definition: rowid_ordered_retrieval_plan.h:88
const RANGE_OPT_PARAM * m_param
Range optimizer parameter.
Definition: rowid_ordered_retrieval_plan.h:82
bool add(OverflowBitset needed_fields, ROR_SCAN_INFO *ror_scan, bool is_cpk_scan, Opt_trace_object *trace_costs, bool ignore_cost)
Definition: rowid_ordered_retrieval_plan.cc:513
size_t num_scans() const
Definition: rowid_ordered_retrieval_plan.h:78
Cost_estimate m_index_read_cost
Total cost for reading the indexes picked in the plan.
Definition: rowid_ordered_retrieval_plan.h:99
Mem_root_array< ROR_SCAN_INFO * > m_ror_scans
Rowid ordered scans that are part of this plan.
Definition: rowid_ordered_retrieval_plan.h:84
A graph of (possible multiple) key ranges, represented as a red-black binary tree.
Definition: tree.h:67
Definition: tree.h:870
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:33
static MEM_ROOT mem_root
Definition: client_plugin.cc:113
This file includes constants used by all storage engines.
my_off_t ha_rows
Definition: my_base.h:1139
static uint verbose
Definition: mysqlcheck.cc:65
static char * path
Definition: mysqldump.cc:140
static PFS_engine_table_share_proxy table
Definition: pfs.cc:60
OverflowBitset is a fixed-size (once allocated) bitmap that is optimized for the common case of few e...
void add_keys_and_lengths_rowid_union(const AccessPath *path, String *key_names, String *used_lengths)
Definition: rowid_ordered_retrieval_plan.cc:945
AccessPath * get_best_ror_intersect(THD *thd, const RANGE_OPT_PARAM *param, TABLE *table, bool index_merge_intersect_allowed, SEL_TREE *tree, double cost_est, bool force_index_merge_result, bool reuse_handler)
Definition: rowid_ordered_retrieval_plan.cc:678
void find_intersect_order(Mem_root_array< ROR_SCAN_INFO * > *ror_scans, OverflowBitset needed_fields, MEM_ROOT *mem_root)
Sort indexes in an order that is likely to be a good index merge intersection order.
Definition: rowid_ordered_retrieval_plan.cc:215
AccessPath * MakeRowIdOrderedIndexScanAccessPath(ROR_SCAN_INFO *scan, TABLE *table, KEY_PART *used_key_part, bool reuse_handler, MEM_ROOT *mem_root)
Definition: rowid_ordered_retrieval_plan.cc:580
void add_keys_and_lengths_rowid_intersection(const AccessPath *path, String *key_names, String *used_lengths)
Definition: rowid_ordered_retrieval_plan.cc:910
void dbug_dump_rowid_union(int indent, bool verbose, const Mem_root_array< AccessPath * > &children)
Definition: rowid_ordered_retrieval_plan.cc:970
void trace_basic_info_rowid_intersection(THD *thd, const AccessPath *path, const RANGE_OPT_PARAM *param, Opt_trace_object *trace_object)
Definition: rowid_ordered_retrieval_plan.cc:111
OverflowBitset get_needed_fields(const RANGE_OPT_PARAM *param)
Definition: rowid_ordered_retrieval_plan.cc:85
ROR_SCAN_INFO * make_ror_scan(const RANGE_OPT_PARAM *param, int idx, SEL_ROOT *sel_root, OverflowBitset needed_fields)
Definition: rowid_ordered_retrieval_plan.cc:157
void trace_basic_info_rowid_union(THD *thd, const AccessPath *path, const RANGE_OPT_PARAM *param, Opt_trace_object *trace_object)
Definition: rowid_ordered_retrieval_plan.cc:129
void dbug_dump_rowid_intersection(int indent, bool verbose, const Mem_root_array< AccessPath * > &children)
Definition: rowid_ordered_retrieval_plan.cc:960
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:193
Definition: range_optimizer.h:54
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: rowid_ordered_retrieval_plan.h:43
Cost_estimate index_read_cost
Cost of reading all index records with values in sel_arg intervals set (assuming there is no need to ...
Definition: rowid_ordered_retrieval_plan.h:58
uint keynr
Definition: rowid_ordered_retrieval_plan.h:45
SEL_ROOT * sel_root
Set of intervals over key fields that will be used for row retrieval.
Definition: rowid_ordered_retrieval_plan.h:49
uint idx
Definition: rowid_ordered_retrieval_plan.h:44
uint used_key_parts
Definition: rowid_ordered_retrieval_plan.h:64
ha_rows records
estimate of # records this scan will return
Definition: rowid_ordered_retrieval_plan.h:46
OverflowBitset covered_fields
Fields used in the query and covered by this ROR scan.
Definition: rowid_ordered_retrieval_plan.h:52
Bounds_checked_array< QUICK_RANGE * > ranges
The ranges to scan for this index.
Definition: rowid_ordered_retrieval_plan.h:63
Definition: table.h:1394