diff options
author | unknown <serg@janus.mylan> | 2007-01-29 10:40:26 +0100 |
---|---|---|
committer | unknown <serg@janus.mylan> | 2007-01-29 10:40:26 +0100 |
commit | 57c50bacbc8da95493960a17da0a8722152fe387 (patch) | |
tree | f14bd08181ddd81d2a41f06d9bf0f11d6edf53b5 /storage | |
parent | 8272457ed299ce920a5b33433658ce84014f1814 (diff) | |
download | mariadb-git-57c50bacbc8da95493960a17da0a8722152fe387.tar.gz |
WL#3700: Handler API change: all index search methods - that is,
index_read(), index_read_idx(), index_read_last(), and
records_in_range() - instead of 'uint keylen' argument take
'ulonglong keypart_map', a bitmap showing which keyparts are
present in the key value.
Fallback method is provided for handlers that are lagging behind.
Diffstat (limited to 'storage')
-rw-r--r-- | storage/blackhole/ha_blackhole.cc | 9 | ||||
-rw-r--r-- | storage/blackhole/ha_blackhole.h | 7 | ||||
-rw-r--r-- | storage/example/ha_example.cc | 5 | ||||
-rw-r--r-- | storage/example/ha_example.h | 2 | ||||
-rw-r--r-- | storage/federated/ha_federated.cc | 5 | ||||
-rw-r--r-- | storage/heap/ha_heap.cc | 13 | ||||
-rw-r--r-- | storage/heap/ha_heap.h | 10 | ||||
-rw-r--r-- | storage/heap/heapdef.h | 2 | ||||
-rw-r--r-- | storage/heap/hp_hash.c | 12 | ||||
-rw-r--r-- | storage/heap/hp_rkey.c | 4 | ||||
-rw-r--r-- | storage/innobase/handler/ha_innodb.cc | 16 | ||||
-rw-r--r-- | storage/myisam/ha_myisam.cc | 26 | ||||
-rw-r--r-- | storage/myisam/ha_myisam.h | 10 | ||||
-rw-r--r-- | storage/myisam/mi_check.c | 2 | ||||
-rw-r--r-- | storage/myisam/mi_key.c | 51 | ||||
-rw-r--r-- | storage/myisam/mi_range.c | 42 | ||||
-rw-r--r-- | storage/myisam/mi_rkey.c | 17 | ||||
-rw-r--r-- | storage/myisam/myisamdef.h | 5 | ||||
-rw-r--r-- | storage/myisam/rt_test.c | 2 | ||||
-rw-r--r-- | storage/myisam/sp_test.c | 2 | ||||
-rw-r--r-- | storage/myisammrg/ha_myisammrg.cc | 15 | ||||
-rw-r--r-- | storage/myisammrg/ha_myisammrg.h | 10 | ||||
-rw-r--r-- | storage/myisammrg/myrg_rkey.c | 6 |
23 files changed, 123 insertions, 150 deletions
diff --git a/storage/blackhole/ha_blackhole.cc b/storage/blackhole/ha_blackhole.cc index 7bdb4e40b3d..b128ab16cc7 100644 --- a/storage/blackhole/ha_blackhole.cc +++ b/storage/blackhole/ha_blackhole.cc @@ -152,7 +152,8 @@ THR_LOCK_DATA **ha_blackhole::store_lock(THD *thd, int ha_blackhole::index_read(byte * buf, const byte * key, - uint key_len, enum ha_rkey_function find_flag) + ulonglong keypart_map, uint key_len, + enum ha_rkey_function find_flag) { DBUG_ENTER("ha_blackhole::index_read"); DBUG_RETURN(0); @@ -160,14 +161,16 @@ int ha_blackhole::index_read(byte * buf, const byte * key, int ha_blackhole::index_read_idx(byte * buf, uint idx, const byte * key, - uint key_len, enum ha_rkey_function find_flag) + ulonglong keypart_map, uint key_len, + enum ha_rkey_function find_flag) { DBUG_ENTER("ha_blackhole::index_read_idx"); DBUG_RETURN(HA_ERR_END_OF_FILE); } -int ha_blackhole::index_read_last(byte * buf, const byte * key, uint key_len) +int ha_blackhole::index_read_last(byte * buf, const byte * key, + ulonglong 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 5388dcfc187..cd8b6491dba 100644 --- a/storage/blackhole/ha_blackhole.h +++ b/storage/blackhole/ha_blackhole.h @@ -64,11 +64,12 @@ 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, + int index_read(byte * buf, const byte * key, ulonglong keypart_map, uint key_len, enum ha_rkey_function find_flag); int index_read_idx(byte * buf, uint idx, const byte * key, - uint key_len, enum ha_rkey_function find_flag); - int index_read_last(byte * buf, const byte * key, uint key_len); + ulonglong keypart_map, uint key_len, + enum ha_rkey_function find_flag); + int index_read_last(byte * buf, const byte * key, ulonglong 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 12ca91f0a6f..65554eb1252 100644 --- a/storage/example/ha_example.cc +++ b/storage/example/ha_example.cc @@ -90,14 +90,13 @@ static handler *example_create_handler(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root); -static int example_init_func(); +static int example_init_func(void *); handlerton *example_hton; /* Variables for example share methods */ static HASH example_open_tables; ///< Hash used to track the number of open tables; variable for example share methods pthread_mutex_t example_mutex; ///< This is the mutex used to init the hash; variable for example share methods -static int example_init= 0; ///< This variable is used to check the init state of hash; variable for example share methods /** @brief Function we use in the creation of our hash to get key. @@ -372,7 +371,7 @@ int ha_example::delete_row(const byte * buf) index. */ int ha_example::index_read(byte * buf, const byte * key, - uint key_len __attribute__((unused)), + ulonglong 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 9b912514887..ee60b412974 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, - uint key_len, enum ha_rkey_function find_flag); + ulonglong 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/federated/ha_federated.cc b/storage/federated/ha_federated.cc index 9290418c7aa..cb599715b9d 100644 --- a/storage/federated/ha_federated.cc +++ b/storage/federated/ha_federated.cc @@ -362,7 +362,7 @@ static handler *federated_create_handler(handlerton *hton, MEM_ROOT *mem_root); static int federated_commit(handlerton *hton, THD *thd, bool all); static int federated_rollback(handlerton *hton, THD *thd, bool all); -static int federated_db_init(void); +static int federated_db_init(void *); /* Federated storage engine handlerton */ @@ -573,9 +573,6 @@ int get_connection(FEDERATED_SHARE *share) int error_num= ER_FOREIGN_SERVER_DOESNT_EXIST; char error_buffer[FEDERATED_QUERY_BUFFER_SIZE]; FOREIGN_SERVER *server; - MYSQL *mysql_conn= 0; - MYSQL_RES *result= 0; - MYSQL_ROW row= 0; DBUG_ENTER("ha_federated::get_connection"); if (!(server= diff --git a/storage/heap/ha_heap.cc b/storage/heap/ha_heap.cc index 7a2f8e20c56..c0ca0af3923 100644 --- a/storage/heap/ha_heap.cc +++ b/storage/heap/ha_heap.cc @@ -238,34 +238,35 @@ int ha_heap::delete_row(const byte * buf) return res; } -int ha_heap::index_read(byte * buf, const byte * key, uint key_len, +int ha_heap::index_read(byte * buf, const byte * key, ulonglong keypart_map, enum ha_rkey_function find_flag) { DBUG_ASSERT(inited==INDEX); statistic_increment(table->in_use->status_var.ha_read_key_count, &LOCK_status); - int error = heap_rkey(file,buf,active_index, key, key_len, find_flag); + int error = heap_rkey(file,buf,active_index, key, keypart_map, find_flag); table->status = error ? STATUS_NOT_FOUND : 0; return error; } -int ha_heap::index_read_last(byte *buf, const byte *key, uint key_len) +int ha_heap::index_read_last(byte *buf, const byte *key, ulonglong keypart_map) { DBUG_ASSERT(inited==INDEX); statistic_increment(table->in_use->status_var.ha_read_key_count, &LOCK_status); - int error= heap_rkey(file, buf, active_index, key, key_len, + int error= heap_rkey(file, buf, active_index, key, keypart_map, HA_READ_PREFIX_LAST); table->status= error ? STATUS_NOT_FOUND : 0; return error; } int ha_heap::index_read_idx(byte * buf, uint index, const byte * key, - uint key_len, enum ha_rkey_function find_flag) + ulonglong keypart_map, + enum ha_rkey_function find_flag) { statistic_increment(table->in_use->status_var.ha_read_key_count, &LOCK_status); - int error = heap_rkey(file, buf, index, key, key_len, find_flag); + int error = heap_rkey(file, buf, index, key, keypart_map, find_flag); table->status = error ? STATUS_NOT_FOUND : 0; return error; } diff --git a/storage/heap/ha_heap.h b/storage/heap/ha_heap.h index 2de80c76999..b49ded6e33d 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, - uint key_len, enum ha_rkey_function find_flag); - int index_read_idx(byte * buf, uint idx, const byte * key, - uint key_len, enum ha_rkey_function find_flag); - int index_read_last(byte * buf, const byte * key, uint key_len); + int index_read(byte * buf, const byte * key, ulonglong keypart_map, + enum ha_rkey_function find_flag); + int index_read_last(byte *buf, const byte *key, ulonglong keypart_map); + int index_read_idx(byte * buf, uint index, const byte * key, + ulonglong 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 016c83db8e0..d9c3ff147b4 100644 --- a/storage/heap/heapdef.h +++ b/storage/heap/heapdef.h @@ -100,7 +100,7 @@ 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, - uint k_len); + ulonglong 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 c5a30a3ef65..326f6adea45 100644 --- a/storage/heap/hp_hash.c +++ b/storage/heap/hp_hash.c @@ -784,30 +784,26 @@ uint hp_rb_make_key(HP_KEYDEF *keydef, byte *key, uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old, - uint k_len) + ulonglong keypart_map) { HA_KEYSEG *seg, *endseg; uchar *start_key= key; for (seg= keydef->seg, endseg= seg + keydef->keysegs; - seg < endseg && (int) k_len > 0; old+= seg->length, seg++) + seg < endseg && keypart_map; old+= seg->length, seg++) { uint char_length; + keypart_map>>= 1; if (seg->null_bit) { - k_len--; if (!(*key++= (char) 1 - *old++)) - { - k_len-= seg->length; continue; } - } if (seg->flag & HA_SWAP_KEY) { uint length= seg->length; byte *pos= (byte*) old + length; - k_len-= length; while (length--) { *key++= *--pos; @@ -822,7 +818,6 @@ uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old, CHARSET_INFO *cs= seg->charset; char_length= length/cs->mbmaxlen; - k_len-= 2+length; old+= 2; set_if_smaller(length,tmp_length); /* Safety */ FIX_LENGTH(cs, old, length, char_length); @@ -843,7 +838,6 @@ uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old, } memcpy(key, old, (size_t) char_length); key+= seg->length; - k_len-= seg->length; } return (uint) (key - start_key); } diff --git a/storage/heap/hp_rkey.c b/storage/heap/hp_rkey.c index a095336d295..98714bf875f 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, - uint key_len, enum ha_rkey_function find_flag) + ulonglong keypart_map, enum ha_rkey_function find_flag) { byte *pos; HP_SHARE *share= info->s; @@ -38,7 +38,7 @@ int heap_rkey(HP_INFO *info, byte *record, int inx, const byte *key, custom_arg.keyseg= info->s->keydef[inx].seg; custom_arg.key_length= info->lastkey_len= hp_rb_pack_key(keyinfo, (uchar*) info->lastkey, - (uchar*) key, key_len); + (uchar*) key, keypart_map); custom_arg.search_flag= SEARCH_FIND | SEARCH_SAME; /* for next rkey() after deletion */ if (find_flag == HA_READ_AFTER_KEY) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index b5b354d4b39..bebd0422a24 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -3920,14 +3920,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. The template is used to save CPU time in large joins. +::index_read_old. 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 for the + 4) We do the SELECT. MySQL may repeatedly call ::index_read_old for the same table handle instance, if it is a join. 5) When the SELECT ends, MySQL removes its intention table level locks @@ -3941,7 +3941,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 also compare the query id to the latest query id where the +::index_read_old 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 @@ -3978,7 +3978,7 @@ ha_innobase::index_read( int error; ulint ret; - DBUG_ENTER("index_read"); + DBUG_ENTER("index_read_old"); ut_a(prebuilt->trx == (trx_t*) current_thd->ha_data[ht->slot]); @@ -4060,7 +4060,7 @@ ha_innobase::index_read( } /*********************************************************************** -The following functions works like index_read, but it find the last +The following functions works like index_read_old, but it find the last row with the current key value or prefix. */ int @@ -4166,7 +4166,7 @@ ha_innobase::index_read_idx( /*************************************************************************** Reads the next or previous row from a cursor, which must have previously been -positioned using index_read. */ +positioned using index_read_old. */ int ha_innobase::general_fetch( @@ -4215,7 +4215,7 @@ ha_innobase::general_fetch( /*************************************************************************** Reads the next row from a cursor, which must have previously been -positioned using index_read. */ +positioned using index_read_old. */ int ha_innobase::index_next( @@ -4251,7 +4251,7 @@ ha_innobase::index_next_same( /*************************************************************************** Reads the previous row from a cursor, which must have previously been -positioned using index_read. */ +positioned using index_read_old. */ int ha_innobase::index_prev( diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 397856a4a4e..83180872f5f 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -1203,34 +1203,37 @@ int ha_myisam::delete_row(const byte * buf) return mi_delete(file,buf); } -int ha_myisam::index_read(byte * buf, const byte * key, - uint key_len, enum ha_rkey_function find_flag) +int ha_myisam::index_read(byte *buf, const byte *key, ulonglong keypart_map, + enum ha_rkey_function find_flag) { DBUG_ASSERT(inited==INDEX); statistic_increment(table->in_use->status_var.ha_read_key_count, &LOCK_status); - int error=mi_rkey(file,buf,active_index, key, key_len, find_flag); + int error=mi_rkey(file, buf, active_index, key, keypart_map, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; return error; } -int ha_myisam::index_read_idx(byte * buf, uint index, const byte * key, - uint key_len, enum ha_rkey_function find_flag) +int ha_myisam::index_read_idx(byte *buf, uint index, const byte *key, + ulonglong keypart_map, + enum ha_rkey_function find_flag) { statistic_increment(table->in_use->status_var.ha_read_key_count, &LOCK_status); - int error=mi_rkey(file,buf,index, key, key_len, find_flag); + int error=mi_rkey(file, buf, index, key, keypart_map, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; return error; } -int ha_myisam::index_read_last(byte * buf, const byte * key, uint key_len) +int ha_myisam::index_read_last(byte *buf, const byte *key, + ulonglong keypart_map) { DBUG_ENTER("ha_myisam::index_read_last"); DBUG_ASSERT(inited==INDEX); statistic_increment(table->in_use->status_var.ha_read_key_count, &LOCK_status); - int error=mi_rkey(file,buf,active_index, key, key_len, HA_READ_PREFIX_LAST); + int error=mi_rkey(file, buf, active_index, key, keypart_map, + HA_READ_PREFIX_LAST); table->status=error ? STATUS_NOT_FOUND: 0; DBUG_RETURN(error); } @@ -1338,7 +1341,7 @@ int ha_myisam::info(uint flag) stats.index_file_length=info.index_file_length; stats.delete_length = info.delete_length; stats.check_time = info.check_time; - stats. mean_rec_length=info.mean_reclength; + stats.mean_rec_length=info.mean_reclength; } if (flag & HA_STATUS_CONST) { @@ -1698,8 +1701,9 @@ void ha_myisam::get_auto_increment(ulonglong offset, ulonglong increment, key_copy(key, table->record[0], table->key_info + table->s->next_number_index, table->s->next_number_key_offset); - error= mi_rkey(file,table->record[1],(int) table->s->next_number_index, - key,table->s->next_number_key_offset,HA_READ_PREFIX_LAST); + error= mi_rkey(file, table->record[1], (int) table->s->next_number_index, + key, make_prev_keypart_map(table->s->next_number_keypart), + HA_READ_PREFIX_LAST); if (error) nr= 1; else diff --git a/storage/myisam/ha_myisam.h b/storage/myisam/ha_myisam.h index 882900bd35f..b66a9e5cca4 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, - uint key_len, enum ha_rkey_function find_flag); - int index_read_idx(byte * buf, uint idx, const byte * key, - uint key_len, enum ha_rkey_function find_flag); - int index_read_last(byte * buf, const byte * key, uint key_len); + int index_read(byte *buf, const byte *key, ulonglong 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); 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 7bcb8041fe0..5c67404559e 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, - keyinfo->seg->length, HA_READ_KEY_EXACT)) + ULL(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 b203286d544..1b7ba676139 100644 --- a/storage/myisam/mi_key.c +++ b/storage/myisam/mi_key.c @@ -206,7 +206,7 @@ uint _mi_make_key(register MI_INFO *info, uint keynr, uchar *key, uint keynr key number key Store packed key here old Not packed key - k_length Length of 'old' to use + keypart_map bitmap of used keyparts last_used_keyseg out parameter. May be NULL RETURN @@ -216,34 +216,36 @@ 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, - uint k_length, HA_KEYSEG **last_used_keyseg) + ulonglong keypart_map, HA_KEYSEG **last_used_keyseg) { uchar *start_key=key; HA_KEYSEG *keyseg; my_bool is_ft= info->s->keyinfo[keynr].flag & HA_FULLTEXT; DBUG_ENTER("_mi_pack_key"); - for (keyseg=info->s->keyinfo[keynr].seg ; - keyseg->type && (int) k_length > 0; - old+=keyseg->length, keyseg++) + /* "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; + + /* only key prefixes are supported */ + DBUG_ASSERT(((keypart_map+1) & keypart_map) == 0); + + for (keyseg= info->s->keyinfo[keynr].seg ; keyseg->type && keypart_map; + old+= keyseg->length, keyseg++) { - enum ha_base_keytype type=(enum ha_base_keytype) keyseg->type; - uint length=min((uint) keyseg->length,(uint) k_length); + enum ha_base_keytype type= (enum ha_base_keytype) keyseg->type; + uint length= keyseg->length; uint char_length; uchar *pos; CHARSET_INFO *cs=keyseg->charset; + keypart_map>>= 1; if (keyseg->null_bit) { - k_length--; if (!(*key++= (char) 1-*old++)) /* Copy null marker */ { - k_length-=length; if (keyseg->flag & (HA_VAR_LENGTH_PART | HA_BLOB_PART)) - { - k_length-=2; /* Skip length */ old+= 2; - } continue; /* Found NULL */ } } @@ -262,7 +264,6 @@ uint _mi_pack_key(register MI_INFO *info, uint keynr, uchar *key, uchar *old, while (pos < end && pos[0] == ' ') pos++; } - k_length-=length; length=(uint) (end-pos); FIX_LENGTH(cs, pos, length, char_length); store_key_length_inc(key,char_length); @@ -274,7 +275,6 @@ uint _mi_pack_key(register MI_INFO *info, uint keynr, uchar *key, uchar *old, { /* Length of key-part used with mi_rkey() always 2 */ uint tmp_length=uint2korr(pos); - k_length-= 2+length; pos+=2; set_if_smaller(length,tmp_length); /* Safety */ FIX_LENGTH(cs, pos, length, char_length); @@ -287,11 +287,8 @@ uint _mi_pack_key(register MI_INFO *info, uint keynr, uchar *key, uchar *old, else if (keyseg->flag & HA_SWAP_KEY) { /* Numerical column */ pos+=length; - k_length-=length; while (length--) - { *key++ = *--pos; - } continue; } FIX_LENGTH(cs, pos, length, char_length); @@ -299,30 +296,10 @@ uint _mi_pack_key(register MI_INFO *info, uint keynr, uchar *key, uchar *old, if (length > char_length) cs->cset->fill(cs, (char*) key+char_length, length-char_length, ' '); key+= length; - k_length-=length; } if (last_used_keyseg) *last_used_keyseg= keyseg; -#ifdef NOT_USED - if (keyseg->type) - { - /* Part-key ; fill with ASCII 0 for easier searching */ - length= (uint) -k_length; /* unused part of last key */ - do - { - if (keyseg->flag & HA_NULL_PART) - length++; - if (keyseg->flag & HA_SPACE_PACK) - length+=2; - else - length+= keyseg->length; - keyseg++; - } while (keyseg->type); - bzero((byte*) key,length); - key+=length; - } -#endif DBUG_RETURN((uint) (key-start_key)); } /* _mi_pack_key */ diff --git a/storage/myisam/mi_range.c b/storage/myisam/mi_range.c index 6655f5a7de6..5e5fe3c6b22 100644 --- a/storage/myisam/mi_range.c +++ b/storage/myisam/mi_range.c @@ -21,13 +21,10 @@ #include "myisamdef.h" #include "rt_index.h" -static ha_rows _mi_record_pos(MI_INFO *info,const byte *key,uint key_len, - enum ha_rkey_function search_flag); -static double _mi_search_pos(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key, - uint key_len,uint nextflag,my_off_t pos); -static uint _mi_keynr(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *page, - uchar *keypos,uint *ret_max_key); - +static ha_rows _mi_record_pos(MI_INFO *, const byte *, ulonglong, + 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 *); /* Estimate how many records there is in a given range @@ -47,9 +44,8 @@ static uint _mi_keynr(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *page, number Estimated number of rows */ - -ha_rows mi_records_in_range(MI_INFO *info, int inx, key_range *min_key, - key_range *max_key) +ha_rows mi_records_in_range(MI_INFO *info, int inx, + key_range *min_key, key_range *max_key) { ha_rows start_pos,end_pos,res; DBUG_ENTER("mi_records_in_range"); @@ -87,7 +83,7 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx, key_range *min_key, } key_buff= info->lastkey+info->s->base.max_key_length; start_key_len= _mi_pack_key(info,inx, key_buff, - (uchar*) min_key->key, min_key->length, + (uchar*) min_key->key, min_key->keypart_map, (HA_KEYSEG**) 0); res= rtree_estimate(info, inx, key_buff, start_key_len, myisam_read_vec[min_key->flag]); @@ -97,14 +93,12 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx, key_range *min_key, #endif case HA_KEY_ALG_BTREE: default: - start_pos= (min_key ? - _mi_record_pos(info, min_key->key, min_key->length, - min_key->flag) : - (ha_rows) 0); - end_pos= (max_key ? - _mi_record_pos(info, max_key->key, max_key->length, - max_key->flag) : - info->state->records+ (ha_rows) 1); + start_pos= (min_key ? _mi_record_pos(info, min_key->key, + min_key->keypart_map, min_key->flag) + : (ha_rows) 0); + end_pos= (max_key ? _mi_record_pos(info, max_key->key, + max_key->keypart_map, max_key->flag) + : info->state->records + (ha_rows) 1); res= (end_pos < start_pos ? (ha_rows) 0 : (end_pos == start_pos ? (ha_rows) 1 : end_pos-start_pos)); if (start_pos == HA_POS_ERROR || end_pos == HA_POS_ERROR) @@ -122,21 +116,21 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx, key_range *min_key, /* Find relative position (in records) for key in index-tree */ -static ha_rows _mi_record_pos(MI_INFO *info, const byte *key, uint key_len, +static ha_rows _mi_record_pos(MI_INFO *info, const byte *key, + ulonglong keypart_map, enum ha_rkey_function search_flag) { - uint inx=(uint) info->lastinx, nextflag; + uint inx=(uint) info->lastinx, nextflag, key_len; MI_KEYDEF *keyinfo=info->s->keyinfo+inx; uchar *key_buff; double pos; DBUG_ENTER("_mi_record_pos"); DBUG_PRINT("enter",("search_flag: %d",search_flag)); + DBUG_ASSERT(keypart_map); - if (key_len == 0) - key_len=USE_WHOLE_KEY; key_buff=info->lastkey+info->s->base.max_key_length; - key_len=_mi_pack_key(info,inx,key_buff,(uchar*) key,key_len, + key_len=_mi_pack_key(info,inx,key_buff,(uchar*) key, keypart_map, (HA_KEYSEG**) 0); DBUG_EXECUTE("key",_mi_print_key(DBUG_FILE,keyinfo->seg, (uchar*) key_buff,key_len);); diff --git a/storage/myisam/mi_rkey.c b/storage/myisam/mi_rkey.c index 6323c95ffd7..027d3d8dea0 100644 --- a/storage/myisam/mi_rkey.c +++ b/storage/myisam/mi_rkey.c @@ -21,8 +21,8 @@ /* Read a record using key */ /* 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, uint key_len, - enum ha_rkey_function search_flag) +int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, + ulonglong keypart_map, enum ha_rkey_function search_flag) { uchar *key_buff; MYISAM_SHARE *share=info->s; @@ -30,8 +30,8 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len, HA_KEYSEG *last_used_keyseg; uint pack_key_length, use_key_length, nextflag; DBUG_ENTER("mi_rkey"); - DBUG_PRINT("enter", ("base: %lx buf: %lx inx: %d search_flag: %d", - (long) info, (long) buf, inx, search_flag)); + DBUG_PRINT("enter", ("base: %lx buf: %lx inx: %d keyparts %lx search_flag: %d", + (long) info, (long) buf, inx, keypart_map, search_flag)); if ((inx = _mi_check_index(info,inx)) < 0) DBUG_RETURN(my_errno); @@ -47,18 +47,17 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len, key is already packed!; This happens when we are using a MERGE TABLE */ key_buff=info->lastkey+info->s->base.max_key_length; - pack_key_length= key_len; - bmove(key_buff,key,key_len); + pack_key_length= keypart_map; + bmove(key_buff, key, pack_key_length); last_used_keyseg= 0; } else { - if (key_len == 0) - key_len=USE_WHOLE_KEY; + DBUG_ASSERT(keypart_map); /* Save the packed key for later use in the second buffer of lastkey. */ key_buff=info->lastkey+info->s->base.max_key_length; pack_key_length=_mi_pack_key(info,(uint) inx, key_buff, (uchar*) key, - key_len, &last_used_keyseg); + keypart_map, &last_used_keyseg); /* Save packed_key_length for use by the MERGE engine. */ info->pack_key_length= pack_key_length; DBUG_EXECUTE("key",_mi_print_key(DBUG_FILE, keyinfo->seg, diff --git a/storage/myisam/myisamdef.h b/storage/myisam/myisamdef.h index dceccd10ae2..f1ca1754696 100644 --- a/storage/myisam/myisamdef.h +++ b/storage/myisam/myisamdef.h @@ -604,8 +604,9 @@ extern int _mi_dispose(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t pos, 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(MI_INFO *info,uint keynr,uchar *key,uchar *old, - uint key_length, HA_KEYSEG **last_used_keyseg); +extern uint _mi_pack_key(register MI_INFO *info, uint keynr, uchar *key, + uchar *old, ulonglong 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, uint length,int re_read_if_possibly); diff --git a/storage/myisam/rt_test.c b/storage/myisam/rt_test.c index 1126266d2f9..55b52c0c3bf 100644 --- a/storage/myisam/rt_test.c +++ b/storage/myisam/rt_test.c @@ -323,7 +323,7 @@ static int run_test(const char *filename) range.key= record+1; range.length= 1000; /* Big enough */ range.flag= HA_READ_MBR_INTERSECT; - hrows= mi_records_in_range(file,0, &range, (key_range*) 0); + hrows= mi_records_in_range(file, 0, &range, (key_range*) 0); printf(" %ld rows\n", (long) hrows); if (mi_close(file)) goto err; diff --git a/storage/myisam/sp_test.c b/storage/myisam/sp_test.c index c7226589811..96ba05e8a74 100644 --- a/storage/myisam/sp_test.c +++ b/storage/myisam/sp_test.c @@ -255,7 +255,7 @@ int run_test(const char *filename) max_range.key= record+1; max_range.length= 1000; /* Big enough */ max_range.flag= HA_READ_KEY_EXACT; - hrows= mi_records_in_range(file,0, &min_range, &max_range); + hrows= mi_records_in_range(file, 0, &min_range, &max_range); printf(" %ld rows\n", (long) hrows); if (mi_close(file)) goto err; diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index 7df81a4802f..9ed24f35aba 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -145,30 +145,33 @@ int ha_myisammrg::delete_row(const byte * buf) } int ha_myisammrg::index_read(byte * buf, const byte * key, - uint key_len, enum ha_rkey_function find_flag) + ulonglong keypart_map, + enum ha_rkey_function find_flag) { statistic_increment(table->in_use->status_var.ha_read_key_count, &LOCK_status); - int error=myrg_rkey(file,buf,active_index, key, key_len, find_flag); + int error=myrg_rkey(file,buf,active_index, key, keypart_map, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; return error; } int ha_myisammrg::index_read_idx(byte * buf, uint index, const byte * key, - uint key_len, enum ha_rkey_function find_flag) + ulonglong keypart_map, + enum ha_rkey_function find_flag) { statistic_increment(table->in_use->status_var.ha_read_key_count, &LOCK_status); - int error=myrg_rkey(file,buf,index, key, key_len, find_flag); + int error=myrg_rkey(file,buf,index, key, keypart_map, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; return error; } -int ha_myisammrg::index_read_last(byte * buf, const byte * key, uint key_len) +int ha_myisammrg::index_read_last(byte * buf, const byte * key, + ulonglong keypart_map) { statistic_increment(table->in_use->status_var.ha_read_key_count, &LOCK_status); - int error=myrg_rkey(file,buf,active_index, key, key_len, + int error=myrg_rkey(file,buf,active_index, key, keypart_map, HA_READ_PREFIX_LAST); table->status=error ? STATUS_NOT_FOUND: 0; return error; diff --git a/storage/myisammrg/ha_myisammrg.h b/storage/myisammrg/ha_myisammrg.h index ffa55673ad1..ee2a46e3d00 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, - uint key_len, enum ha_rkey_function find_flag); - int index_read_idx(byte * buf, uint idx, const byte * key, - uint key_len, enum ha_rkey_function find_flag); - int index_read_last(byte * buf, const byte * key, uint key_len); + int index_read(byte * buf, const byte * key, ulonglong 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); 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 f7b7f082019..2273f7d62b8 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, - uint key_len, enum ha_rkey_function search_flag) + ulonglong keypart_map, enum ha_rkey_function search_flag) { byte *key_buff; uint pack_key_length; @@ -56,7 +56,7 @@ int myrg_rkey(MYRG_INFO *info,byte *buf,int inx, const byte *key, if (table == info->open_tables) { - err=mi_rkey(mi,0,inx,key,key_len,search_flag); + err=mi_rkey(mi, 0, inx, key, keypart_map, search_flag); /* Get the saved packed key and packed key length. */ key_buff=(byte*) mi->lastkey+mi->s->base.max_key_length; pack_key_length=mi->pack_key_length; @@ -64,7 +64,7 @@ int myrg_rkey(MYRG_INFO *info,byte *buf,int inx, const byte *key, else { mi->once_flags|= USE_PACKED_KEYS; - err=mi_rkey(mi,0,inx,key_buff,pack_key_length,search_flag); + err=mi_rkey(mi, 0, inx, key_buff, pack_key_length, search_flag); } info->last_used_table=table+1; |