24#ifndef SQL_RANGE_OPTIMIZER_TREE_H_
25#define SQL_RANGE_OPTIMIZER_TREE_H_
128 uint last_part,
bool start_key);
132 uint last_part,
bool start_key);
576 if (
part != arg->
part)
return false;
598 uchar *new_min, *new_max;
599 uint8 flag_min, flag_max;
691 memset(*min_key + 1, 0,
length - 1);
705 memset(*max_key + 1, 0,
length - 1);
758 uint *cur_min_flag,
uchar **cur_max_key,
759 uint *cur_max_flag,
int *min_part,
832 if (*min_val != *max_val)
return false;
834 if (*min_val)
return true;
992 assert(
keys[index]->use_count > 0);
993 --
keys[index]->use_count;
995 keys[index] =
nullptr;
1009 if (
key) ++
key->use_count;
1074 while (idx < param->
keys) {
1078 return (range_tree->
keys[idx]);
Definition: sql_bitmap.h:154
Used to store optimizer cost estimates.
Definition: handler.h:3877
bool is_nullable() const
Definition: field.h:1302
virtual int key_cmp(const uchar *a, const uchar *b) const
Definition: field.h:1207
Definition: sql_list.h:494
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
Definition: range_opt_param.h:29
uint * real_keynr
Definition: range_opt_param.h:69
void set_next_key_part(SEL_ROOT *next_key_part_arg)
Convenience function for changing next_key_part, including updating the use_count.
Definition: tree.h:549
SEL_ARG * first()
This gives the first SEL_ARG in the interval list, and the minimal element in the red-black tree.
Definition: tree.cc:386
void copy_max_to_min(SEL_ARG *arg)
Definition: tree.h:664
bool copy_min(SEL_ARG *arg)
Definition: tree.h:635
SEL_ARG * last()
Definition: tree.cc:397
SEL_ARG * rb_insert(SEL_ARG *leaf)
Definition: tree.cc:1886
void set_gis_index_read_function(const enum ha_rkey_function rkey_func)
Set spatial index range scan parameters.
Definition: tree.h:676
bool is_same(const SEL_ARG *arg) const
returns true if a range predicate is equal.
Definition: tree.h:575
bool maybe_flag
maybe_flag signals that this range is AND-ed with some unknown range (a MAYBE_KEY node).
Definition: tree.h:485
SEL_ROOT * release_next_key_part()
Convenience function for removing the next_key_part.
Definition: tree.h:533
enum ha_rkey_function rkey_func_flag
The rtree index interval to scan, undefined unless SEL_ARG::min_flag == GEOM_FLAG.
Definition: tree.h:499
bool is_ascending
true - ASC order, false - DESC
Definition: tree.h:557
SEL_ARG * clone(RANGE_OPT_PARAM *param, SEL_ARG *new_parent, SEL_ARG **next)
Definition: tree.cc:345
void copy_min_to_min(SEL_ARG *arg)
Definition: tree.h:656
SEL_ROOT * next_key_part
Definition: tree.h:523
uchar * min_value
Definition: tree.h:509
void copy_min_to_max(SEL_ARG *arg)
Definition: tree.h:660
uint8 part
Definition: tree.h:491
Field * field
Definition: tree.h:508
SEL_ARG * prev
Definition: tree.h:517
void make_root()
Definition: tree.h:795
SEL_ARG * clone_and(SEL_ARG *arg, MEM_ROOT *mem_root)
Definition: tree.h:596
int store_min_value(uint length, uchar **min_key, uint min_key_flag)
Definition: tree.h:684
uint get_min_flag()
Return correct min_flag.
Definition: tree.h:847
bool maybe_null() const
Definition: tree.h:493
SEL_ARG * parent
Definition: tree.h:518
leaf_color
Definition: tree.h:555
@ RED
Definition: tree.h:555
@ BLACK
Definition: tree.h:555
bool is_null_interval()
Definition: tree.h:583
int cmp_max_to_max(const SEL_ARG *arg) const
Definition: tree.h:590
uchar * max_value
Definition: tree.h:509
void maybe_smaller()
Definition: tree.h:581
SEL_ARG * right
Definition: tree.h:516
~SEL_ARG()
Note that almost all SEL_ARGs are created on the MEM_ROOT, so this destructor will only rarely be cal...
Definition: tree.h:569
void store_min_max_values(uint length, uchar **min_key, uint min_flag, uchar **max_key, uint max_flag, int *min_part, int *max_part)
Helper function for storing min/max values of SEL_ARG taking into account key part's order.
Definition: tree.h:733
enum SEL_ARG::leaf_color color
int store_max_value(uint length, uchar **max_key, uint max_key_flag)
Definition: tree.h:700
uint8 max_flag
Definition: tree.h:467
SEL_ARG * left
Definition: tree.h:516
void store_next_min_max_keys(KEY_PART *key, uchar **cur_min_key, uint *cur_min_flag, uchar **cur_max_key, uint *cur_max_flag, int *min_part, int *max_part)
Helper function for storing min/max keys of next SEL_ARG taking into account key part's order.
Definition: tree.h:757
SEL_ARG * next
Definition: tree.h:517
int cmp_max_to_min(const SEL_ARG *arg) const
Definition: tree.h:593
int cmp_min_to_max(const SEL_ARG *arg) const
Definition: tree.h:587
bool copy_max(SEL_ARG *arg)
Definition: tree.h:645
uint get_max_flag()
Return correct max_flag.
Definition: tree.h:857
uint8 min_flag
Definition: tree.h:467
bool is_singlepoint() const
Definition: tree.h:821
void merge_flags(SEL_ARG *arg)
Definition: tree.h:580
SEL_ARG ** parent_ptr()
Definition: tree.h:801
SEL_ARG * clone_last(SEL_ARG *arg, MEM_ROOT *mem_root)
Definition: tree.h:626
friend int test_rb_tree(SEL_ARG *element, SEL_ARG *parent)
Definition: tree.cc:2007
friend SEL_ARG * rb_delete_fixup(SEL_ARG *root, SEL_ARG *key, SEL_ARG *par)
Definition: tree.cc:1939
SEL_ARG * clone_first(SEL_ARG *arg, MEM_ROOT *mem_root)
Definition: tree.h:619
int cmp_min_to_min(const SEL_ARG *arg) const
Definition: tree.h:584
A graph of (possible multiple) key ranges, represented as a red-black binary tree.
Definition: tree.h:68
Type
Used to indicate if the range predicate for an index is always true/false, depends on values from oth...
Definition: tree.h:75
@ KEY_RANGE
There is a range condition that can be used on this index.
@ MAYBE_KEY
There is a range predicate that refers to another table.
@ IMPOSSIBLE
The range predicate for this index is always false.
uint16 elements
Number of nodes in the RB-tree, not including sentinels.
Definition: tree.h:218
bool test_use_count(const SEL_ROOT *root) const
Check if SEL_ROOT::use_count value is correct.
Definition: tree.cc:2102
SEL_ROOT(SEL_ARG *root)
Constructs a tree of type KEY_RANGE, using the given root.
Definition: tree.cc:460
~SEL_ROOT()
Note that almost all SEL_ROOTs are created on the MEM_ROOT, so this destructor will only rarely be ca...
Definition: tree.h:110
int store_min_key(KEY_PART *key, uchar **range_key, uint *range_key_flag, uint last_part, bool start_key)
Returns a number of keypart values appended to the key buffer for min key and max key.
Definition: tree.cc:87
SEL_ROOT * clone_tree(RANGE_OPT_PARAM *param) const
Create a new tree that's a duplicate of this one.
Definition: tree.cc:475
SEL_ARG * find_range(const SEL_ARG *key) const
Find best key with min <= given key.
Definition: tree.cc:1767
void free_tree()
Signal to the tree that the caller will shortly be dropping it on the floor; if others are still usin...
Definition: tree.cc:151
SEL_ARG * root
The root node of the tree.
Definition: tree.h:203
bool simple_key() const
Returns true iff this is a single-element, single-field predicate.
Definition: tree.h:867
void insert(SEL_ARG *key)
Insert the given node into the tree, and update the root.
Definition: tree.cc:1717
bool is_always() const
Returns true iff we have a single node that has no max nor min.
Definition: tree.h:862
void tree_delete(SEL_ARG *key)
Delete the given node from the tree, and update the root.
Definition: tree.cc:1794
int store_max_key(KEY_PART *key, uchar **range_key, uint *range_key_flag, uint last_part, bool start_key)
Definition: tree.cc:124
ulong use_count
Number of references to this SEL_ARG tree.
Definition: tree.h:213
Key_map keys_map
Definition: tree.h:962
uint n_ror_scans
Definition: tree.h:978
bool inexact
Whether this SEL_TREE is an inexact (too broad) representation of the predicates it is based on; that...
Definition: tree.h:920
List< SEL_IMERGE > merges
Definition: tree.h:974
SEL_TREE(MEM_ROOT *root, size_t num_keys)
Definition: tree.h:924
SEL_ROOT * release_key(int index)
Convenience function for removing an element in keys[].
Definition: tree.h:989
Key_map ror_scans_map
Definition: tree.h:977
Type
Starting an effort to document this field:
Definition: tree.h:889
@ IMPOSSIBLE
Definition: tree.h:889
@ ALWAYS
Definition: tree.h:889
void set_key(int index, SEL_ROOT *key)
Convenience function for changing an element in keys[], including updating the use_count.
Definition: tree.h:1006
SEL_TREE(enum Type type_arg, MEM_ROOT *root, size_t num_keys)
Definition: tree.h:922
Mem_root_array< SEL_ROOT * > keys
Definition: tree.h:961
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
static uint16 key1[1001]
Definition: hp_test2.cc:50
static uint keys
Definition: hp_test2.cc:49
void print_tree(String *out, const char *tree_name, SEL_TREE *tree, const RANGE_OPT_PARAM *param, const bool print_full)
Definition: range_optimizer.cc:1691
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
This file includes constants used by all storage engines.
ha_rkey_function
Definition: my_base.h:78
@ HA_READ_MBR_EQUAL
Definition: my_base.h:91
@ HA_READ_INVALID
Definition: my_base.h:93
@ HA_READ_MBR_CONTAIN
Definition: my_base.h:87
@ NEAR_MIN
Definition: my_base.h:1083
@ NO_MIN_RANGE
from -inf
Definition: my_base.h:1080
@ NO_MAX_RANGE
to +inf
Definition: my_base.h:1081
@ NEAR_MAX
Definition: my_base.h:1085
@ GEOM_FLAG
This flag means that the index is an rtree index, and the interval is specified using HA_READ_MBR_XXX...
Definition: my_base.h:1107
int _db_enabled_()
Definition: dbug.cc:1279
Some integer typedefs for easier portability.
uint8_t uint8
Definition: my_inttypes.h:63
unsigned char uchar
Definition: my_inttypes.h:52
uint16_t uint16
Definition: my_inttypes.h:65
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
SEL_ARG * null_element
Definition: range_optimizer.cc:157
required string key
Definition: replication_asynchronous_connection_failover.proto:60
File containing constants that can be used throughout the server.
constexpr const unsigned int MAX_KEY
Definition: sql_const.h:45
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: rowid_ordered_retrieval_plan.h:44
void dbug_print_tree(const char *tree_name, SEL_TREE *tree, const RANGE_OPT_PARAM *param)
Print the ranges in a SEL_TREE to debug log.
Definition: tree.h:1088
SEL_ROOT * key_and(RANGE_OPT_PARAM *param, SEL_ROOT *key1, SEL_ROOT *key2)
Definition: tree.cc:886
bool sel_trees_can_be_ored(SEL_TREE *tree1, SEL_TREE *tree2, RANGE_OPT_PARAM *param)
Definition: tree.cc:591
SEL_ROOT * get_index_range_tree(uint index, SEL_TREE *range_tree, RANGE_OPT_PARAM *param)
Definition: tree.h:1071
void print_sel_tree(RANGE_OPT_PARAM *param, SEL_TREE *tree, Key_map *tree_map, const char *msg)
Definition: tree.cc:2177
uint invert_min_flag(uint min_flag)
A helper function to invert min flags to max flags for DESC key parts.
Definition: tree.h:228
SEL_ROOT * key_or(RANGE_OPT_PARAM *param, SEL_ROOT *key1, SEL_ROOT *key2)
Combine two range expression under a common OR.
Definition: tree.cc:1079
SEL_TREE * tree_or(RANGE_OPT_PARAM *param, bool remove_jump_scans, SEL_TREE *tree1, SEL_TREE *tree2)
Definition: tree.cc:683
uint invert_max_flag(uint max_flag)
A helper function to invert max flags to min flags for DESC key parts.
Definition: tree.h:240
int sel_cmp(Field *f, uchar *a, uchar *b, uint8 a_flag, uint8 b_flag)
Definition: tree.cc:409
bool get_sel_root_for_keypart(uint key_part_num, SEL_ROOT *keypart_tree, SEL_ROOT **cur_range)
Definition: tree.cc:2136
SEL_TREE * tree_and(RANGE_OPT_PARAM *param, SEL_TREE *tree1, SEL_TREE *tree2)
Definition: tree.cc:502