diff options
47 files changed, 187 insertions, 183 deletions
diff --git a/include/heap.h b/include/heap.h index 33bbd2f0b3f..6cacb7fc529 100644 --- a/include/heap.h +++ b/include/heap.h @@ -225,8 +225,8 @@ extern void heap_update_auto_increment(HP_INFO *info, const byte *record); ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, key_range *min_key, key_range *max_key); int hp_panic(enum ha_panic_function flag); -int heap_rkey(HP_INFO *info, byte *record, int inx, const byte *key, - ulonglong keypart_map, enum ha_rkey_function find_flag); +int heap_rkey(HP_INFO *info, byte *record, int inx, const byte *key, + key_part_map keypart_map, enum ha_rkey_function find_flag); extern gptr heap_find(HP_INFO *info,int inx,const byte *key); extern int heap_check_heap(HP_INFO *info, my_bool print_status); extern byte *heap_position(HP_INFO *info); diff --git a/include/my_base.h b/include/my_base.h index 3aa280d825a..dd21362e8f7 100644 --- a/include/my_base.h +++ b/include/my_base.h @@ -395,7 +395,10 @@ enum ha_base_keytype { /* Other constants */ #define HA_NAMELEN 64 /* Max length of saved filename */ -#define NO_SUCH_KEY ((uint)~0) /* used as a key no. */ +#define NO_SUCH_KEY (~(uint)0) /* used as a key no. */ + +typedef ulong key_part_map; +#define HA_WHOLE_KEY (~(key_part_map)0) /* Intern constants in databases */ @@ -469,7 +472,7 @@ typedef struct st_key_range { const byte *key; uint length; - ulonglong keypart_map; + key_part_map keypart_map; enum ha_rkey_function flag; } key_range; diff --git a/include/myisam.h b/include/myisam.h index 1dd8f6f7ec4..b05440e5ae4 100644 --- a/include/myisam.h +++ b/include/myisam.h @@ -275,7 +275,7 @@ extern struct st_myisam_info *mi_open(const char *name,int mode, extern int mi_panic(enum ha_panic_function function); extern int mi_rfirst(struct st_myisam_info *file,byte *buf,int inx); extern int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, - ulonglong keypart_map, enum ha_rkey_function search_flag); + key_part_map keypart_map, enum ha_rkey_function search_flag); extern int mi_rlast(struct st_myisam_info *file,byte *buf,int inx); extern int mi_rnext(struct st_myisam_info *file,byte *buf,int inx); extern int mi_rnext_same(struct st_myisam_info *info, byte *buf); diff --git a/include/myisammrg.h b/include/myisammrg.h index 149b72dc7e1..02e81cf806d 100644 --- a/include/myisammrg.h +++ b/include/myisammrg.h @@ -87,7 +87,7 @@ extern int myrg_rnext(MYRG_INFO *file,byte *buf,int inx); extern int myrg_rprev(MYRG_INFO *file,byte *buf,int inx); extern int myrg_rnext_same(MYRG_INFO *file,byte *buf); extern int myrg_rkey(MYRG_INFO *info,byte *buf,int inx, const byte *key, - ulonglong keypart_map, enum ha_rkey_function search_flag); + key_part_map keypart_map, enum ha_rkey_function search_flag); extern int myrg_rrnd(MYRG_INFO *file,byte *buf,ulonglong pos); extern int myrg_rsame(MYRG_INFO *file,byte *record,int inx); extern int myrg_update(MYRG_INFO *file,const byte *old,byte *new_rec); diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc index 860cb54e27f..c5d015cdea7 100644 --- a/sql/event_db_repository.cc +++ b/sql/event_db_repository.cc @@ -288,7 +288,7 @@ Event_db_repository::index_read_for_db_for_i_s(THD *thd, TABLE *schema_table, { key_copy(key_buf, event_table->record[0], key_info, key_len); if (!(ret= event_table->file->index_read(event_table->record[0], key_buf, - (ulonglong)1, HA_READ_PREFIX))) + (key_part_map)1, HA_READ_PREFIX))) { DBUG_PRINT("info",("Found rows. Let's retrieve them. ret=%d", ret)); do @@ -843,7 +843,7 @@ Event_db_repository::find_named_event(THD *thd, LEX_STRING db, LEX_STRING name, key_copy(key, table->record[0], table->key_info, table->key_info->key_length); - if (table->file->index_read_idx(table->record[0], 0, key, ~ULL(0), + if (table->file->index_read_idx(table->record[0], 0, key, HA_WHOLE_KEY, HA_READ_KEY_EXACT)) { DBUG_PRINT("info", ("Row not found")); diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 4ed602be54d..d3979fa0718 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -3336,7 +3336,7 @@ int ha_partition::index_end() */ int ha_partition::index_read(byte * buf, const byte * key, - ulonglong keypart_map, + key_part_map keypart_map, enum ha_rkey_function find_flag) { DBUG_ENTER("ha_partition::index_read"); @@ -3357,7 +3357,7 @@ int ha_partition::index_read(byte * buf, const byte * key, */ int ha_partition::common_index_read(byte *buf, const byte *key, - ulonglong keypart_map, + key_part_map keypart_map, enum ha_rkey_function find_flag) { int error; @@ -3513,7 +3513,7 @@ int ha_partition::common_first_last(byte *buf) */ int ha_partition::index_read_last(byte *buf, const byte *key, - ulonglong keypart_map) + key_part_map keypart_map) { DBUG_ENTER("ha_partition::index_read_last"); diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 2d43e2b0df2..a081e4bb472 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -384,8 +384,8 @@ public: any end processing needed. */ virtual int index_read(byte * buf, const byte * key, - ulonglong keypart_map, - enum ha_rkey_function find_flag); + key_part_map keypart_map, + enum ha_rkey_function find_flag); virtual int index_init(uint idx, bool sorted); virtual int index_end(); @@ -399,7 +399,7 @@ public: virtual int index_last(byte * buf); virtual int index_next_same(byte * buf, const byte * key, uint keylen); virtual int index_read_last(byte * buf, const byte * key, - ulonglong keypart_map); + key_part_map keypart_map); /* read_first_row is virtual method but is only implemented by @@ -425,7 +425,8 @@ public: private: int common_index_read(byte * buf, const byte * key, - ulonglong keypart_map, enum ha_rkey_function find_flag); + key_part_map keypart_map, + enum ha_rkey_function find_flag); int common_first_last(byte * buf); int partition_scan_set_up(byte * buf, bool idx_read_flag); int handle_unordered_next(byte * buf, bool next_same); diff --git a/sql/handler.cc b/sql/handler.cc index 7d3edf36162..6df8a4a5021 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -3282,8 +3282,8 @@ int handler::compare_key(key_range *range) int handler::index_read_idx(byte * buf, uint index, const byte * key, - ulonglong keypart_map, - enum ha_rkey_function find_flag) + key_part_map keypart_map, + enum ha_rkey_function find_flag) { int error, error1; error= index_init(index, 0); diff --git a/sql/handler.h b/sql/handler.h index 1d02d6a7ee3..0158cbad515 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -867,17 +867,17 @@ public: {} }; -uint calculate_key_len(TABLE *, uint, const byte *, ulonglong); +uint calculate_key_len(TABLE *, uint, const byte *, key_part_map); /* bitmap with first N+1 bits set (keypart_map for a key prefix of [0..N] keyparts) */ -#define make_keypart_map(N) (((ulonglong)2 << (N)) - 1) +#define make_keypart_map(N) (((key_part_map)2 << (N)) - 1) /* bitmap with first N bits set (keypart_map for a key prefix of [0..N-1] keyparts) */ -#define make_prev_keypart_map(N) (((ulonglong)1 << (N)) - 1) +#define make_prev_keypart_map(N) (((key_part_map)1 << (N)) - 1) /* The handler class is the interface for dynamically loadable @@ -1219,14 +1219,26 @@ public: enum ha_rkey_function find_flag) { return HA_ERR_WRONG_COMMAND; } public: - virtual int index_read(byte * buf, const byte * key, ulonglong keypart_map, +/** + @brief + Positions an index cursor to the index specified in the handle. Fetches the + row if available. If the key value is null, begin at the first key of the + index. +*/ + virtual int index_read(byte * buf, const byte * key, key_part_map keypart_map, enum ha_rkey_function find_flag) { uint key_len= calculate_key_len(table, active_index, key, keypart_map); return index_read(buf, key, key_len, find_flag); } +/** + @brief + Positions an index cursor to the index specified in the handle. Fetches the + row if available. If the key value is null, begin at the first key of the + index. +*/ virtual int index_read_idx(byte * buf, uint index, const byte * key, - ulonglong keypart_map, + key_part_map keypart_map, enum ha_rkey_function find_flag); virtual int index_next(byte * buf) { return HA_ERR_WRONG_COMMAND; } @@ -1241,8 +1253,13 @@ public: virtual int index_read_last(byte * buf, const byte * key, uint key_len) { return (my_errno=HA_ERR_WRONG_COMMAND); } public: +/** + @brief + The following functions works like index_read, but it find the last + row with the current key value or prefix. +*/ virtual int index_read_last(byte * buf, const byte * key, - ulonglong keypart_map) + key_part_map keypart_map) { uint key_len= calculate_key_len(table, active_index, key, keypart_map); return index_read_last(buf, key, key_len); diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index d9141cc0740..e1abda2f612 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -2045,7 +2045,7 @@ int subselect_uniquesubquery_engine::exec() table->file->ha_index_init(tab->ref.key, 0); error= table->file->index_read(table->record[0], tab->ref.key_buff, - tab_to_keypart_map(tab), + make_prev_keypart_map(tab->ref.key_parts), HA_READ_KEY_EXACT); if (error && error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE) @@ -2155,7 +2155,7 @@ int subselect_indexsubquery_engine::exec() table->file->ha_index_init(tab->ref.key, 1); error= table->file->index_read(table->record[0], tab->ref.key_buff, - tab_to_keypart_map(tab), + make_prev_keypart_map(tab->ref.key_parts), HA_READ_KEY_EXACT); if (error && error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE) diff --git a/sql/log_event.cc b/sql/log_event.cc index 5ff23a49252..0448aacd4f3 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -6855,7 +6855,7 @@ replace_record(THD *thd, TABLE *table, key_copy((byte*)key.get(), table->record[0], table->key_info + keynum, 0); error= table->file->index_read_idx(table->record[1], keynum, - (const byte*)key.get(), ~ULL(0), + (const byte*)key.get(), HA_WHOLE_KEY, HA_READ_KEY_EXACT); if (error) DBUG_RETURN(error); @@ -7039,8 +7039,8 @@ static int find_and_fetch_row(TABLE *table, byte *key) my_ptrdiff_t const pos= table->s->null_bytes > 0 ? table->s->null_bytes - 1 : 0; table->record[1][pos]= 0xFF; - if ((error= table->file->index_read(table->record[1], key, - ~(ulonglong)0, HA_READ_KEY_EXACT))) + if ((error= table->file->index_read(table->record[1], key, HA_WHOLE_KEY, + HA_READ_KEY_EXACT))) { table->file->print_error(error, MYF(0)); table->file->ha_index_end(); diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 1852e74a333..099c9b98c1f 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -47,7 +47,6 @@ typedef Bitmap<64> key_map; /* Used for finding keys */ #else typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */ #endif -typedef ulong key_part_map; /* Used for finding key parts */ typedef ulong nesting_map; /* Used for flags of nesting constructs */ /* Used to identify NESTED_JOIN structures within a join (applicable only to diff --git a/sql/opt_range.cc b/sql/opt_range.cc index d95eb1c3553..52faaf25b42 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -312,6 +312,7 @@ public: min_value=arg->max_value; min_flag=arg->max_flag & NEAR_MAX ? 0 : NEAR_MIN; } + /* returns a number of keypart values (0 or 1) appended to the key buffer */ int store_min(uint length,char **min_key,uint min_key_flag) { if ((min_flag & GEOM_FLAG) || @@ -330,6 +331,7 @@ public: } return 0; } + /* returns a number of keypart values (0 or 1) appended to the key buffer */ int store_max(uint length,char **max_key, uint max_key_flag) { if (!(max_flag & NO_MAX_RANGE) && @@ -347,13 +349,8 @@ public: } return 0; } - /*void store(uint length,char **min_key,uint min_key_flag, - char **max_key, uint max_key_flag) - { - store_min(length, min_key, min_key_flag); - store_max(length, max_key, max_key_flag); - }*/ + /* returns a number of keypart values appended to the key buffer */ int store_min_key(KEY_PART *key,char **range_key, uint *range_key_flag) { SEL_ARG *key_tree= first(); @@ -369,6 +366,7 @@ public: return res; } + /* returns a number of keypart values appended to the key buffer */ int store_max_key(KEY_PART *key,char **range_key, uint *range_key_flag) { SEL_ARG *key_tree= last(); @@ -595,7 +593,7 @@ static SEL_ARG *get_mm_leaf(RANGE_OPT_PARAM *param,COND *cond_func,Field *field, static SEL_TREE *get_mm_tree(RANGE_OPT_PARAM *param,COND *cond); static bool is_key_scan_ror(PARAM *param, uint keynr, uint8 nparts); -static ha_rows check_quick_select(PARAM *param,uint index,SEL_ARG *key_tree, +static ha_rows check_quick_select(PARAM *param,uint index,SEL_ARG *key_tree, bool update_tbl_stats); static ha_rows check_quick_keys(PARAM *param,uint index,SEL_ARG *key_tree, char *min_key, uint min_key_flag, int, @@ -4075,7 +4073,7 @@ static double ror_scan_selectivity(const ROR_INTERSECT_INFO *info, byte key_val[MAX_KEY_LENGTH+MAX_FIELD_WIDTH]; /* key values tuple */ char *key_ptr= (char*) key_val; SEL_ARG *sel_arg, *tuple_arg= NULL; - ulonglong keypart_map= 0; + key_part_map keypart_map= 0; bool cur_covered; bool prev_covered= test(bitmap_is_set(&info->covered_fields, key_part->fieldnr-1)); @@ -7457,7 +7455,8 @@ get_quick_keys(PARAM *param,QUICK_RANGE_SELECT *quick,KEY_PART *key, { QUICK_RANGE *range; uint flag; - int min_part= key_tree->part-1, max_part=key_tree->part-1; + int min_part= key_tree->part-1, // # of keypart values in min_key buffer + max_part= key_tree->part-1; // # of keypart values in max_key buffer if (key_tree->left != &null_element) { @@ -7488,15 +7487,11 @@ get_quick_keys(PARAM *param,QUICK_RANGE_SELECT *quick,KEY_PART *key, { uint tmp_min_flag=key_tree->min_flag,tmp_max_flag=key_tree->max_flag; if (!tmp_min_flag) - { min_part+= key_tree->next_key_part->store_min_key(key, &tmp_min_key, &tmp_min_flag); - } if (!tmp_max_flag) - { max_part+= key_tree->next_key_part->store_max_key(key, &tmp_max_key, &tmp_max_flag); - } flag=tmp_min_flag | tmp_max_flag; } } @@ -7652,13 +7647,13 @@ bool QUICK_ROR_UNION_SELECT::is_keys_used(const MY_BITMAP *fields) thd Thread handle table Table to access ref ref[_or_null] scan parameters - records Estimate of number of records (needed only to construct + records Estimate of number of records (needed only to construct quick select) NOTES This allocates things in a new memory root, as this may be called many times during a query. - - RETURN + + RETURN Quick select that retrieves the same rows as passed ref scan NULL on error. */ @@ -7694,9 +7689,10 @@ QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table, !(range= new(alloc) QUICK_RANGE())) goto err; // out of memory - range->min_key=range->max_key=(char*) ref->key_buff; - range->min_length=range->max_length=ref->key_length; - range->min_keypart_map= range->max_keypart_map= (1 << ref->key_parts) - 1; + range->min_key= range->max_key= (char*) ref->key_buff; + range->min_length= range->max_length= ref->key_length; + range->min_keypart_map= range->max_keypart_map= + make_prev_keypart_map(ref->key_parts); range->flag= ((ref->key_length == key_info->key_length && (key_info->flags & (HA_NOSAME | HA_END_SPACE_KEY)) == HA_NOSAME) ? EQ_RANGE : 0); @@ -7709,7 +7705,7 @@ QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table, { key_part->part=part; key_part->field= key_info->key_part[part].field; - key_part->length= key_info->key_part[part].length; + key_part->length= key_info->key_part[part].length; key_part->store_length= key_info->key_part[part].store_length; key_part->null_bit= key_info->key_part[part].null_bit; key_part->flag= (uint8) key_info->key_part[part].key_part_flag; @@ -7728,13 +7724,11 @@ QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table, QUICK_RANGE *null_range; *ref->null_ref_key= 1; // Set null byte then create a range - if (!(null_range= new (alloc) QUICK_RANGE((char*)ref->key_buff, - ref->key_length, - (1 << ref->key_parts) - 1, - (char*)ref->key_buff, - ref->key_length, - (1 << ref->key_parts) - 1, - EQ_RANGE))) + if (!(null_range= new (alloc) + QUICK_RANGE((char*)ref->key_buff, ref->key_length, + make_prev_keypart_map(ref->key_parts), + (char*)ref->key_buff, ref->key_length, + make_prev_keypart_map(ref->key_parts), EQ_RANGE))) goto err; *ref->null_ref_key= 0; // Clear null byte if (insert_dynamic(&quick->ranges,(gptr)&null_range)) @@ -8246,7 +8240,7 @@ end: */ int QUICK_RANGE_SELECT::get_next_prefix(uint prefix_length, - ulonglong keypart_map, + key_part_map keypart_map, byte *cur_prefix) { DBUG_ENTER("QUICK_RANGE_SELECT::get_next_prefix"); @@ -10502,7 +10496,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_prefix() { byte *cur_prefix= seen_first_key ? group_prefix : NULL; if ((result= quick_prefix_select->get_next_prefix(group_prefix_len, - (ULL(1) << group_key_parts) - 1, cur_prefix))) + make_prev_keypart_map(group_key_parts), cur_prefix))) DBUG_RETURN(result); seen_first_key= TRUE; } @@ -10561,8 +10555,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_prefix() int QUICK_GROUP_MIN_MAX_SELECT::next_min_in_range() { ha_rkey_function find_flag; - uint search_prefix_len; - ulonglong keypart_map; + key_part_map keypart_map; QUICK_RANGE *cur_range; bool found_null= FALSE; int result= HA_ERR_KEY_NOT_FOUND; @@ -10584,8 +10577,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_min_in_range() if (cur_range->flag & NO_MIN_RANGE) { - search_prefix_len= real_prefix_len; - keypart_map= (ULL(1) << real_key_parts) - 1; + keypart_map= make_prev_keypart_map(real_key_parts); find_flag= HA_READ_KEY_EXACT; } else @@ -10593,8 +10585,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_min_in_range() /* Extend the search key with the lower boundary for this range. */ memcpy(group_prefix + real_prefix_len, cur_range->min_key, cur_range->min_length); - search_prefix_len= real_prefix_len + min_max_arg_len; - keypart_map= (ULL(2) << real_key_parts) - 1; + keypart_map= make_keypart_map(real_key_parts); find_flag= (cur_range->flag & (EQ_RANGE | NULL_RANGE)) ? HA_READ_KEY_EXACT : (cur_range->flag & NEAR_MIN) ? HA_READ_AFTER_KEY : HA_READ_KEY_OR_NEXT; @@ -10697,8 +10688,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_min_in_range() int QUICK_GROUP_MIN_MAX_SELECT::next_max_in_range() { ha_rkey_function find_flag; - uint search_prefix_len; - ulonglong keypart_map; + key_part_map keypart_map; QUICK_RANGE *cur_range; int result; @@ -10720,8 +10710,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_max_in_range() if (cur_range->flag & NO_MAX_RANGE) { - search_prefix_len= real_prefix_len; - keypart_map= (ULL(1) << real_key_parts) - 1; + keypart_map= make_prev_keypart_map(real_key_parts); find_flag= HA_READ_PREFIX_LAST; } else @@ -10729,8 +10718,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_max_in_range() /* Extend the search key with the upper boundary for this range. */ memcpy(group_prefix + real_prefix_len, cur_range->max_key, cur_range->max_length); - search_prefix_len= real_prefix_len + min_max_arg_len; - keypart_map= (ULL(2) << real_key_parts) - 1; + keypart_map= make_keypart_map(real_key_parts); find_flag= (cur_range->flag & EQ_RANGE) ? HA_READ_KEY_EXACT : (cur_range->flag & NEAR_MAX) ? HA_READ_BEFORE_KEY : HA_READ_PREFIX_LAST_OR_PREV; diff --git a/sql/opt_range.h b/sql/opt_range.h index ce98b4609d1..1ad9567cddd 100644 --- a/sql/opt_range.h +++ b/sql/opt_range.h @@ -37,15 +37,16 @@ class QUICK_RANGE :public Sql_alloc { public: char *min_key,*max_key; uint16 min_length,max_length,flag; - ulonglong min_keypart_map, max_keypart_map; + key_part_map min_keypart_map, // bitmap of used keyparts in min_key + max_keypart_map; // bitmap of used keyparts in max_key #ifdef HAVE_purify uint16 dummy; /* Avoid warnings on 'flag' */ #endif QUICK_RANGE(); /* Full range */ QUICK_RANGE(const char *min_key_arg, uint min_length_arg, - ulonglong min_keypart_map_arg, + key_part_map min_keypart_map_arg, const char *max_key_arg, uint max_length_arg, - ulonglong max_keypart_map_arg, + key_part_map max_keypart_map_arg, uint flag_arg) : min_key((char*) sql_memdup(min_key_arg,min_length_arg+1)), max_key((char*) sql_memdup(max_key_arg,max_length_arg+1)), @@ -65,11 +66,11 @@ class QUICK_RANGE :public Sql_alloc { /* Quick select interface. This class is a parent for all QUICK_*_SELECT and FT_SELECT classes. - + The usage scenario is as follows: 1. Create quick select quick= new QUICK_XXX_SELECT(...); - + 2. Perform lightweight initialization. This can be done in 2 ways: 2.a: Regular initialization if (quick->init()) @@ -80,29 +81,29 @@ class QUICK_RANGE :public Sql_alloc { 2.b: Special initialization for quick selects merged by QUICK_ROR_*_SELECT if (quick->init_ror_merged_scan()) delete quick; - + 3. Perform zero, one, or more scans. while (...) { // initialize quick select for scan. This may allocate - // buffers and/or prefetch rows. + // buffers and/or prefetch rows. if (quick->reset()) { //the only valid action after failed reset() call is delete delete quick; //abort query } - + // perform the scan do { res= quick->get_next(); } while (res && ...) } - + 4. Delete the select: delete quick; - + */ class QUICK_SELECT_I @@ -128,6 +129,8 @@ public: Max. number of (first) key parts this quick select uses for retrieval. eg. for "(key1p1=c1 AND key1p2=c2) OR key1p1=c2" used_key_parts == 2. Applicable if index!= MAX_KEY. + + For QUICK_GROUP_MIN_MAX_SELECT it includes MIN/MAX argument keyparts. */ uint used_key_parts; @@ -323,7 +326,7 @@ public: int reset(void); int get_next(); void range_end(); - int get_next_prefix(uint prefix_length, ulonglong keypart_map, + int get_next_prefix(uint prefix_length, key_part_map keypart_map, byte *cur_prefix); bool reverse_sorted() { return 0; } bool unique_key_range(); @@ -611,7 +614,7 @@ private: byte *tmp_record; /* Temporary storage for next_min(), next_max(). */ byte *group_prefix; /* Key prefix consisting of the GROUP fields. */ uint group_prefix_len; /* Length of the group prefix. */ - uint group_key_parts; + uint group_key_parts; /* A number of keyparts in the group prefix */ byte *last_prefix; /* Prefix of the last group for detecting EOF. */ bool have_min; /* Specify whether we are computing */ bool have_max; /* a MIN, a MAX, or both. */ @@ -623,7 +626,7 @@ private: uint key_infix_len; DYNAMIC_ARRAY min_max_ranges; /* Array of range ptrs for the MIN/MAX field. */ uint real_prefix_len; /* Length of key prefix extended with key_infix. */ - uint real_key_parts; + uint real_key_parts; /* A number of keyparts in the above value. */ List<Item_sum> *min_functions; List<Item_sum> *max_functions; List_iterator<Item_sum> *min_functions_it; diff --git a/sql/sp.cc b/sql/sp.cc index 27b3b2532c3..eef5dc01912 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -218,7 +218,7 @@ db_find_routine_aux(THD *thd, int type, sp_name *name, TABLE *table) key_copy(key, table->record[0], table->key_info, table->key_info->key_length); - if (table->file->index_read_idx(table->record[0], 0, key, ~ULL(0), + if (table->file->index_read_idx(table->record[0], 0, key, HA_WHOLE_KEY, HA_READ_KEY_EXACT)) DBUG_RETURN(SP_KEY_NOT_FOUND); @@ -924,7 +924,7 @@ sp_drop_db_routines(THD *thd, char *db) table->file->ha_index_init(0, 1); if (! table->file->index_read(table->record[0], (byte *)table->field[MYSQL_PROC_FIELD_DB]->ptr, - (ulonglong)1, HA_READ_KEY_EXACT)) + (key_part_map)1, HA_READ_KEY_EXACT)) { int nxtres; bool deleted= FALSE; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 2b642689281..aaa88071173 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1813,7 +1813,7 @@ static bool update_user_table(THD *thd, TABLE *table, table->key_info->key_length); if (table->file->index_read_idx(table->record[0], 0, - (byte *) user_key, ~ULL(0), + (byte *) user_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT)) { my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), @@ -1904,7 +1904,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, key_copy(user_key, table->record[0], table->key_info, table->key_info->key_length); - if (table->file->index_read_idx(table->record[0], 0, user_key, ~ULL(0), + if (table->file->index_read_idx(table->record[0], 0, user_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT)) { /* what == 'N' means revoke */ @@ -2121,7 +2121,7 @@ static int replace_db_table(TABLE *table, const char *db, key_copy(user_key, table->record[0], table->key_info, table->key_info->key_length); - if (table->file->index_read_idx(table->record[0],0, user_key, ~ULL(0), + if (table->file->index_read_idx(table->record[0],0, user_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT)) { if (what == 'N') @@ -2339,7 +2339,7 @@ GRANT_TABLE::GRANT_TABLE(TABLE *form, TABLE *col_privs) col_privs->file->ha_index_init(0, 1); if (col_privs->file->index_read(col_privs->record[0], (byte*) key, - (ulonglong)15, HA_READ_KEY_EXACT)) + (key_part_map)15, HA_READ_KEY_EXACT)) { cols = 0; /* purecov: deadcode */ col_privs->file->ha_index_end(); @@ -2501,7 +2501,7 @@ static int replace_column_table(GRANT_TABLE *g_t, key_copy(user_key, table->record[0], table->key_info, table->key_info->key_length); - if (table->file->index_read(table->record[0], user_key, ~(ulonglong)0, + if (table->file->index_read(table->record[0], user_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT)) { if (revoke_grant) @@ -2577,7 +2577,7 @@ static int replace_column_table(GRANT_TABLE *g_t, key_copy(user_key, table->record[0], table->key_info, key_prefix_length); - if (table->file->index_read(table->record[0], user_key, (ulonglong)15, + if (table->file->index_read(table->record[0], user_key, (key_part_map)15, HA_READ_KEY_EXACT)) goto end; @@ -2678,7 +2678,7 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, key_copy(user_key, table->record[0], table->key_info, table->key_info->key_length); - if (table->file->index_read_idx(table->record[0], 0, user_key, ~ULL(0), + if (table->file->index_read_idx(table->record[0], 0, user_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT)) { /* @@ -2796,13 +2796,13 @@ static int replace_routine_table(THD *thd, GRANT_NAME *grant_name, table->field[2]->store(combo.user.str,combo.user.length, &my_charset_latin1); table->field[3]->store(routine_name,(uint) strlen(routine_name), &my_charset_latin1); - table->field[4]->store((longlong)(is_proc ? + table->field[4]->store((longlong)(is_proc ? TYPE_ENUM_PROCEDURE : TYPE_ENUM_FUNCTION), TRUE); store_record(table,record[1]); // store at pos 1 if (table->file->index_read_idx(table->record[0], 0, - (byte*) table->field[0]->ptr, ~ULL(0), + (byte*) table->field[0]->ptr, HA_WHOLE_KEY, HA_READ_KEY_EXACT)) { /* @@ -5001,7 +5001,7 @@ static int handle_grant_table(TABLE_LIST *tables, uint table_no, bool drop, key_copy(user_key, table->record[0], table->key_info, key_prefix_length); if ((error= table->file->index_read_idx(table->record[0], 0, - user_key, ULL(3), + user_key, (key_part_map)3, HA_READ_KEY_EXACT))) { if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE) diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 9c6c98cb151..cd87330cedb 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -515,7 +515,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, } List_iterator<Item> it_ke(*key_expr); Item *item; - ulonglong keypart_map; + key_part_map keypart_map; for (keypart_map= key_len=0 ; (item=it_ke++) ; key_part++) { my_bitmap_map *old_map; diff --git a/sql/sql_help.cc b/sql/sql_help.cc index aacfd8f8245..b677111c019 100644 --- a/sql/sql_help.cc +++ b/sql/sql_help.cc @@ -295,7 +295,7 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, rkey_id->store((longlong) key_id, TRUE); rkey_id->get_key_image(buff, rkey_id->pack_length(), Field::itRAW); int key_res= relations->file->index_read(relations->record[0], - (byte *) buff, (ulonglong)1, + (byte *) buff, (key_part_map)1, HA_READ_KEY_EXACT); for ( ; @@ -309,7 +309,7 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, field->get_key_image(topic_id_buff, field->pack_length(), Field::itRAW); if (!topics->file->index_read(topics->record[0], (byte *)topic_id_buff, - (ulonglong)1, HA_READ_KEY_EXACT)) + (key_part_map)1, HA_READ_KEY_EXACT)) { memorize_variant_topic(thd,topics,count,find_fields, names,name,description,example); diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 62c4e32409b..e973180eef7 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1214,7 +1214,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) } key_copy((byte*) key,table->record[0],table->key_info+key_nr,0); if ((error=(table->file->index_read_idx(table->record[1],key_nr, - (byte*) key, ~ULL(0), + (byte*) key, HA_WHOLE_KEY, HA_READ_KEY_EXACT)))) goto err; } diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index d7ced748394..70bc9ef23d5 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -943,7 +943,7 @@ my_bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name) table->use_all_columns(); table->field[0]->store(name->str, name->length, system_charset_info); if (! table->file->index_read_idx(table->record[0], 0, - (byte *)table->field[0]->ptr, ~ULL(0), + (byte *)table->field[0]->ptr, HA_WHOLE_KEY, HA_READ_KEY_EXACT)) { int error; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 8661503df8e..8184b2a732e 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -10980,7 +10980,7 @@ int safe_index_read(JOIN_TAB *tab) TABLE *table= tab->table; if ((error=table->file->index_read(table->record[0], tab->ref.key_buff, - tab_to_keypart_map(tab), + make_prev_keypart_map(tab->ref.key_parts), HA_READ_KEY_EXACT))) return report_error(table, error); return 0; @@ -11119,7 +11119,7 @@ join_read_const(JOIN_TAB *tab) { error=table->file->index_read_idx(table->record[0],tab->ref.key, (byte*) tab->ref.key_buff, - tab_to_keypart_map(tab), + make_prev_keypart_map(tab->ref.key_parts), HA_READ_KEY_EXACT); } if (error) @@ -11163,7 +11163,7 @@ join_read_key(JOIN_TAB *tab) } error=table->file->index_read(table->record[0], tab->ref.key_buff, - tab_to_keypart_map(tab), + make_prev_keypart_map(tab->ref.key_parts), HA_READ_KEY_EXACT); if (error && error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE) return report_error(table, error); @@ -11192,7 +11192,7 @@ join_read_always_key(JOIN_TAB *tab) return -1; if ((error=table->file->index_read(table->record[0], tab->ref.key_buff, - tab_to_keypart_map(tab), + make_prev_keypart_map(tab->ref.key_parts), HA_READ_KEY_EXACT))) { if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE) @@ -11219,8 +11219,7 @@ join_read_last_key(JOIN_TAB *tab) if (cp_buffer_from_ref(tab->join->thd, table, &tab->ref)) return -1; if ((error=table->file->index_read_last(table->record[0], - tab->ref.key_buff, - tab_to_keypart_map(tab)))) + tab->ref.key_buff, make_prev_keypart_map(tab->ref.key_parts)))) { if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE) return report_error(table, error); @@ -11761,7 +11760,7 @@ end_update(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), group->buff[-1]= (char) group->field->is_null(); } if (!table->file->index_read(table->record[1], - join->tmp_table_param.group_buff, ~(ulonglong)0, + join->tmp_table_param.group_buff, HA_WHOLE_KEY, HA_READ_KEY_EXACT)) { /* Update old record */ restore_record(table,record[1]); diff --git a/sql/sql_select.h b/sql/sql_select.h index e31fe143573..ca93179f9d9 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -192,7 +192,7 @@ typedef struct st_join_table { JOIN *join; /* Bitmap of nested joins this table is part of */ nested_join_map embedding_map; - + void cleanup(); inline bool is_using_loose_index_scan() { @@ -202,11 +202,6 @@ typedef struct st_join_table { } } JOIN_TAB; -static inline ulonglong tab_to_keypart_map(JOIN_TAB *tab) -{ - return (ULL(1) << tab->ref.key_parts) - 1; -} - enum_nested_loop_state sub_select_cache(JOIN *join, JOIN_TAB *join_tab, bool end_of_records); enum_nested_loop_state sub_select(JOIN *join,JOIN_TAB *join_tab, bool diff --git a/sql/sql_servers.cc b/sql/sql_servers.cc index 1d7c8d5272d..7b3b71cdd9a 100644 --- a/sql/sql_servers.cc +++ b/sql/sql_servers.cc @@ -354,7 +354,7 @@ my_bool server_exists_in_table(THD *thd, LEX_SERVER_OPTIONS *server_options) system_charset_info); if ((error= table->file->index_read_idx(table->record[0], 0, - (byte *)table->field[0]->ptr, ~(ulonglong)0, + (byte *)table->field[0]->ptr, HA_WHOLE_KEY, HA_READ_KEY_EXACT))) { if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE) @@ -554,7 +554,7 @@ int insert_server_record(TABLE *table, FOREIGN_SERVER *server) /* read index until record is that specified in server_name */ if ((error= table->file->index_read_idx(table->record[0], 0, - (byte *)table->field[0]->ptr, ~(longlong)0, + (byte *)table->field[0]->ptr, HA_WHOLE_KEY, HA_READ_KEY_EXACT))) { /* if not found, err */ @@ -926,7 +926,7 @@ int delete_server_record(TABLE *table, table->field[0]->store(server_name, server_name_length, system_charset_info); if ((error= table->file->index_read_idx(table->record[0], 0, - (byte *)table->field[0]->ptr, ~(ulonglong)0, + (byte *)table->field[0]->ptr, HA_WHOLE_KEY, HA_READ_KEY_EXACT))) { if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE) diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index b0e7831465a..4c584bff72a 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -514,7 +514,7 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name) table->use_all_columns(); table->field[0]->store(exact_name_str, exact_name_len, &my_charset_bin); if (!table->file->index_read_idx(table->record[0], 0, - (byte*) table->field[0]->ptr, ~ULL(0), + (byte*) table->field[0]->ptr, HA_WHOLE_KEY, HA_READ_KEY_EXACT)) { int error; @@ -523,7 +523,7 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name) } close_thread_tables(thd); - rw_unlock(&THR_LOCK_udf); + rw_unlock(&THR_LOCK_udf); DBUG_RETURN(0); err: rw_unlock(&THR_LOCK_udf); diff --git a/sql/table.cc b/sql/table.cc index e4b3be5dbe0..f2bf25e6a75 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -2250,7 +2250,7 @@ char *get_field(MEM_ROOT *mem, Field *field) that are present in this value, returns the length of the value */ uint calculate_key_len(TABLE *table, uint key, const byte *buf, - ulonglong keypart_map) + key_part_map keypart_map) { /* works only with key prefixes */ DBUG_ASSERT(((keypart_map + 1) & keypart_map) == 0); diff --git a/sql/table.h b/sql/table.h index d15929e8cba..aa053f207b3 100644 --- a/sql/table.h +++ b/sql/table.h @@ -197,9 +197,9 @@ typedef struct st_table_share uint rowid_field_offset; /* Field_nr +1 to rowid field */ /* Index of auto-updated TIMESTAMP field in field array */ uint primary_key; - uint next_number_index; - uint next_number_key_offset; - uint next_number_keypart; + uint next_number_index; /* autoincrement key number */ + uint next_number_key_offset; /* autoinc keypart offset in a key */ + uint next_number_keypart; /* autoinc keypart number in a key */ uint error, open_errno, errarg; /* error from open_table_def() */ uint column_bitmap_size; uchar frm_version; diff --git a/sql/tztime.cc b/sql/tztime.cc index b9f757faeb8..18161022dc3 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -1917,7 +1917,7 @@ tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables) (void)table->file->ha_index_init(0, 1); if (table->file->index_read(table->record[0], (byte*)table->field[0]->ptr, - ~(ulonglong)0, HA_READ_KEY_EXACT)) + HA_WHOLE_KEY, HA_READ_KEY_EXACT)) { #ifdef EXTRA_DEBUG /* @@ -1945,7 +1945,7 @@ tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables) (void)table->file->ha_index_init(0, 1); if (table->file->index_read(table->record[0], (byte*)table->field[0]->ptr, - ~(ulonglong)0, HA_READ_KEY_EXACT)) + HA_WHOLE_KEY, HA_READ_KEY_EXACT)) { sql_print_error("Can't find description of time zone '%u'", tzid); goto end; @@ -1973,7 +1973,7 @@ tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables) (void)table->file->ha_index_init(0, 1); res= table->file->index_read(table->record[0], (byte*)table->field[0]->ptr, - (ulonglong)1, HA_READ_KEY_EXACT); + (key_part_map)1, HA_READ_KEY_EXACT); while (!res) { ttid= (uint)table->field[1]->val_int(); @@ -2045,7 +2045,7 @@ tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables) (void)table->file->ha_index_init(0, 1); res= table->file->index_read(table->record[0], (byte*)table->field[0]->ptr, - (ulonglong)1, HA_READ_KEY_EXACT); + (key_part_map)1, HA_READ_KEY_EXACT); while (!res) { ttime= (my_time_t)table->field[1]->val_int(); diff --git a/storage/blackhole/ha_blackhole.cc b/storage/blackhole/ha_blackhole.cc index d7e56f91af4..6f07c4183f1 100644 --- a/storage/blackhole/ha_blackhole.cc +++ b/storage/blackhole/ha_blackhole.cc @@ -152,7 +152,7 @@ THR_LOCK_DATA **ha_blackhole::store_lock(THD *thd, int ha_blackhole::index_read(byte * buf, const byte * key, - ulonglong keypart_map, uint key_len, + key_part_map keypart_map, enum ha_rkey_function find_flag) { DBUG_ENTER("ha_blackhole::index_read"); @@ -161,7 +161,7 @@ int ha_blackhole::index_read(byte * buf, const byte * key, int ha_blackhole::index_read_idx(byte * buf, uint idx, const byte * key, - ulonglong keypart_map, uint key_len, + key_part_map keypart_map, enum ha_rkey_function find_flag) { DBUG_ENTER("ha_blackhole::index_read_idx"); @@ -170,7 +170,7 @@ int ha_blackhole::index_read_idx(byte * buf, uint idx, const byte * key, int ha_blackhole::index_read_last(byte * buf, const byte * key, - ulonglong keypart_map) + key_part_map keypart_map) { DBUG_ENTER("ha_blackhole::index_read_last"); DBUG_RETURN(HA_ERR_END_OF_FILE); diff --git a/storage/blackhole/ha_blackhole.h b/storage/blackhole/ha_blackhole.h index cd8b6491dba..2af12b33077 100644 --- a/storage/blackhole/ha_blackhole.h +++ b/storage/blackhole/ha_blackhole.h @@ -64,12 +64,11 @@ public: int rnd_init(bool scan); int rnd_next(byte *buf); int rnd_pos(byte * buf, byte *pos); - int index_read(byte * buf, const byte * key, ulonglong keypart_map, - uint key_len, enum ha_rkey_function find_flag); + int index_read(byte * buf, const byte * key, key_part_map keypart_map, + enum ha_rkey_function find_flag); int index_read_idx(byte * buf, uint idx, const byte * key, - ulonglong keypart_map, uint key_len, - enum ha_rkey_function find_flag); - int index_read_last(byte * buf, const byte * key, ulonglong keypart_map); + key_part_map keypart_map, enum ha_rkey_function find_flag); + int index_read_last(byte * buf, const byte * key, key_part_map keypart_map); int index_next(byte * buf); int index_prev(byte * buf); int index_first(byte * buf); diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc index 01d508e3290..999e36a4242 100644 --- a/storage/example/ha_example.cc +++ b/storage/example/ha_example.cc @@ -415,7 +415,7 @@ int ha_example::delete_row(const byte * buf) */ int ha_example::index_read(byte * buf, const byte * key, - ulonglong keypart_map __attribute__((unused)), + key_part_map keypart_map __attribute__((unused)), enum ha_rkey_function find_flag __attribute__((unused))) { diff --git a/storage/example/ha_example.h b/storage/example/ha_example.h index ee60b412974..9777a478209 100644 --- a/storage/example/ha_example.h +++ b/storage/example/ha_example.h @@ -191,7 +191,7 @@ public: skip it and and MySQL will treat it as not implemented. */ int index_read(byte * buf, const byte * key, - ulonglong keypart_map, enum ha_rkey_function find_flag); + key_part_map keypart_map, enum ha_rkey_function find_flag); /** @brief We implement this in ha_example.cc. It's not an obligatory method; diff --git a/storage/heap/ha_heap.cc b/storage/heap/ha_heap.cc index 9e6a7aea6c3..5831ec6167a 100644 --- a/storage/heap/ha_heap.cc +++ b/storage/heap/ha_heap.cc @@ -238,7 +238,7 @@ int ha_heap::delete_row(const byte * buf) return res; } -int ha_heap::index_read(byte * buf, const byte * key, ulonglong keypart_map, +int ha_heap::index_read(byte * buf, const byte * key, key_part_map keypart_map, enum ha_rkey_function find_flag) { DBUG_ASSERT(inited==INDEX); @@ -249,7 +249,7 @@ int ha_heap::index_read(byte * buf, const byte * key, ulonglong keypart_map, return error; } -int ha_heap::index_read_last(byte *buf, const byte *key, ulonglong keypart_map) +int ha_heap::index_read_last(byte *buf, const byte *key, key_part_map keypart_map) { DBUG_ASSERT(inited==INDEX); statistic_increment(table->in_use->status_var.ha_read_key_count, @@ -261,7 +261,7 @@ int ha_heap::index_read_last(byte *buf, const byte *key, ulonglong keypart_map) } int ha_heap::index_read_idx(byte * buf, uint index, const byte * key, - ulonglong keypart_map, + key_part_map keypart_map, enum ha_rkey_function find_flag) { statistic_increment(table->in_use->status_var.ha_read_key_count, diff --git a/storage/heap/ha_heap.h b/storage/heap/ha_heap.h index b49ded6e33d..a2d531fc515 100644 --- a/storage/heap/ha_heap.h +++ b/storage/heap/ha_heap.h @@ -75,11 +75,11 @@ public: ulonglong nb_desired_values, ulonglong *first_value, ulonglong *nb_reserved_values); - int index_read(byte * buf, const byte * key, ulonglong keypart_map, + int index_read(byte * buf, const byte * key, key_part_map keypart_map, enum ha_rkey_function find_flag); - int index_read_last(byte *buf, const byte *key, ulonglong keypart_map); + int index_read_last(byte *buf, const byte *key, key_part_map keypart_map); int index_read_idx(byte * buf, uint index, const byte * key, - ulonglong keypart_map, enum ha_rkey_function find_flag); + key_part_map keypart_map, enum ha_rkey_function find_flag); int index_next(byte * buf); int index_prev(byte * buf); int index_first(byte * buf); diff --git a/storage/heap/heapdef.h b/storage/heap/heapdef.h index d9c3ff147b4..b52a6c60ac6 100644 --- a/storage/heap/heapdef.h +++ b/storage/heap/heapdef.h @@ -90,7 +90,7 @@ extern int hp_rec_key_cmp(HP_KEYDEF *keydef,const byte *rec1, extern int hp_key_cmp(HP_KEYDEF *keydef,const byte *rec, const byte *key); extern void hp_make_key(HP_KEYDEF *keydef,byte *key,const byte *rec); -extern uint hp_rb_make_key(HP_KEYDEF *keydef, byte *key, +extern uint hp_rb_make_key(HP_KEYDEF *keydef, byte *key, const byte *rec, byte *recpos); extern uint hp_rb_key_length(HP_KEYDEF *keydef, const byte *key); extern uint hp_rb_null_key_length(HP_KEYDEF *keydef, const byte *key); @@ -99,8 +99,8 @@ extern my_bool hp_if_null_in_key(HP_KEYDEF *keyinfo, const byte *record); extern int hp_close(register HP_INFO *info); extern void hp_clear(HP_SHARE *info); extern void hp_clear_keys(HP_SHARE *info); -extern uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old, - ulonglong keypart_map); +extern uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old, + key_part_map keypart_map); #ifdef THREAD extern pthread_mutex_t THR_LOCK_heap; #else diff --git a/storage/heap/hp_hash.c b/storage/heap/hp_hash.c index 326f6adea45..fbf3e541372 100644 --- a/storage/heap/hp_hash.c +++ b/storage/heap/hp_hash.c @@ -35,7 +35,7 @@ HA_READ_KEY_EXACT Include the key in the range HA_READ_AFTER_KEY Don't include key in range - max_key.flag can have one of the following values: + max_key.flag can have one of the following values: HA_READ_BEFORE_KEY Don't include key in range HA_READ_AFTER_KEY Include all 'end_key' values in the range @@ -62,7 +62,7 @@ ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, key_range *min_key, { custom_arg.key_length= hp_rb_pack_key(keyinfo, (uchar*) info->recbuf, (uchar*) min_key->key, - min_key->length); + min_key->keypart_map); start_pos= tree_record_pos(rb_tree, info->recbuf, min_key->flag, &custom_arg); } @@ -70,12 +70,12 @@ ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, key_range *min_key, { start_pos= 0; } - + if (max_key) { custom_arg.key_length= hp_rb_pack_key(keyinfo, (uchar*) info->recbuf, (uchar*) max_key->key, - max_key->length); + max_key->keypart_map); end_pos= tree_record_pos(rb_tree, info->recbuf, max_key->flag, &custom_arg); } @@ -772,7 +772,7 @@ uint hp_rb_make_key(HP_KEYDEF *keydef, byte *key, char_length / seg->charset->mbmaxlen); set_if_smaller(char_length, seg->length); /* QQ: ok to remove? */ if (char_length < seg->length) - seg->charset->cset->fill(seg->charset, (char*) key + char_length, + seg->charset->cset->fill(seg->charset, (char*) key + char_length, seg->length - char_length, ' '); } memcpy(key, rec + seg->start, (size_t) char_length); @@ -784,11 +784,11 @@ uint hp_rb_make_key(HP_KEYDEF *keydef, byte *key, uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old, - ulonglong keypart_map) + key_part_map keypart_map) { HA_KEYSEG *seg, *endseg; uchar *start_key= key; - + for (seg= keydef->seg, endseg= seg + keydef->keysegs; seg < endseg && keypart_map; old+= seg->length, seg++) { diff --git a/storage/heap/hp_rkey.c b/storage/heap/hp_rkey.c index 98714bf875f..ced81985f99 100644 --- a/storage/heap/hp_rkey.c +++ b/storage/heap/hp_rkey.c @@ -16,7 +16,7 @@ #include "heapdef.h" int heap_rkey(HP_INFO *info, byte *record, int inx, const byte *key, - ulonglong keypart_map, enum ha_rkey_function find_flag) + key_part_map keypart_map, enum ha_rkey_function find_flag) { byte *pos; HP_SHARE *share= info->s; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 6feb8e0146d..e9309f4f8b8 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -3927,14 +3927,14 @@ statement issued by the user. We also increment trx->n_mysql_tables_in_use. 2) If prebuilt->sql_stat_start == TRUE we 'pre-compile' the MySQL search instructions to prebuilt->template of the table handle instance in -::index_read_old. The template is used to save CPU time in large joins. +::index_read. The template is used to save CPU time in large joins. 3) In row_search_for_mysql, if prebuilt->sql_stat_start is true, we allocate a new consistent read view for the trx if it does not yet have one, or in the case of a locking read, set an InnoDB 'intention' table level lock on the table. - 4) We do the SELECT. MySQL may repeatedly call ::index_read_old for the + 4) We do the SELECT. MySQL may repeatedly call ::index_read for the same table handle instance, if it is a join. 5) When the SELECT ends, MySQL removes its intention table level locks @@ -3948,7 +3948,7 @@ table handler in that case has to execute the COMMIT in ::external_lock. B) If the user has explicitly set MySQL table level locks, then MySQL does NOT call ::external_lock at the start of the statement. To determine when we are at the start of a new SQL statement we at the start of -::index_read_old also compare the query id to the latest query id where the +::index_read also compare the query id to the latest query id where the table handle instance was used. If it has changed, we know we are at the start of a new SQL statement. Since the query id can theoretically overwrap, we use this test only as a secondary way of determining the @@ -3985,7 +3985,7 @@ ha_innobase::index_read( int error; ulint ret; - DBUG_ENTER("index_read_old"); + DBUG_ENTER("index_read"); ut_a(prebuilt->trx == (trx_t*) current_thd->ha_data[ht->slot]); @@ -4067,7 +4067,7 @@ ha_innobase::index_read( } /*********************************************************************** -The following functions works like index_read_old, but it find the last +The following functions works like index_read, but it find the last row with the current key value or prefix. */ int @@ -4173,7 +4173,7 @@ ha_innobase::index_read_idx( /*************************************************************************** Reads the next or previous row from a cursor, which must have previously been -positioned using index_read_old. */ +positioned using index_read. */ int ha_innobase::general_fetch( @@ -4222,7 +4222,7 @@ ha_innobase::general_fetch( /*************************************************************************** Reads the next row from a cursor, which must have previously been -positioned using index_read_old. */ +positioned using index_read. */ int ha_innobase::index_next( @@ -4258,7 +4258,7 @@ ha_innobase::index_next_same( /*************************************************************************** Reads the previous row from a cursor, which must have previously been -positioned using index_read_old. */ +positioned using index_read. */ int ha_innobase::index_prev( diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index fb0c3eebc4d..48f1d9b2395 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -1555,7 +1555,7 @@ int ha_myisam::delete_row(const byte * buf) return mi_delete(file,buf); } -int ha_myisam::index_read(byte *buf, const byte *key, ulonglong keypart_map, +int ha_myisam::index_read(byte *buf, const byte *key, key_part_map keypart_map, enum ha_rkey_function find_flag) { DBUG_ASSERT(inited==INDEX); @@ -1567,7 +1567,7 @@ int ha_myisam::index_read(byte *buf, const byte *key, ulonglong keypart_map, } int ha_myisam::index_read_idx(byte *buf, uint index, const byte *key, - ulonglong keypart_map, + key_part_map keypart_map, enum ha_rkey_function find_flag) { statistic_increment(table->in_use->status_var.ha_read_key_count, @@ -1578,7 +1578,7 @@ int ha_myisam::index_read_idx(byte *buf, uint index, const byte *key, } int ha_myisam::index_read_last(byte *buf, const byte *key, - ulonglong keypart_map) + key_part_map keypart_map) { DBUG_ENTER("ha_myisam::index_read_last"); DBUG_ASSERT(inited==INDEX); diff --git a/storage/myisam/ha_myisam.h b/storage/myisam/ha_myisam.h index b66a9e5cca4..647e72d53eb 100644 --- a/storage/myisam/ha_myisam.h +++ b/storage/myisam/ha_myisam.h @@ -69,11 +69,11 @@ class ha_myisam: public handler int write_row(byte * buf); int update_row(const byte * old_data, byte * new_data); int delete_row(const byte * buf); - int index_read(byte *buf, const byte *key, ulonglong keypart_map, + int index_read(byte *buf, const byte *key, key_part_map keypart_map, enum ha_rkey_function find_flag); int index_read_idx(byte *buf, uint index, const byte *key, - ulonglong keypart_map, enum ha_rkey_function find_flag); - int index_read_last(byte *buf, const byte *key, ulonglong keypart_map); + key_part_map keypart_map, enum ha_rkey_function find_flag); + int index_read_last(byte *buf, const byte *key, key_part_map keypart_map); int index_next(byte * buf); int index_prev(byte * buf); int index_first(byte * buf); diff --git a/storage/myisam/mi_check.c b/storage/myisam/mi_check.c index 5c67404559e..7a4d47954a5 100644 --- a/storage/myisam/mi_check.c +++ b/storage/myisam/mi_check.c @@ -532,7 +532,7 @@ int chk_key(MI_CHECK *param, register MI_INFO *info) mi_extra(info,HA_EXTRA_KEYREAD,0); bzero(info->lastkey,keyinfo->seg->length); if (!mi_rkey(info, info->rec_buff, key, (const byte*) info->lastkey, - ULL(1), HA_READ_KEY_EXACT)) + (key_part_map)1, HA_READ_KEY_EXACT)) { /* Don't count this as a real warning, as myisamchk can't correct it */ uint save=param->warning_printed; diff --git a/storage/myisam/mi_key.c b/storage/myisam/mi_key.c index 1b7ba676139..2f4915dec39 100644 --- a/storage/myisam/mi_key.c +++ b/storage/myisam/mi_key.c @@ -216,7 +216,7 @@ uint _mi_make_key(register MI_INFO *info, uint keynr, uchar *key, */ uint _mi_pack_key(register MI_INFO *info, uint keynr, uchar *key, uchar *old, - ulonglong keypart_map, HA_KEYSEG **last_used_keyseg) + key_part_map keypart_map, HA_KEYSEG **last_used_keyseg) { uchar *start_key=key; HA_KEYSEG *keyseg; @@ -225,7 +225,7 @@ uint _mi_pack_key(register MI_INFO *info, uint keynr, uchar *key, uchar *old, /* "one part" rtree key is 2*SPDIMS part key in MyISAM */ if (info->s->keyinfo[keynr].key_alg == HA_KEY_ALG_RTREE) - keypart_map= (ULL(1) << (2*SPDIMS)) - 1; + keypart_map= (((key_part_map)1) << (2*SPDIMS)) - 1; /* only key prefixes are supported */ DBUG_ASSERT(((keypart_map+1) & keypart_map) == 0); diff --git a/storage/myisam/mi_range.c b/storage/myisam/mi_range.c index 5e5fe3c6b22..2cdb02b2c80 100644 --- a/storage/myisam/mi_range.c +++ b/storage/myisam/mi_range.c @@ -21,7 +21,7 @@ #include "myisamdef.h" #include "rt_index.h" -static ha_rows _mi_record_pos(MI_INFO *, const byte *, ulonglong, +static ha_rows _mi_record_pos(MI_INFO *, const byte *, key_part_map, enum ha_rkey_function); static double _mi_search_pos(MI_INFO *,MI_KEYDEF *,uchar *, uint,uint,my_off_t); static uint _mi_keynr(MI_INFO *info,MI_KEYDEF *,uchar *, uchar *,uint *); @@ -104,11 +104,11 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx, if (start_pos == HA_POS_ERROR || end_pos == HA_POS_ERROR) res=HA_POS_ERROR; } - + if (info->s->concurrent_insert) rw_unlock(&info->s->key_root_lock[inx]); fast_mi_writeinfo(info); - + DBUG_PRINT("info",("records: %ld",(ulong) (res))); DBUG_RETURN(res); } @@ -117,7 +117,7 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx, /* Find relative position (in records) for key in index-tree */ static ha_rows _mi_record_pos(MI_INFO *info, const byte *key, - ulonglong keypart_map, + key_part_map keypart_map, enum ha_rkey_function search_flag) { uint inx=(uint) info->lastinx, nextflag, key_len; diff --git a/storage/myisam/mi_rkey.c b/storage/myisam/mi_rkey.c index 2ff24d565b9..373ab303bf0 100644 --- a/storage/myisam/mi_rkey.c +++ b/storage/myisam/mi_rkey.c @@ -22,7 +22,7 @@ /* Ordinary search_flag is 0 ; Give error if no record with key */ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, - ulonglong keypart_map, enum ha_rkey_function search_flag) + key_part_map keypart_map, enum ha_rkey_function search_flag) { uchar *key_buff; MYISAM_SHARE *share=info->s; diff --git a/storage/myisam/myisamdef.h b/storage/myisam/myisamdef.h index f1ca1754696..7325340b970 100644 --- a/storage/myisam/myisamdef.h +++ b/storage/myisam/myisamdef.h @@ -605,7 +605,7 @@ extern my_off_t _mi_new(MI_INFO *info,MI_KEYDEF *keyinfo,int level); extern uint _mi_make_key(MI_INFO *info,uint keynr,uchar *key, const byte *record,my_off_t filepos); extern uint _mi_pack_key(register MI_INFO *info, uint keynr, uchar *key, - uchar *old, ulonglong keypart_map, + uchar *old, key_part_map keypart_map, HA_KEYSEG **last_used_keyseg); extern int _mi_read_key_record(MI_INFO *info,my_off_t filepos,byte *buf); extern int _mi_read_cache(IO_CACHE *info,byte *buff,my_off_t pos, diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index df77931ddb5..96f7db6e633 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -179,7 +179,7 @@ int ha_myisammrg::delete_row(const byte * buf) } int ha_myisammrg::index_read(byte * buf, const byte * key, - ulonglong keypart_map, + key_part_map keypart_map, enum ha_rkey_function find_flag) { statistic_increment(table->in_use->status_var.ha_read_key_count, @@ -190,7 +190,7 @@ int ha_myisammrg::index_read(byte * buf, const byte * key, } int ha_myisammrg::index_read_idx(byte * buf, uint index, const byte * key, - ulonglong keypart_map, + key_part_map keypart_map, enum ha_rkey_function find_flag) { statistic_increment(table->in_use->status_var.ha_read_key_count, @@ -201,7 +201,7 @@ int ha_myisammrg::index_read_idx(byte * buf, uint index, const byte * key, } int ha_myisammrg::index_read_last(byte * buf, const byte * key, - ulonglong keypart_map) + key_part_map keypart_map) { statistic_increment(table->in_use->status_var.ha_read_key_count, &LOCK_status); diff --git a/storage/myisammrg/ha_myisammrg.h b/storage/myisammrg/ha_myisammrg.h index 805a2cb04b6..7bbe659d4b7 100644 --- a/storage/myisammrg/ha_myisammrg.h +++ b/storage/myisammrg/ha_myisammrg.h @@ -56,11 +56,11 @@ class ha_myisammrg: public handler int write_row(byte * buf); int update_row(const byte * old_data, byte * new_data); int delete_row(const byte * buf); - int index_read(byte * buf, const byte * key, ulonglong keypart_map, + int index_read(byte * buf, const byte * key, key_part_map keypart_map, enum ha_rkey_function find_flag); int index_read_idx(byte * buf, uint index, const byte * key, - ulonglong keypart_map, enum ha_rkey_function find_flag); - int index_read_last(byte * buf, const byte * key, ulonglong keypart_map); + key_part_map keypart_map, enum ha_rkey_function find_flag); + int index_read_last(byte * buf, const byte * key, key_part_map keypart_map); int index_next(byte * buf); int index_prev(byte * buf); int index_first(byte * buf); diff --git a/storage/myisammrg/myrg_rkey.c b/storage/myisammrg/myrg_rkey.c index 2273f7d62b8..0eefe7eb173 100644 --- a/storage/myisammrg/myrg_rkey.c +++ b/storage/myisammrg/myrg_rkey.c @@ -36,7 +36,7 @@ */ int myrg_rkey(MYRG_INFO *info,byte *buf,int inx, const byte *key, - ulonglong keypart_map, enum ha_rkey_function search_flag) + key_part_map keypart_map, enum ha_rkey_function search_flag) { byte *key_buff; uint pack_key_length; |