23#ifndef SQL_RANGE_OPTIMIZER_PATH_HELPERS_H_
24#define SQL_RANGE_OPTIMIZER_PATH_HELPERS_H_
48 return path->index_skip_scan().param->has_aggregate_function;
51 return path->group_index_skip_scan().param->have_agg_distinct;
72 path->index_range_scan().reverse;
81 if (
path->index_range_scan().geometry) {
84 path->index_range_scan().reverse =
true;
85 TABLE *
table =
path->index_range_scan().used_key_part[0].field->table;
86 path->index_range_scan().using_extended_key_parts =
87 (used_key_parts >
table->key_info[
path->index_range_scan().index]
88 .user_defined_key_parts);
114 switch (
path->type) {
116 return path->index_range_scan().index;
118 return path->index_skip_scan().index;
120 return path->group_index_skip_scan().index;
133 if (
path->index_range_scan().num_ranges == 1) {
137 path->index_range_scan().used_key_part[0].field->table->key_info +
138 path->index_range_scan().index;
146 switch (
path->type) {
148 for (uint i = 0; i <
path->index_range_scan().num_used_key_parts; ++i) {
151 path->index_range_scan().used_key_part[i].field->field_index());
163 if (
path->rowid_intersection().cpk_child !=
nullptr) {
173 for (uint i = 0; i <
path->index_skip_scan().num_used_key_parts; ++i) {
175 .param->index_info->key_part[i]
176 .field->field_index());
180 for (uint i = 0; i <
path->group_index_skip_scan().num_used_key_parts;
183 .param->index_info->key_part[i]
184 .field->field_index());
193 switch (
path->type) {
195 return path->index_range_scan().num_used_key_parts;
197 return path->index_skip_scan().num_used_key_parts;
199 return path->group_index_skip_scan().num_used_key_parts;
216 switch (
path->type) {
218 return is_key_used(
path->index_range_scan().used_key_part[0].field->table,
219 path->index_range_scan().index, fields);
233 return path->rowid_intersection().cpk_child !=
nullptr &&
244 path->index_skip_scan().index, fields);
247 path->group_index_skip_scan().index, fields);
260 switch (
path->type) {
262 int max_used_key_length = 0;
264 path->index_range_scan().num_ranges};
266 max_used_key_length =
267 std::max<int>(max_used_key_length,
range->min_length);
268 max_used_key_length =
269 std::max<int>(max_used_key_length,
range->max_length);
271 return max_used_key_length;
274 int max_used_key_length = 0;
276 for (uint i = 0; i <
path->index_skip_scan().num_used_key_parts;
278 max_used_key_length +=
p->store_length;
280 return max_used_key_length;
283 return path->group_index_skip_scan().param->max_used_key_length;
295 switch (
path->type) {
297 TABLE *
table =
path->index_range_scan().used_key_part[0].field->table;
298 KEY *key_info =
table->key_info +
path->index_range_scan().index;
309 for (
bool print_primary : {
false,
true}) {
311 const bool is_primary =
table->file->primary_key_is_clustered() &&
313 if (is_primary != print_primary)
continue;
327 for (
AccessPath *current : *
path->rowid_intersection().children) {
334 if (
path->rowid_intersection().cpk_child) {
356 str->append(
path->index_skip_scan().param->index_info->name);
362 str->append(
path->group_index_skip_scan().param->index_info->name);
380 switch (
path->type) {
382 TABLE *
table =
path->index_range_scan().used_key_part[0].field->table;
383 KEY *key_info =
table->key_info +
path->index_range_scan().index;
402 key_names->
append(
path->index_skip_scan().param->index_info->name);
412 key_names->
append(
path->group_index_skip_scan().param->index_info->name);
438 switch (
path->type) {
463 switch (
path->type) {
467 return path->index_merge().forced_by_hint;
469 return path->rowid_intersection().forced_by_hint;
471 return path->rowid_union().forced_by_hint;
473 return path->index_skip_scan().forced_by_hint;
475 return path->group_index_skip_scan().forced_by_hint;
488 switch (
path->type) {
490 const auto ¶m =
path->index_range_scan();
492 param.index, param.used_key_part,
493 {param.ranges, param.num_ranges});
502 *
path->index_merge().children);
A wrapper class which provides array bounds checking.
Definition: sql_array.h:46
const char * name
Name of key.
Definition: key.h:152
A JSON object (unordered set of key/value pairs).
Definition: opt_trace.h:798
Definition: range_optimizer.h:68
uint16 flag
Stores bitwise-or'ed bits defined in enum key_range_flags.
Definition: range_optimizer.h:74
uint16 min_length
Definition: range_optimizer.h:71
Definition: range_opt_param.h:28
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:166
bool append(const String &s)
Definition: sql_string.cc:418
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
static char buf[MAX_BUF]
Definition: conf_to_src.cc:72
const char * p
Definition: ctype-mb.cc:1234
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:77
void dbug_dump_group_index_skip_scan(int indent, bool, const AccessPath *path)
Definition: group_index_skip_scan_plan.cc:1684
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:33
void add_keys_and_lengths_index_merge(const AccessPath *path, String *key_names, String *used_lengths)
Definition: index_merge_plan.cc:45
void dbug_dump_index_merge(int indent, bool verbose, const Mem_root_array< AccessPath * > &children)
Definition: index_merge_plan.cc:70
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:793
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:1311
void dbug_dump_index_skip_scan(int indent, bool verbose, const AccessPath *path)
Definition: index_skip_scan_plan.cc:799
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:69
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:97
bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields)
Definition: key.cc:410
@ EQ_RANGE
Definition: my_base.h:1095
@ NULL_RANGE
Definition: my_base.h:1100
#define HA_NOSAME
Do not allow duplicate records.
Definition: my_base.h:473
static void bitmap_set_bit(MY_BITMAP *map, uint bit)
Definition: my_bitmap.h:79
static uint verbose
Definition: mysqlcheck.cc:65
static char * path
Definition: mysqldump.cc:140
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1063
static PFS_engine_table_share_proxy table
Definition: pfs.cc:60
Definition: buf0block_hint.cc:29
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:75
void add_info_string(const AccessPath *path, String *str)
Definition: path_helpers.h:294
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:129
bool is_loose_index_scan(const AccessPath *path)
Definition: path_helpers.h:40
void add_keys_and_lengths(const AccessPath *path, String *key_names, String *used_lengths)
Definition: path_helpers.h:378
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:113
bool get_forced_by_hint(const AccessPath *path)
Definition: path_helpers.h:462
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:259
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:214
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:435
bool is_agg_loose_index_scan(const AccessPath *path)
Definition: path_helpers.h:45
void set_need_sorted_output(AccessPath *path)
Definition: path_helpers.h:95
unsigned get_used_key_parts(const AccessPath *path)
Definition: path_helpers.h:192
bool make_reverse(uint used_key_parts, AccessPath *path)
Ask the AccessPath to reverse itself; returns false if successful.
Definition: path_helpers.h:79
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:70
void get_fields_used(const AccessPath *path, MY_BITMAP *used_fields)
Definition: path_helpers.h:145
void dbug_dump(const AccessPath *path, int indent, bool verbose)
Definition: path_helpers.h:487
bool reverse_sort_possible(const AccessPath *path)
Whether the range access method is capable of returning records in reverse order.
Definition: path_helpers.h:62
required string key
Definition: replication_asynchronous_connection_failover.proto:59
void add_keys_and_lengths_rowid_union(const AccessPath *path, String *key_names, String *used_lengths)
Definition: rowid_ordered_retrieval_plan.cc:945
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
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
#define HA_MRR_SORTED
Definition: handler.h:3889
constexpr const unsigned int MAX_KEY
Definition: sql_const.h:45
#define STRING_WITH_LEN(X)
Definition: string_with_len.h:28
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:42
Definition: gen_lex_token.cc:148