313
307
uint32_t *bufsize,
314
308
COST_VECT *cost);
316
static TRP_RANGE *get_key_scans_params(optimizer::Parameter *param,
318
bool index_read_must_be_used,
319
bool update_tbl_stats,
323
TRP_ROR_INTERSECT *get_best_ror_intersect(const optimizer::Parameter *param,
326
bool *are_all_covering);
329
TRP_ROR_INTERSECT *get_best_covering_ror_intersect(optimizer::Parameter *param,
334
TABLE_READ_PLAN *get_best_disjunct_quick(optimizer::Parameter *param,
339
TRP_GROUP_MIN_MAX *get_best_group_min_max(optimizer::Parameter *param, SEL_TREE *tree);
310
static optimizer::TRP_RANGE *get_key_scans_params(optimizer::Parameter *param,
312
bool index_read_must_be_used,
313
bool update_tbl_stats,
317
optimizer::TRP_ROR_INTERSECT *get_best_ror_intersect(const optimizer::Parameter *param,
320
bool *are_all_covering);
323
optimizer::TRP_ROR_INTERSECT *get_best_covering_ror_intersect(optimizer::Parameter *param,
328
optimizer::TABLE_READ_PLAN *get_best_disjunct_quick(optimizer::Parameter *param,
333
optimizer::TRP_GROUP_MIN_MAX *get_best_group_min_max(optimizer::Parameter *param, SEL_TREE *tree);
341
335
static void print_sel_tree(optimizer::Parameter *param,
786
Table rows retrieval plan. Range optimizer creates QuickSelectInterface-derived
787
objects from table read plans.
789
class TABLE_READ_PLAN
793
Plan read cost, with or without cost of full row retrieval, depending
794
on plan creation parameters.
797
ha_rows records; /* estimate of #rows to be examined */
800
If true, the scan returns rows in rowid order. This is used only for
801
scans that can be both ROR and non-ROR.
806
Create quick select for this plan.
809
param Parameter from test_quick_select
810
retrieve_full_rows If true, created quick select will do full record
812
parent_alloc Memory pool to use, if any.
815
retrieve_full_rows is ignored by some implementations.
821
virtual optimizer::QuickSelectInterface *make_quick(optimizer::Parameter *param,
822
bool retrieve_full_rows,
823
MEM_ROOT *parent_alloc=NULL) = 0;
825
/* Table read plans are allocated on MEM_ROOT and are never deleted */
826
static void *operator new(size_t size, MEM_ROOT *mem_root)
827
{ return (void*) alloc_root(mem_root, (uint32_t) size); }
828
static void operator delete(void *, size_t)
829
{ TRASH(ptr, size); }
830
static void operator delete(void *, MEM_ROOT *)
831
{ /* Never called */ }
832
virtual ~TABLE_READ_PLAN() {} /* Remove gcc warning */
836
class TRP_ROR_INTERSECT;
838
class TRP_INDEX_MERGE;
842
Plan for a QuickRangeSelect scan.
843
TRP_RANGE::make_quick ignores retrieve_full_rows parameter because
844
QuickRangeSelect doesn't distinguish between 'index only' scans and full
845
record retrieval scans.
848
class TRP_RANGE : public TABLE_READ_PLAN
851
optimizer::SEL_ARG *key; /* set of intervals to be used in "range" method retrieval */
852
uint32_t key_idx; /* key number in Parameter::key */
854
uint32_t mrr_buf_size;
856
TRP_RANGE(optimizer::SEL_ARG *key_arg, uint32_t idx_arg, uint32_t mrr_flags_arg)
860
mrr_flags(mrr_flags_arg)
862
virtual ~TRP_RANGE() {} /* Remove gcc warning */
864
optimizer::QuickSelectInterface *make_quick(optimizer::Parameter *param, bool, MEM_ROOT *parent_alloc)
866
optimizer::QuickRangeSelect *quick= NULL;
867
if ((quick= optimizer::get_quick_select(param,
874
quick->records= records;
875
quick->read_time= read_cost;
882
/* Plan for QuickRorIntersectSelect scan. */
884
class TRP_ROR_INTERSECT : public TABLE_READ_PLAN
887
TRP_ROR_INTERSECT() {} /* Remove gcc warning */
888
virtual ~TRP_ROR_INTERSECT() {} /* Remove gcc warning */
889
optimizer::QuickSelectInterface *make_quick(optimizer::Parameter *param,
890
bool retrieve_full_rows,
891
MEM_ROOT *parent_alloc);
893
/* Array of pointers to ROR range scans used in this intersection */
894
struct st_ror_scan_info **first_scan;
895
struct st_ror_scan_info **last_scan; /* End of the above array */
896
struct st_ror_scan_info *cpk_scan; /* Clustered PK scan, if there is one */
897
bool is_covering; /* true if no row retrieval phase is necessary */
898
double index_scan_costs; /* SUM(cost(index_scan)) */
903
Plan for QuickRorUnionSelect scan.
904
QuickRorUnionSelect always retrieves full rows, so retrieve_full_rows
905
is ignored by make_quick.
908
class TRP_ROR_UNION : public TABLE_READ_PLAN
911
TRP_ROR_UNION() {} /* Remove gcc warning */
912
virtual ~TRP_ROR_UNION() {} /* Remove gcc warning */
913
optimizer::QuickSelectInterface *make_quick(optimizer::Parameter *param,
914
bool retrieve_full_rows,
915
MEM_ROOT *parent_alloc);
916
TABLE_READ_PLAN **first_ror; /* array of ptrs to plans for merged scans */
917
TABLE_READ_PLAN **last_ror; /* end of the above array */
922
Plan for QuickIndexMergeSelect scan.
923
QuickRorIntersectSelect always retrieves full rows, so retrieve_full_rows
924
is ignored by make_quick.
927
class TRP_INDEX_MERGE : public TABLE_READ_PLAN
930
TRP_INDEX_MERGE() {} /* Remove gcc warning */
931
virtual ~TRP_INDEX_MERGE() {} /* Remove gcc warning */
932
optimizer::QuickSelectInterface *make_quick(optimizer::Parameter *param,
933
bool retrieve_full_rows,
934
MEM_ROOT *parent_alloc);
935
TRP_RANGE **range_scans; /* array of ptrs to plans of merged scans */
936
TRP_RANGE **range_scans_end; /* end of the array */
941
Plan for a QuickGroupMinMaxSelect scan.
944
class TRP_GROUP_MIN_MAX : public TABLE_READ_PLAN
947
bool have_min, have_max;
948
KEY_PART_INFO *min_max_arg_part;
949
uint32_t group_prefix_len;
950
uint32_t used_key_parts;
951
uint32_t group_key_parts;
954
uint32_t key_infix_len;
955
unsigned char key_infix[MAX_KEY_LENGTH];
956
SEL_TREE *range_tree; /* Represents all range predicates in the query. */
957
optimizer::SEL_ARG *index_tree; /* The SEL_ARG sub-tree corresponding to index_info. */
958
uint32_t param_idx; /* Index of used key in param->key. */
959
/* Number of records selected by the ranges in index_tree. */
961
ha_rows quick_prefix_records;
963
TRP_GROUP_MIN_MAX(bool have_min_arg, bool have_max_arg,
964
KEY_PART_INFO *min_max_arg_part_arg,
965
uint32_t group_prefix_len_arg, uint32_t used_key_parts_arg,
966
uint32_t group_key_parts_arg, KEY *index_info_arg,
967
uint32_t index_arg, uint32_t key_infix_len_arg,
968
unsigned char *key_infix_arg,
969
SEL_TREE *tree_arg, optimizer::SEL_ARG *index_tree_arg,
970
uint32_t param_idx_arg, ha_rows quick_prefix_records_arg)
972
have_min(have_min_arg),
973
have_max(have_max_arg),
974
min_max_arg_part(min_max_arg_part_arg),
975
group_prefix_len(group_prefix_len_arg),
976
used_key_parts(used_key_parts_arg),
977
group_key_parts(group_key_parts_arg),
978
index_info(index_info_arg),
980
key_infix_len(key_infix_len_arg),
981
range_tree(tree_arg),
982
index_tree(index_tree_arg),
983
param_idx(param_idx_arg),
984
quick_prefix_records(quick_prefix_records_arg)
987
memcpy(this->key_infix, key_infix_arg, key_infix_len);
989
virtual ~TRP_GROUP_MIN_MAX() {} /* Remove gcc warning */
991
optimizer::QuickSelectInterface *make_quick(optimizer::Parameter *param,
992
bool retrieve_full_rows,
993
MEM_ROOT *parent_alloc);
998
781
Fill param->needed_fields with bitmap of fields used in the query.