24#ifndef SQL_RANGE_OPTIMIZER_PATH_HELPERS_H_
25#define SQL_RANGE_OPTIMIZER_PATH_HELPERS_H_
50 return path->index_skip_scan().param->has_aggregate_function;
53 return path->group_index_skip_scan().param->have_agg_distinct;
74 path->index_range_scan().reverse;
83 if (
path->index_range_scan().geometry) {
86 path->index_range_scan().reverse =
true;
87 TABLE *
table =
path->index_range_scan().used_key_part[0].field->table;
88 path->index_range_scan().using_extended_key_parts =
89 (used_key_parts >
table->key_info[
path->index_range_scan().index]
90 .user_defined_key_parts);
116 switch (
path->type) {
118 return path->index_range_scan().index;
120 return path->index_skip_scan().index;
122 return path->group_index_skip_scan().index;
135 if (
path->index_range_scan().num_ranges == 1) {
139 path->index_range_scan().used_key_part[0].field->table->key_info +
140 path->index_range_scan().index;
148 switch (
path->type) {
150 for (uint i = 0; i <
path->index_range_scan().num_used_key_parts; ++i) {
153 path->index_range_scan().used_key_part[i].field->field_index());
165 if (
path->rowid_intersection().cpk_child !=
nullptr) {
175 for (uint i = 0; i <
path->index_skip_scan().num_used_key_parts; ++i) {
177 .param->index_info->key_part[i]
178 .field->field_index());
182 for (uint i = 0; i <
path->group_index_skip_scan().num_used_key_parts;
185 .param->index_info->key_part[i]
186 .field->field_index());
195 switch (
path->type) {
197 return path->index_range_scan().num_used_key_parts;
199 return path->index_skip_scan().num_used_key_parts;
201 return path->group_index_skip_scan().num_used_key_parts;
203 return path->ref().ref->key_parts;
205 return path->ref_or_null().ref->key_parts;
207 return path->eq_ref().ref->key_parts;
209 return path->pushed_join_ref().ref->key_parts;
211 return path->full_text_search().ref->key_parts;
213 return path->mrr().ref->key_parts;
232 switch (
path->type) {
234 return is_key_used(
path->index_range_scan().used_key_part[0].field->table,
235 path->index_range_scan().index, fields);
249 return path->rowid_intersection().cpk_child !=
nullptr &&
260 path->index_skip_scan().index, fields);
263 path->group_index_skip_scan().index, fields);
276 switch (
path->type) {
278 int max_used_key_length = 0;
280 path->index_range_scan().num_ranges};
282 max_used_key_length =
283 std::max<int>(max_used_key_length,
range->min_length);
284 max_used_key_length =
285 std::max<int>(max_used_key_length,
range->max_length);
287 return max_used_key_length;
290 int max_used_key_length = 0;
292 for (uint i = 0; i <
path->index_skip_scan().num_used_key_parts;
294 max_used_key_length +=
p->store_length;
296 return max_used_key_length;
299 return path->group_index_skip_scan().param->max_used_key_length;
311 switch (
path->type) {
313 TABLE *
table =
path->index_range_scan().used_key_part[0].field->table;
314 KEY *key_info =
table->key_info +
path->index_range_scan().index;
325 for (
bool print_primary : {
false,
true}) {
327 const bool is_primary =
table->file->primary_key_is_clustered() &&
329 if (is_primary != print_primary)
continue;
343 for (
AccessPath *current : *
path->rowid_intersection().children) {
350 if (
path->rowid_intersection().cpk_child) {
372 str->append(
path->index_skip_scan().param->index_info->name);
378 str->append(
path->group_index_skip_scan().param->index_info->name);
396 switch (
path->type) {
398 TABLE *
table =
path->index_range_scan().used_key_part[0].field->table;
399 KEY *key_info =
table->key_info +
path->index_range_scan().index;
418 key_names->
append(
path->index_skip_scan().param->index_info->name);
428 key_names->
append(
path->group_index_skip_scan().param->index_info->name);
454 switch (
path->type) {
479 switch (
path->type) {
483 return path->index_merge().forced_by_hint;
485 return path->rowid_intersection().forced_by_hint;
487 return path->rowid_union().forced_by_hint;
489 return path->index_skip_scan().forced_by_hint;
491 return path->group_index_skip_scan().forced_by_hint;
504 switch (
path->type) {
506 const auto ¶m =
path->index_range_scan();
508 param.index, param.used_key_part,
509 {param.ranges, param.num_ranges});
518 *
path->rowid_intersection().children);
A wrapper class which provides array bounds checking.
Definition: sql_array.h:47
const char * name
Name of key.
Definition: key.h:153
A JSON object (unordered set of key/value pairs).
Definition: opt_trace.h:802
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:167
bool append(const String &s)
Definition: sql_string.cc:419
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
static char buf[MAX_BUF]
Definition: conf_to_src.cc:73
const char * p
Definition: ctype-mb.cc:1225
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:79
void dbug_dump_group_index_skip_scan(int indent, bool, const AccessPath *path)
Definition: group_index_skip_scan_plan.cc:1837
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:804
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:71
MYSQL_STRINGS_EXPORT 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:98
bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields)
Definition: key.cc:411
@ EQ_RANGE
Definition: my_base.h:1097
@ NULL_RANGE
Definition: my_base.h:1102
#define HA_NOSAME
Do not allow duplicate records.
Definition: my_base.h:475
static void bitmap_set_bit(MY_BITMAP *map, uint bit)
Definition: my_bitmap.h:80
static uint verbose
Definition: mysqlcheck.cc:66
static char * path
Definition: mysqldump.cc:149
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1105
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
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:310
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:131
bool is_loose_index_scan(const AccessPath *path)
Definition: path_helpers.h:42
void add_keys_and_lengths(const AccessPath *path, String *key_names, String *used_lengths)
Definition: path_helpers.h:394
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:115
bool get_forced_by_hint(const AccessPath *path)
Definition: path_helpers.h:478
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:275
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:230
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:451
bool is_agg_loose_index_scan(const AccessPath *path)
Definition: path_helpers.h:47
void set_need_sorted_output(AccessPath *path)
Definition: path_helpers.h:97
unsigned get_used_key_parts(const AccessPath *path)
Definition: path_helpers.h:194
bool make_reverse(uint used_key_parts, AccessPath *path)
Ask the AccessPath to reverse itself; returns false if successful.
Definition: path_helpers.h:81
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:72
void get_fields_used(const AccessPath *path, MY_BITMAP *used_fields)
Definition: path_helpers.h:147
void dbug_dump(const AccessPath *path, int indent, bool verbose)
Definition: path_helpers.h:503
bool reverse_sort_possible(const AccessPath *path)
Whether the range access method is capable of returning records in reverse order.
Definition: path_helpers.h:64
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:947
void add_keys_and_lengths_rowid_intersection(const AccessPath *path, String *key_names, String *used_lengths)
Definition: rowid_ordered_retrieval_plan.cc:912
void dbug_dump_rowid_union(int indent, bool verbose, const Mem_root_array< AccessPath * > &children)
Definition: rowid_ordered_retrieval_plan.cc:972
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:112
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:130
void dbug_dump_rowid_intersection(int indent, bool verbose, const Mem_root_array< AccessPath * > &children)
Definition: rowid_ordered_retrieval_plan.cc:962
#define HA_MRR_SORTED
Definition: handler.h:4014
constexpr const unsigned int MAX_KEY
Definition: sql_const.h:45
Common types of the Optimizer, used by optimization and execution.
#define STRING_WITH_LEN(X)
Definition: string_with_len.h:29
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:227
@ PUSHED_JOIN_REF
Definition: access_path.h:239
@ GROUP_INDEX_SKIP_SCAN
Definition: access_path.h:249
@ INDEX_RANGE_SCAN
Definition: access_path.h:244
@ EQ_REF
Definition: access_path.h:238
@ REF_OR_NULL
Definition: access_path.h:237
@ ROWID_UNION
Definition: access_path.h:247
@ INDEX_SKIP_SCAN
Definition: access_path.h:248
@ MRR
Definition: access_path.h:242
@ INDEX_SCAN
Definition: access_path.h:234
@ REF
Definition: access_path.h:236
@ INDEX_MERGE
Definition: access_path.h:245
@ FULL_TEXT_SEARCH
Definition: access_path.h:240
@ ROWID_INTERSECTION
Definition: access_path.h:246
@ INDEX_DISTANCE_SCAN
Definition: access_path.h:235
Definition: my_bitmap.h:43
Definition: gen_lex_token.cc:149