24#ifndef SQL_RANGE_OPTIMIZER_PATH_HELPERS_H_
25#define SQL_RANGE_OPTIMIZER_PATH_HELPERS_H_
49 return path->index_skip_scan().param->has_aggregate_function;
52 return path->group_index_skip_scan().param->have_agg_distinct;
73 path->index_range_scan().reverse;
82 if (
path->index_range_scan().geometry) {
85 path->index_range_scan().reverse =
true;
86 TABLE *table =
path->index_range_scan().used_key_part[0].field->table;
87 path->index_range_scan().using_extended_key_parts =
88 (used_key_parts > table->
key_info[
path->index_range_scan().index]
115 switch (
path->type) {
117 return path->index_range_scan().index;
119 return path->index_skip_scan().index;
121 return path->group_index_skip_scan().index;
134 if (
path->index_range_scan().num_ranges == 1) {
138 path->index_range_scan().used_key_part[0].field->table->key_info +
139 path->index_range_scan().index;
147 switch (
path->type) {
149 for (
uint i = 0; i <
path->index_range_scan().num_used_key_parts; ++i) {
152 path->index_range_scan().used_key_part[i].field->field_index());
164 if (
path->rowid_intersection().cpk_child !=
nullptr) {
174 for (
uint i = 0; i <
path->index_skip_scan().num_used_key_parts; ++i) {
176 .param->index_info->key_part[i]
177 .field->field_index());
181 for (
uint i = 0; i <
path->group_index_skip_scan().num_used_key_parts;
184 .param->index_info->key_part[i]
185 .field->field_index());
194 switch (
path->type) {
196 return path->index_range_scan().num_used_key_parts;
198 return path->index_skip_scan().num_used_key_parts;
200 return path->group_index_skip_scan().num_used_key_parts;
217 switch (
path->type) {
219 return is_key_used(
path->index_range_scan().used_key_part[0].field->table,
220 path->index_range_scan().index, fields);
234 return path->rowid_intersection().cpk_child !=
nullptr &&
245 path->index_skip_scan().index, fields);
248 path->group_index_skip_scan().index, fields);
261 switch (
path->type) {
263 int max_used_key_length = 0;
265 path->index_range_scan().num_ranges};
267 max_used_key_length =
268 std::max<int>(max_used_key_length,
range->min_length);
269 max_used_key_length =
270 std::max<int>(max_used_key_length,
range->max_length);
272 return max_used_key_length;
275 int max_used_key_length = 0;
277 for (
uint i = 0; i <
path->index_skip_scan().num_used_key_parts;
279 max_used_key_length +=
p->store_length;
281 return max_used_key_length;
284 return path->group_index_skip_scan().param->max_used_key_length;
296 switch (
path->type) {
298 TABLE *table =
path->index_range_scan().used_key_part[0].field->table;
305 TABLE *table =
path->index_merge().table;
310 for (
bool print_primary : {
false,
true}) {
314 if (is_primary != print_primary)
continue;
328 for (
AccessPath *current : *
path->rowid_intersection().children) {
335 if (
path->rowid_intersection().cpk_child) {
357 str->append(
path->index_skip_scan().param->index_info->name);
363 str->append(
path->group_index_skip_scan().param->index_info->name);
381 switch (
path->type) {
383 TABLE *table =
path->index_range_scan().used_key_part[0].field->table;
403 key_names->
append(
path->index_skip_scan().param->index_info->name);
413 key_names->
append(
path->group_index_skip_scan().param->index_info->name);
439 switch (
path->type) {
464 switch (
path->type) {
468 return path->index_merge().forced_by_hint;
470 return path->rowid_intersection().forced_by_hint;
472 return path->rowid_union().forced_by_hint;
474 return path->index_skip_scan().forced_by_hint;
476 return path->group_index_skip_scan().forced_by_hint;
489 switch (
path->type) {
491 const auto ¶m =
path->index_range_scan();
493 param.index, param.used_key_part,
494 {param.ranges, param.num_ranges});
503 *
path->index_merge().children);
A wrapper class which provides array bounds checking.
Definition: sql_array.h:47
const char * name
Name of key.
Definition: key.h:153
uint user_defined_key_parts
How many key_parts.
Definition: key.h:122
A JSON object (unordered set of key/value pairs).
Definition: opt_trace.h:799
Definition: range_optimizer.h:69
uint16 flag
Stores bitwise-or'ed bits defined in enum key_range_flags.
Definition: range_optimizer.h:75
uint16 min_length
Definition: range_optimizer.h:72
Definition: range_opt_param.h:29
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:168
bool append(const String &s)
Definition: sql_string.cc:413
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
virtual bool primary_key_is_clustered() const
Check if the primary key is clustered or not.
Definition: handler.h:5875
const char * p
Definition: ctype-mb.cc:1237
void trace_basic_info_group_index_skip_scan(THD *thd, const AccessPath *path, const RANGE_OPT_PARAM *, Opt_trace_object *trace_object)
Definition: group_index_skip_scan_plan.cc:78
void dbug_dump_group_index_skip_scan(int indent, bool, const AccessPath *path)
Definition: group_index_skip_scan_plan.cc:1685
void trace_basic_info_index_merge(THD *thd, const AccessPath *path, const RANGE_OPT_PARAM *param, Opt_trace_object *trace_object)
Definition: index_merge_plan.cc:34
void add_keys_and_lengths_index_merge(const AccessPath *path, String *key_names, String *used_lengths)
Definition: index_merge_plan.cc:46
void dbug_dump_index_merge(int indent, bool verbose, const Mem_root_array< AccessPath * > &children)
Definition: index_merge_plan.cc:71
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
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
void dbug_dump_index_skip_scan(int indent, bool verbose, const AccessPath *path)
Definition: index_skip_scan_plan.cc:657
void trace_basic_info_index_skip_scan(THD *thd, const AccessPath *path, const RANGE_OPT_PARAM *, Opt_trace_object *trace_object)
Definition: index_skip_scan_plan.cc:70
bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields)
Definition: key.cc:410
char * longlong10_to_str(int64_t val, char *dst, int radix)
Converts a 64-bit integer to its string representation in decimal notation.
Definition: int2str.cc:101
#define STRING_WITH_LEN(X)
Definition: m_string.h:315
@ EQ_RANGE
Definition: my_base.h:1096
@ NULL_RANGE
Definition: my_base.h:1101
#define HA_NOSAME
Do not allow duplicate records.
Definition: my_base.h:474
static void bitmap_set_bit(MY_BITMAP *map, uint bit)
Definition: my_bitmap.h:80
static uint verbose
Definition: mysqlcheck.cc:65
static char * path
Definition: mysqldump.cc:137
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1052
Definition: buf0block_hint.cc:30
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
void add_info_string(const AccessPath *path, String *str)
Definition: path_helpers.h:295
bool unique_key_range(const AccessPath *path)
Return true if there is only one range and this uses the whole unique key.
Definition: path_helpers.h:130
bool is_loose_index_scan(const AccessPath *path)
Definition: path_helpers.h:41
void add_keys_and_lengths(const AccessPath *path, String *key_names, String *used_lengths)
Definition: path_helpers.h:379
unsigned used_index(const AccessPath *path)
If this is an index range scan, and that range scan uses a single index, returns the index used.
Definition: path_helpers.h:114
bool get_forced_by_hint(const AccessPath *path)
Definition: path_helpers.h:463
unsigned get_max_used_key_length(const AccessPath *path)
Get the total length of first used_key_parts parts of the key, in bytes.
Definition: path_helpers.h:260
bool uses_index_on_fields(const AccessPath *path, const MY_BITMAP *fields)
Return whether any index used by this range scan uses the field(s) marked in passed bitmap.
Definition: path_helpers.h:215
void trace_basic_info(THD *thd, const AccessPath *path, const RANGE_OPT_PARAM *param, Opt_trace_object *trace_object)
Add basic info for this range scan to the optimizer trace.
Definition: path_helpers.h:436
bool is_agg_loose_index_scan(const AccessPath *path)
Definition: path_helpers.h:46
void set_need_sorted_output(AccessPath *path)
Definition: path_helpers.h:96
unsigned get_used_key_parts(const AccessPath *path)
Definition: path_helpers.h:193
bool make_reverse(uint used_key_parts, AccessPath *path)
Ask the AccessPath to reverse itself; returns false if successful.
Definition: path_helpers.h:80
bool is_reverse_sorted_range(const AccessPath *path)
Whether the access path is an INDEX_RANGE_SCAN that returns rows in reverse order.
Definition: path_helpers.h:71
void get_fields_used(const AccessPath *path, MY_BITMAP *used_fields)
Definition: path_helpers.h:146
void dbug_dump(const AccessPath *path, int indent, bool verbose)
Definition: path_helpers.h:488
bool reverse_sort_possible(const AccessPath *path)
Whether the range access method is capable of returning records in reverse order.
Definition: path_helpers.h:63
required string key
Definition: replication_asynchronous_connection_failover.proto:60
void add_keys_and_lengths_rowid_union(const AccessPath *path, String *key_names, String *used_lengths)
Definition: rowid_ordered_retrieval_plan.cc:1065
void add_keys_and_lengths_rowid_intersection(const AccessPath *path, String *key_names, String *used_lengths)
Definition: rowid_ordered_retrieval_plan.cc:1030
void dbug_dump_rowid_union(int indent, bool verbose, const Mem_root_array< AccessPath * > &children)
Definition: rowid_ordered_retrieval_plan.cc:1090
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:81
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:99
void dbug_dump_rowid_intersection(int indent, bool verbose, const Mem_root_array< AccessPath * > &children)
Definition: rowid_ordered_retrieval_plan.cc:1080
#define HA_MRR_SORTED
Definition: handler.h:3843
constexpr const unsigned int MAX_KEY
Definition: sql_const.h:45
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:193
@ GROUP_INDEX_SKIP_SCAN
Definition: access_path.h:227
@ INDEX_RANGE_SCAN
Definition: access_path.h:222
@ ROWID_UNION
Definition: access_path.h:225
@ INDEX_SKIP_SCAN
Definition: access_path.h:226
@ INDEX_MERGE
Definition: access_path.h:223
@ ROWID_INTERSECTION
Definition: access_path.h:224
Definition: my_bitmap.h:43
uint primary_key
Definition: table.h:911
handler * file
Definition: table.h:1401
KEY * key_info
Definition: table.h:1488
TABLE_SHARE * s
Definition: table.h:1400
Definition: gen_lex_token.cc:149
unsigned int uint
Definition: uca9-dump.cc:75