diff options
author | unknown <ram@mysql.r18.ru> | 2002-10-07 17:49:03 +0500 |
---|---|---|
committer | unknown <ram@mysql.r18.ru> | 2002-10-07 17:49:03 +0500 |
commit | 9195963f56122b3ca7fa480607b8da9ae969a364 (patch) | |
tree | ebf4b60cc6d75288281e8c8da41994ba6bc7d89f /heap | |
parent | 9e5a4be4605cf71c5e3d6c07283c95fc4f29db70 (diff) | |
download | mariadb-git-9195963f56122b3ca7fa480607b8da9ae969a364.tar.gz |
auto_increment for heap tables
test case
heap/hp_create.c:
auto_increment for heap tables
heap/hp_hash.c:
auto_increment for heap tables
heap/hp_info.c:
auto_increment for heap tables
heap/hp_test1.c:
auto_increment for heap tables
heap/hp_test2.c:
auto_increment for heap tables
heap/hp_update.c:
auto_increment for heap tables
heap/hp_write.c:
auto_increment for heap tables
include/heap.h:
auto_increment for heap tables
mysql-test/r/create.result:
auto_increment for heap tables
mysql-test/t/create.test:
auto_increment for heap tables
sql/ha_heap.cc:
auto_increment for heap tables
sql/ha_heap.h:
auto_increment for heap tables
Diffstat (limited to 'heap')
-rw-r--r-- | heap/hp_create.c | 6 | ||||
-rw-r--r-- | heap/hp_hash.c | 48 | ||||
-rw-r--r-- | heap/hp_info.c | 2 | ||||
-rw-r--r-- | heap/hp_test1.c | 6 | ||||
-rw-r--r-- | heap/hp_test2.c | 7 | ||||
-rw-r--r-- | heap/hp_update.c | 12 | ||||
-rw-r--r-- | heap/hp_write.c | 2 |
7 files changed, 75 insertions, 8 deletions
diff --git a/heap/hp_create.c b/heap/hp_create.c index 7eee6eaa64d..6c38d54cb12 100644 --- a/heap/hp_create.c +++ b/heap/hp_create.c @@ -21,7 +21,8 @@ static void init_block(HP_BLOCK *block,uint reclength,ulong min_records, ulong max_records); int heap_create(const char *name, uint keys, HP_KEYDEF *keydef, - uint reclength, ulong max_records, ulong min_records) + uint reclength, ulong max_records, ulong min_records, + HP_CREATE_INFO *create_info) { uint i, j, key_segs, max_length, length; HP_SHARE *share; @@ -120,6 +121,9 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef, share->keys= keys; share->max_key_length= max_length; share->changed= 0; + share->auto_key= create_info->auto_key; + share->auto_key_type= create_info->auto_key_type; + share->auto_increment= create_info->auto_increment; if (!(share->name= my_strdup(name,MYF(0)))) { my_free((gptr) share,MYF(0)); diff --git a/heap/hp_hash.c b/heap/hp_hash.c index 4f7dc956cba..0145e0d503c 100644 --- a/heap/hp_hash.c +++ b/heap/hp_hash.c @@ -537,3 +537,51 @@ my_bool hp_if_null_in_key(HP_KEYDEF *keydef, const byte *record) } return 0; } + +void heap_update_auto_increment(HP_INFO *info, const byte *record) +{ + ulonglong value; + HA_KEYSEG *keyseg= info->s->keydef[info->s->auto_key - 1].seg; + const uchar *key= (uchar*) record + keyseg->start; + + switch (info->s->auto_key_type) { + case HA_KEYTYPE_INT8: + case HA_KEYTYPE_BINARY: + value= (ulonglong) *(uchar*) key; + break; + case HA_KEYTYPE_SHORT_INT: + case HA_KEYTYPE_USHORT_INT: + value= (ulonglong) uint2korr(key); + break; + case HA_KEYTYPE_LONG_INT: + case HA_KEYTYPE_ULONG_INT: + value= (ulonglong) uint4korr(key); + break; + case HA_KEYTYPE_INT24: + case HA_KEYTYPE_UINT24: + value= (ulonglong) uint3korr(key); + break; + case HA_KEYTYPE_FLOAT: /* This shouldn't be used */ + { + float f_1; + float4get(f_1, key); + value= (ulonglong) f_1; + break; + } + case HA_KEYTYPE_DOUBLE: /* This shouldn't be used */ + { + double f_1; + float8get(f_1, key); + value= (ulonglong) f_1; + break; + } + case HA_KEYTYPE_LONGLONG: + case HA_KEYTYPE_ULONGLONG: + value= uint8korr(key); + break; + default: + value= 0; /* Error */ + break; + } + set_if_bigger(info->s->auto_increment, value); +} diff --git a/heap/hp_info.c b/heap/hp_info.c index 3e9d6b6a90b..3122a665fac 100644 --- a/heap/hp_info.c +++ b/heap/hp_info.c @@ -55,5 +55,7 @@ int heap_info(reg1 HP_INFO *info,reg2 HEAPINFO *x, x->index_length= info->s->index_length; x->max_records = info->s->max_records; x->errkey = info->errkey; + if (flag & HA_STATUS_AUTO) + x->auto_increment= info->s->auto_increment + 1; DBUG_RETURN(0); } /* heap_info */ diff --git a/heap/hp_test1.c b/heap/hp_test1.c index 58a13efc12f..2e0a57a12d3 100644 --- a/heap/hp_test1.c +++ b/heap/hp_test1.c @@ -37,11 +37,14 @@ int main(int argc, char **argv) const char *filename; HP_KEYDEF keyinfo[10]; HA_KEYSEG keyseg[4]; + HP_CREATE_INFO hp_create_info; MY_INIT(argv[0]); filename= "test1"; get_options(argc,argv); + bzero(&hp_create_info, sizeof(hp_create_info)); + keyinfo[0].keysegs=1; keyinfo[0].seg=keyseg; keyinfo[0].algorithm= HA_KEY_ALG_HASH; @@ -55,7 +58,8 @@ int main(int argc, char **argv) bzero((gptr) flags,sizeof(flags)); printf("- Creating heap-file\n"); - if (heap_create(filename,1,keyinfo,30,(ulong) flag*100000l,10l) || + if (heap_create(filename,1,keyinfo,30,(ulong) flag*100000l,10l, + &hp_create_info) || !(file= heap_open(filename, 2))) goto err; printf("- Writing records:s\n"); diff --git a/heap/hp_test2.c b/heap/hp_test2.c index 3355c94727b..73e8039d125 100644 --- a/heap/hp_test2.c +++ b/heap/hp_test2.c @@ -63,6 +63,7 @@ int main(int argc, char *argv[]) HP_KEYDEF keyinfo[MAX_KEYS]; HA_KEYSEG keyseg[MAX_KEYS*5]; HEAP_PTR position; + HP_CREATE_INFO hp_create_info; MY_INIT(argv[0]); /* init my_sys library & pthreads */ LINT_INIT(position); @@ -70,6 +71,8 @@ int main(int argc, char *argv[]) filename2= "test2_2"; file=file2=0; get_options(argc,argv); + + bzero(&hp_create_info, sizeof(hp_create_info)); write_count=update=opt_delete=0; key_check=0; @@ -122,7 +125,7 @@ int main(int argc, char *argv[]) printf("- Creating heap-file\n"); if (heap_create(filename,keys,keyinfo,reclength,(ulong) flag*100000L, - (ulong) recant/2) || + (ulong) recant/2, &hp_create_info) || !(file= heap_open(filename, 2))) goto err; signal(SIGINT,endprog); @@ -557,7 +560,7 @@ int main(int argc, char *argv[]) heap_close(file2); printf("- Creating output heap-file 2\n"); - if (heap_create(filename2,1,keyinfo,reclength,0L,0L) || + if (heap_create(filename2,1,keyinfo,reclength,0L,0L,&hp_create_info) || !(file2= heap_open(filename2, 2))) goto err; diff --git a/heap/hp_update.c b/heap/hp_update.c index dd47e04ebc2..dd7374f506c 100644 --- a/heap/hp_update.c +++ b/heap/hp_update.c @@ -22,7 +22,8 @@ int heap_update(HP_INFO *info, const byte *old, const byte *heap_new) { HP_KEYDEF *keydef, *end, *p_lastinx; byte *pos; - HP_SHARE *share=info->s; + bool auto_key_changed= 0; + HP_SHARE *share= info->s; DBUG_ENTER("heap_update"); test_active(info); @@ -33,20 +34,23 @@ int heap_update(HP_INFO *info, const byte *old, const byte *heap_new) if (--(share->records) < share->blength >> 1) share->blength>>= 1; share->changed=1; - p_lastinx = share->keydef + info->lastinx; - for (keydef = share->keydef, end = keydef + share->keys; keydef < end; - keydef++) + p_lastinx= share->keydef + info->lastinx; + for (keydef= share->keydef, end= keydef + share->keys; keydef < end; keydef++) { if (hp_rec_key_cmp(keydef, old, heap_new)) { if ((*keydef->delete_key)(info, keydef, old, pos, keydef == p_lastinx) || (*keydef->write_key)(info, keydef, heap_new, pos)) goto err; + if (share->auto_key == (uint) (keydef - share->keydef + 1)) + auto_key_changed= 1; } } memcpy(pos,heap_new,(size_t) share->reclength); if (++(share->records) == share->blength) share->blength+= share->blength; + if (auto_key_changed) + heap_update_auto_increment(info, heap_new); DBUG_RETURN(0); err: diff --git a/heap/hp_write.c b/heap/hp_write.c index 33527855e60..9edd897eb34 100644 --- a/heap/hp_write.c +++ b/heap/hp_write.c @@ -61,6 +61,8 @@ int heap_write(HP_INFO *info, const byte *record) info->current_ptr=pos; info->current_hash_ptr=0; info->update|=HA_STATE_AKTIV; + if (share->auto_key) + heap_update_auto_increment(info, record); DBUG_RETURN(0); err: DBUG_PRINT("info",("Duplicate key: %d", keydef - share->keydef)); |