22 #include "thr_malloc.h"
30 #include "sql_class.h"
41 uint16 store_length, length;
49 Field::imagetype image_type;
55 uchar *min_key,*max_key;
56 uint16 min_length,max_length,flag;
57 key_part_map min_keypart_map,
61 QUICK_RANGE(
const uchar *min_key_arg, uint min_length_arg,
62 key_part_map min_keypart_map_arg,
63 const uchar *max_key_arg, uint max_length_arg,
64 key_part_map max_keypart_map_arg,
82 key_part_map keypart_map) {
85 kr->length= min(kr->length, prefix_length);
86 kr->keypart_map&= keypart_map;
99 kr->key= (
const uchar*)min_key;
100 kr->length= min_length;
101 kr->keypart_map= min_keypart_map;
102 kr->flag= ((flag & NEAR_MIN) ? HA_READ_AFTER_KEY :
103 (flag & EQ_RANGE) ? HA_READ_KEY_EXACT : HA_READ_KEY_OR_NEXT);
121 key_part_map keypart_map) {
124 kr->length= min(kr->length, prefix_length);
125 kr->keypart_map&= keypart_map;
138 kr->key= (
const uchar*)max_key;
139 kr->length= max_length;
140 kr->keypart_map= max_keypart_map;
145 kr->flag= (flag & NEAR_MAX ? HA_READ_BEFORE_KEY : HA_READ_AFTER_KEY);
213 uint max_used_key_length;
244 virtual int init() = 0;
262 virtual int reset(
void) = 0;
264 virtual int get_next() = 0;
267 virtual void range_end() {}
278 virtual bool unique_key_range() {
return false; }
279 virtual bool clustered_pk_range() {
return false; }
289 virtual void need_sorted_output() = 0;
292 QS_TYPE_INDEX_MERGE = 1,
293 QS_TYPE_RANGE_DESC = 2,
294 QS_TYPE_FULLTEXT = 3,
295 QS_TYPE_ROR_INTERSECT = 4,
296 QS_TYPE_ROR_UNION = 5,
297 QS_TYPE_GROUP_MIN_MAX = 6
301 virtual int get_type() = 0;
316 virtual int init_ror_merged_scan(
bool reuse_handler)
317 { DBUG_ASSERT(0);
return 1; }
322 virtual void save_last_pos(){};
329 virtual void add_keys_and_lengths(
String *key_names,
338 virtual void add_info_string(
String *str) {};
343 virtual bool is_keys_used(
const MY_BITMAP *fields);
350 virtual bool is_valid() {
return index != MAX_KEY; };
367 virtual void dbug_dump(
int indent,
bool verbose)= 0;
373 virtual QUICK_SELECT_I *make_reverse(uint used_key_parts_arg) {
return NULL; }
374 virtual void set_handler(
handler *file_arg) {}
378 struct st_qsel_param;
394 range_seq_t quick_range_seq_init(
void *init_param, uint n_ranges, uint
flags);
407 bool in_ror_merged_scan;
415 friend bool get_quick_keys(
PARAM *param,
418 uchar *min_key, uint min_key_flag,
419 uchar *max_key, uint max_key_flag);
425 friend uint quick_range_seq_next(range_seq_t rseq,
KEY_MULTI_RANGE *range);
426 friend range_seq_t quick_range_seq_init(
void *init_param,
427 uint n_ranges, uint
flags);
456 bool row_in_ranges();
461 MEM_ROOT *parent_alloc,
bool *create_error);
464 void need_sorted_output();
469 int get_next_prefix(uint prefix_length, uint group_key_parts,
473 bool unique_key_range();
474 int init_ror_merged_scan(
bool reuse_handler);
477 int get_type() {
return QS_TYPE_RANGE; }
478 void add_keys_and_lengths(
String *key_names,
String *used_lengths);
479 void add_info_string(
String *str);
481 void dbug_dump(
int indent,
bool verbose);
484 void set_handler(
handler *file_arg) {
file= file_arg; }
494 bool no_alloc,
MEM_ROOT *parent_alloc,
499 virtual int get_next();
570 void need_sorted_output() { DBUG_ASSERT(
false); }
575 bool unique_key_range() {
return false; }
576 int get_type() {
return QS_TYPE_INDEX_MERGE; }
577 void add_keys_and_lengths(
String *key_names,
String *used_lengths);
578 void add_info_string(
String *str);
579 bool is_keys_used(
const MY_BITMAP *fields);
581 void dbug_dump(
int indent,
bool verbose);
597 int read_keys_and_merge();
599 bool clustered_pk_range() {
return test(pk_quick_select); }
606 while ((quick= it++))
644 bool retrieve_full_rows,
649 void need_sorted_output() { DBUG_ASSERT(
false); }
654 bool unique_key_range() {
return false; }
655 int get_type() {
return QS_TYPE_ROR_INTERSECT; }
656 void add_keys_and_lengths(
String *key_names,
String *used_lengths);
657 void add_info_string(
String *str);
658 bool is_keys_used(
const MY_BITMAP *fields);
660 void dbug_dump(
int indent,
bool verbose);
662 int init_ror_merged_scan(
bool reuse_handler);
676 while ((quick= it++))
695 bool need_to_fetch_row;
721 void need_sorted_output() { DBUG_ASSERT(
false); }
726 bool unique_key_range() {
return false; }
727 int get_type() {
return QS_TYPE_ROR_UNION; }
728 void add_keys_and_lengths(
String *key_names,
String *used_lengths);
729 void add_info_string(
String *str);
730 bool is_keys_used(
const MY_BITMAP *fields);
732 void dbug_dump(
int indent,
bool verbose);
744 while ((quick= it++))
761 bool have_prev_rowid;
809 const uint group_prefix_len;
810 uint group_key_parts;
814 bool have_agg_distinct;
818 uint min_max_arg_len;
822 uint real_prefix_len;
842 int next_min_in_range();
843 int next_max_in_range();
846 void update_min_result();
847 void update_max_result();
850 bool have_max,
bool have_agg_distinct,
852 uint group_prefix_len, uint group_key_parts,
853 uint used_key_parts,
KEY *index_info, uint
854 use_index,
double read_cost, ha_rows records, uint
855 key_infix_len, uchar *key_infix,
MEM_ROOT
856 *parent_alloc,
bool is_index_scan);
858 bool add_range(
SEL_ARG *sel_range);
859 void update_key_stat();
860 void adjust_prefix_ranges();
861 bool alloc_buffers();
863 void need_sorted_output() { }
868 bool unique_key_range() {
return false; }
869 int get_type() {
return QS_TYPE_GROUP_MIN_MAX; }
870 void add_keys_and_lengths(
String *key_names,
String *used_lengths);
872 void dbug_dump(
int indent,
bool verbose);
874 bool is_agg_distinct() {
return have_agg_distinct; }
875 virtual void append_loose_scan_type(
String *str)
878 str->append(STRING_WITH_LEN(
"scanning"));
891 int get_type() {
return QS_TYPE_RANGE_DESC; }
898 int reset(
void) { rev_it.rewind();
return QUICK_RANGE_SELECT::reset(); }
916 table_map const_tables,read_tables;
933 void set_quick(
QUICK_SELECT_I *new_quick) {
delete quick; quick= new_quick; }
934 bool check_quick(THD *thd,
bool force_quick_range, ha_rows
limit)
936 key_map tmp(key_map::ALL_BITS);
937 return test_quick_select(thd, tmp, 0, limit, force_quick_range,
938 ORDER::ORDER_NOT_RELEVANT) < 0;
940 inline bool skip_record(THD *thd,
bool *skip_record)
942 *skip_record= cond ? cond->val_int() == FALSE : FALSE;
943 return thd->is_error();
945 int test_quick_select(THD *thd,
key_map keys, table_map prev_tables,
946 ha_rows
limit,
bool force_quick_range,
947 const ORDER::enum_order interesting_order);
957 int init() {
return file->ft_init(); }
958 int reset() {
return 0; }
959 int get_next() {
return file->ft_read(
record); }
960 int get_type() {
return QS_TYPE_FULLTEXT; }
968 table_map read_tables,
Item *conds,
969 bool allow_null_cond,
int *error);
971 #ifdef WITH_PARTITION_STORAGE_ENGINE
972 bool prune_partitions(THD *thd,
TABLE *table,
Item *pprune_cond);
973 void store_key_image_to_rec(
Field *field, uchar *ptr, uint len);
976 extern String null_string;