24#ifndef SQL_RANGE_OPTIMIZER_TREE_H_ 
   25#define SQL_RANGE_OPTIMIZER_TREE_H_ 
  129                    uint last_part, 
bool start_key);
 
  133                    uint last_part, 
bool start_key);
 
  577    if (
part != arg->
part) 
return false;
 
  599    uchar *new_min, *new_max;
 
  600    uint8 flag_min, flag_max;
 
  692        memset(*min_key + 1, 0, 
length - 1);
 
  706        memset(*max_key + 1, 0, 
length - 1);
 
  760                               uint *cur_max_flag, 
int *min_part,
 
  833      if (*min_val != *max_val) 
return false;
 
  835      if (*min_val) 
return true; 
 
  997      assert(
keys[index]->use_count > 0);
 
  998      --
keys[index]->use_count;
 
 1000    keys[index] = 
nullptr;
 
 1014    if (
key) ++
key->use_count;
 
 1079  while (idx < param->
keys) {
 
 1083  return (range_tree->
keys[idx]);
 
Definition: sql_bitmap.h:138
 
Used to store optimizer cost estimates.
Definition: handler.h:3706
 
bool is_nullable() const
Definition: field.h:1297
 
virtual int key_cmp(const uchar *a, const uchar *b) const
Definition: field.h:1202
 
Definition: sql_list.h:434
 
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:550
 
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:387
 
void copy_max_to_min(SEL_ARG *arg)
Definition: tree.h:665
 
bool copy_min(SEL_ARG *arg)
Definition: tree.h:636
 
SEL_ARG * last()
Definition: tree.cc:398
 
SEL_ARG * rb_insert(SEL_ARG *leaf)
Definition: tree.cc:1883
 
void set_gis_index_read_function(const enum ha_rkey_function rkey_func)
Set spatial index range scan parameters.
Definition: tree.h:677
 
bool is_same(const SEL_ARG *arg) const
returns true if a range predicate is equal.
Definition: tree.h:576
 
bool maybe_flag
maybe_flag signals that this range is AND-ed with some unknown range (a MAYBE_KEY node).
Definition: tree.h:486
 
SEL_ROOT * release_next_key_part()
Convenience function for removing the next_key_part.
Definition: tree.h:534
 
enum ha_rkey_function rkey_func_flag
The rtree index interval to scan, undefined unless SEL_ARG::min_flag == GEOM_FLAG.
Definition: tree.h:500
 
bool is_ascending
true - ASC order, false - DESC
Definition: tree.h:558
 
SEL_ARG * clone(RANGE_OPT_PARAM *param, SEL_ARG *new_parent, SEL_ARG **next)
Definition: tree.cc:346
 
void copy_min_to_min(SEL_ARG *arg)
Definition: tree.h:657
 
SEL_ROOT * next_key_part
Definition: tree.h:524
 
uchar * min_value
Definition: tree.h:510
 
void copy_min_to_max(SEL_ARG *arg)
Definition: tree.h:661
 
uint8 part
Definition: tree.h:492
 
Field * field
Definition: tree.h:509
 
SEL_ARG * prev
Definition: tree.h:518
 
void make_root()
Definition: tree.h:796
 
SEL_ARG * clone_and(SEL_ARG *arg, MEM_ROOT *mem_root)
Definition: tree.h:597
 
int store_min_value(uint length, uchar **min_key, uint min_key_flag)
Definition: tree.h:685
 
uint get_min_flag()
Return correct min_flag.
Definition: tree.h:848
 
bool maybe_null() const
Definition: tree.h:494
 
SEL_ARG * parent
Definition: tree.h:519
 
leaf_color
Definition: tree.h:556
 
@ RED
Definition: tree.h:556
 
@ BLACK
Definition: tree.h:556
 
bool is_null_interval()
Definition: tree.h:584
 
int cmp_max_to_max(const SEL_ARG *arg) const
Definition: tree.h:591
 
uchar * max_value
Definition: tree.h:510
 
void maybe_smaller()
Definition: tree.h:582
 
SEL_ARG * right
Definition: tree.h:517
 
~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:570
 
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:734
 
enum SEL_ARG::leaf_color color
 
int store_max_value(uint length, uchar **max_key, uint max_key_flag)
Definition: tree.h:701
 
uint8 max_flag
Definition: tree.h:468
 
SEL_ARG * left
Definition: tree.h:517
 
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:758
 
SEL_ARG * next
Definition: tree.h:518
 
int cmp_max_to_min(const SEL_ARG *arg) const
Definition: tree.h:594
 
int cmp_min_to_max(const SEL_ARG *arg) const
Definition: tree.h:588
 
bool copy_max(SEL_ARG *arg)
Definition: tree.h:646
 
uint get_max_flag()
Return correct max_flag.
Definition: tree.h:858
 
uint8 min_flag
Definition: tree.h:468
 
bool is_singlepoint() const
Definition: tree.h:822
 
void merge_flags(SEL_ARG *arg)
Definition: tree.h:581
 
SEL_ARG ** parent_ptr()
Definition: tree.h:802
 
SEL_ARG * clone_last(SEL_ARG *arg, MEM_ROOT *mem_root)
Definition: tree.h:627
 
friend int test_rb_tree(SEL_ARG *element, SEL_ARG *parent)
Definition: tree.cc:2004
 
friend SEL_ARG * rb_delete_fixup(SEL_ARG *root, SEL_ARG *key, SEL_ARG *par)
Definition: tree.cc:1936
 
SEL_ARG * clone_first(SEL_ARG *arg, MEM_ROOT *mem_root)
Definition: tree.h:620
 
int cmp_min_to_min(const SEL_ARG *arg) const
Definition: tree.h:585
 
A graph of (possible multiple) key ranges, represented as a red-black binary tree.
Definition: tree.h:69
 
size_t elements
Number of nodes in the RB-tree, not including sentinels.
Definition: tree.h:219
 
Type
Used to indicate if the range predicate for an index is always true/false, depends on values from oth...
Definition: tree.h:76
 
@ 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.
 
bool test_use_count(const SEL_ROOT *root) const
Check if SEL_ROOT::use_count value is correct.
Definition: tree.cc:2099
 
SEL_ROOT(SEL_ARG *root)
Constructs a tree of type KEY_RANGE, using the given root.
Definition: tree.cc:461
 
~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:111
 
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:88
 
SEL_ROOT * clone_tree(RANGE_OPT_PARAM *param) const
Create a new tree that's a duplicate of this one.
Definition: tree.cc:476
 
SEL_ARG * find_range(const SEL_ARG *key) const
Find best key with min <= given key.
Definition: tree.cc:1764
 
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:152
 
SEL_ARG * root
The root node of the tree.
Definition: tree.h:204
 
bool simple_key() const
Returns true iff this is a single-element, single-field predicate.
Definition: tree.h:868
 
void insert(SEL_ARG *key)
Insert the given node into the tree, and update the root.
Definition: tree.cc:1714
 
bool is_always() const
Returns true iff we have a single node that has no max nor min.
Definition: tree.h:863
 
void tree_delete(SEL_ARG *key)
Delete the given node from the tree, and update the root.
Definition: tree.cc:1791
 
int store_max_key(KEY_PART *key, uchar **range_key, uint *range_key_flag, uint last_part, bool start_key)
Definition: tree.cc:125
 
ulong use_count
Number of references to this SEL_ARG tree.
Definition: tree.h:214
 
Key_map keys_map
Definition: tree.h:963
 
ROR_SCAN_INFO ** ror_scans
Definition: tree.h:981
 
uint n_ror_scans
Definition: tree.h:979
 
bool inexact
Whether this SEL_TREE is an inexact (too broad) representation of the predicates it is based on; that...
Definition: tree.h:921
 
List< SEL_IMERGE > merges
Definition: tree.h:975
 
SEL_TREE(MEM_ROOT *root, size_t num_keys)
Definition: tree.h:925
 
SEL_ROOT * release_key(int index)
Convenience function for removing an element in keys[].
Definition: tree.h:994
 
Key_map ror_scans_map
Definition: tree.h:978
 
Type
Starting an effort to document this field:
Definition: tree.h:890
 
@ IMPOSSIBLE
Definition: tree.h:890
 
@ ALWAYS
Definition: tree.h:890
 
void set_key(int index, SEL_ROOT *key)
Convenience function for changing an element in keys[], including updating the use_count.
Definition: tree.h:1011
 
ROR_SCAN_INFO ** ror_scans_end
Definition: tree.h:982
 
SEL_TREE(enum Type type_arg, MEM_ROOT *root, size_t num_keys)
Definition: tree.h:923
 
Mem_root_array< SEL_ROOT * > keys
Definition: tree.h:962
 
static MEM_ROOT mem_root
Definition: client_plugin.cc:110
 
static uint16 key1[1001]
Definition: hp_test2.cc:47
 
static uint keys
Definition: hp_test2.cc:46
 
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:1740
 
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:92
 
@ HA_READ_MBR_CONTAIN
Definition: my_base.h:87
 
@ NEAR_MIN
Definition: my_base.h:1082
 
@ NO_MIN_RANGE
from -inf
Definition: my_base.h:1079
 
@ NO_MAX_RANGE
to +inf
Definition: my_base.h:1080
 
@ NEAR_MAX
Definition: my_base.h:1084
 
@ 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:1106
 
int _db_enabled_()
Definition: dbug.cc:1276
 
Some integer typedefs for easier portability.
 
uint8_t uint8
Definition: my_inttypes.h:63
 
unsigned char uchar
Definition: my_inttypes.h:52
 
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:158
 
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:43
 
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:1093
 
SEL_ROOT * key_and(RANGE_OPT_PARAM *param, SEL_ROOT *key1, SEL_ROOT *key2)
Definition: tree.cc:883
 
bool sel_trees_can_be_ored(SEL_TREE *tree1, SEL_TREE *tree2, RANGE_OPT_PARAM *param)
Definition: tree.cc:588
 
SEL_ROOT * get_index_range_tree(uint index, SEL_TREE *range_tree, RANGE_OPT_PARAM *param)
Definition: tree.h:1076
 
void print_sel_tree(RANGE_OPT_PARAM *param, SEL_TREE *tree, Key_map *tree_map, const char *msg)
Definition: tree.cc:2174
 
uint invert_min_flag(uint min_flag)
A helper function to invert min flags to max flags for DESC key parts.
Definition: tree.h:229
 
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:1076
 
SEL_TREE * tree_or(RANGE_OPT_PARAM *param, bool remove_jump_scans, SEL_TREE *tree1, SEL_TREE *tree2)
Definition: tree.cc:680
 
uint invert_max_flag(uint max_flag)
A helper function to invert max flags to min flags for DESC key parts.
Definition: tree.h:241
 
int sel_cmp(Field *f, uchar *a, uchar *b, uint8 a_flag, uint8 b_flag)
Definition: tree.cc:410
 
bool get_sel_root_for_keypart(uint key_part_num, SEL_ROOT *keypart_tree, SEL_ROOT **cur_range)
Definition: tree.cc:2133
 
SEL_TREE * tree_and(RANGE_OPT_PARAM *param, SEL_TREE *tree1, SEL_TREE *tree2)
Definition: tree.cc:503
 
unsigned int uint
Definition: uca9-dump.cc:75