MySQL 9.1.0
Source Code Documentation
index_range_scan_plan.cc File Reference
#include "sql/range_optimizer/index_range_scan_plan.h"
#include <assert.h>
#include <string.h>
#include <algorithm>
#include <memory>
#include "my_alloc.h"
#include "my_base.h"
#include "my_inttypes.h"
#include "my_sys.h"
#include "mysql/strings/m_ctype.h"
#include "sql/join_optimizer/access_path.h"
#include "sql/key.h"
#include "sql/mem_root_array.h"
#include "sql/opt_hints.h"
#include "sql/opt_trace.h"
#include "sql/opt_trace_context.h"
#include "sql/range_optimizer/geometry_index_range_scan.h"
#include "sql/range_optimizer/index_range_scan.h"
#include "sql/range_optimizer/internal.h"
#include "sql/range_optimizer/range_opt_param.h"
#include "sql/range_optimizer/range_optimizer.h"
#include "sql/range_optimizer/reverse_index_range_scan.h"
#include "sql/range_optimizer/tree.h"
#include "sql/sql_bitmap.h"
#include "sql/sql_class.h"
#include "sql/sql_lex.h"
#include "sql/sql_select.h"
#include "sql/table.h"
#include "sql/thr_malloc.h"
#include "sql_string.h"

Classes

struct  RANGE_SEQ_ENTRY
 
class  Sel_arg_range_sequence
 

Functions

static bool is_key_scan_ror (RANGE_OPT_PARAM *param, uint keynr, uint nparts)
 
static bool eq_ranges_exceeds_limit (const SEL_ROOT *keypart, uint *count, uint limit)
 Traverse the R-B range tree for this and later keyparts to see if there are at least as many equality ranges as defined by the limit. More...
 
static bool get_ranges_from_tree_given_base (THD *thd, MEM_ROOT *return_mem_root, const KEY *table_key, KEY_PART *key, SEL_ROOT *key_tree, uchar *const base_min_key, uchar *min_key, uint min_key_flag, uchar *const base_max_key, uchar *max_key, uint max_key_flag, bool first_keypart_is_asc, uint num_key_parts, uint *used_key_parts, uint *num_exact_key_parts, Quick_ranges *ranges)
 Generate key values for range select from given sel_arg tree. More...
 
static range_seq_t sel_arg_range_seq_init (void *init_param, uint, uint)
 
static uint sel_arg_range_seq_next (range_seq_t rseq, KEY_MULTI_RANGE *range)
 
ha_rows check_quick_select (THD *thd, RANGE_OPT_PARAM *param, uint idx, bool index_only, SEL_ROOT *tree, bool update_tbl_stats, enum_order order_direction, bool skip_records_in_range, uint *mrr_flags, uint *bufsize, Cost_estimate *cost, bool *is_ror_scan, bool *is_imerge_scan)
 
bool get_ranges_from_tree (MEM_ROOT *return_mem_root, TABLE *table, KEY_PART *key, uint keyno, SEL_ROOT *key_tree, uint num_key_parts, unsigned *used_key_parts, unsigned *num_exact_key_parts, Quick_ranges *ranges)
 
void trace_basic_info_index_range_scan (THD *thd, const AccessPath *path, const RANGE_OPT_PARAM *param, Opt_trace_object *trace_object)
 
AccessPathget_key_scans_params (THD *thd, RANGE_OPT_PARAM *param, SEL_TREE *tree, bool index_read_must_be_used, bool update_tbl_stats, enum_order order_direction, bool skip_records_in_range, const double cost_est, bool ror_only, Key_map *needed_reg)
 
static bool null_part_in_key (KEY_PART *key_part, const uchar *key, uint length)
 
static std::basic_string_view< ucharmake_string_view (const uchar *start, const uchar *end)
 
static void print_multiple_key_values (const KEY_PART *key_part, const uchar *key, uint used_length)
 
void dbug_dump_range (int indent, bool verbose, TABLE *table, int index, KEY_PART *used_key_part, Bounds_checked_array< QUICK_RANGE * > ranges)
 

Function Documentation

◆ check_quick_select()

ha_rows check_quick_select ( THD thd,
RANGE_OPT_PARAM param,
uint  idx,
bool  index_only,
SEL_ROOT tree,
bool  update_tbl_stats,
enum_order  order_direction,
bool  skip_records_in_range,
uint *  mrr_flags,
uint *  bufsize,
Cost_estimate cost,
bool *  is_ror_scan,
bool *  is_imerge_scan 
)

◆ dbug_dump_range()

void dbug_dump_range ( int  indent,
bool  verbose,
TABLE table,
int  index,
KEY_PART used_key_part,
Bounds_checked_array< QUICK_RANGE * >  ranges 
)

◆ eq_ranges_exceeds_limit()

static bool eq_ranges_exceeds_limit ( const SEL_ROOT keypart,
uint *  count,
uint  limit 
)
static

Traverse the R-B range tree for this and later keyparts to see if there are at least as many equality ranges as defined by the limit.

Parameters
keypartThe R-B tree of ranges for a given keypart.
[in,out]countThe number of equality ranges found so far
limitThe number of ranges
Return values
trueif limit > 0 and 'limit' or more equality ranges have been found in the range R-B trees
falseotherwise

◆ get_key_scans_params()

AccessPath * get_key_scans_params ( THD thd,
RANGE_OPT_PARAM param,
SEL_TREE tree,
bool  index_read_must_be_used,
bool  update_tbl_stats,
enum_order  order_direction,
bool  skip_records_in_range,
const double  cost_est,
bool  ror_only,
Key_map needed_reg 
)

No cost calculation when index dive is skipped.

◆ get_ranges_from_tree()

bool get_ranges_from_tree ( MEM_ROOT return_mem_root,
TABLE table,
KEY_PART key,
uint  keyno,
SEL_ROOT key_tree,
uint  num_key_parts,
unsigned *  used_key_parts,
unsigned *  num_exact_key_parts,
Quick_ranges ranges 
)

◆ get_ranges_from_tree_given_base()

static bool get_ranges_from_tree_given_base ( THD thd,
MEM_ROOT return_mem_root,
const KEY table_key,
KEY_PART key,
SEL_ROOT key_tree,
uchar *const  base_min_key,
uchar min_key,
uint  min_key_flag,
uchar *const  base_max_key,
uchar max_key,
uint  max_key_flag,
bool  first_keypart_is_asc,
uint  num_key_parts,
uint *  used_key_parts,
uint *  num_exact_key_parts,
Quick_ranges ranges 
)
static

Generate key values for range select from given sel_arg tree.

SYNOPSIS get_ranges_from_tree_given_base()

Parameters
thdTHD object
return_mem_rootMEM_ROOT to use for allocating the data
keyGenerate key values for this key
key_treeSEL_ARG tree
base_min_keyStart of min key buffer
min_keyCurrent append place in min key buffer
min_key_flagMin key's flags
base_max_keyStart of max key buffer
max_keyCurrent append place in max key buffer
max_key_flagMax key's flags
first_keypart_is_ascWhether first keypart is ascending or not
num_key_partsNumber of key parts that should be used for creating ranges
used_key_partsNumber of key parts that were ever used in some form
num_exact_key_partsThe number of key parts for which we were able to apply the ranges fully (never higher than used_key_parts), subsuming conditions touching that key part.
rangesThe ranges to scan
Note
Fix this to get all possible sub_ranges
Returns
true OOM false Ok

◆ is_key_scan_ror()

static bool is_key_scan_ror ( RANGE_OPT_PARAM param,
uint  keynr,
uint  nparts 
)
static

◆ make_string_view()

static std::basic_string_view< uchar > make_string_view ( const uchar start,
const uchar end 
)
inlinestatic

◆ null_part_in_key()

static bool null_part_in_key ( KEY_PART key_part,
const uchar key,
uint  length 
)
static

◆ print_multiple_key_values()

static void print_multiple_key_values ( const KEY_PART key_part,
const uchar key,
uint  used_length 
)
static

◆ sel_arg_range_seq_init()

static range_seq_t sel_arg_range_seq_init ( void *  init_param,
uint  ,
uint   
)
static

◆ sel_arg_range_seq_next()

static uint sel_arg_range_seq_next ( range_seq_t  rseq,
KEY_MULTI_RANGE range 
)
static

◆ trace_basic_info_index_range_scan()

void trace_basic_info_index_range_scan ( THD thd,
const AccessPath path,
const RANGE_OPT_PARAM param,
Opt_trace_object trace_object 
)