diff options
author | monty@donna.mysql.com <> | 2000-09-14 02:39:07 +0300 |
---|---|---|
committer | monty@donna.mysql.com <> | 2000-09-14 02:39:07 +0300 |
commit | b581f17be222af50b399242353fd6df31b6b05d5 (patch) | |
tree | 47d3199e561726437875c3247556ac5797525366 /myisammrg | |
parent | 7e543b4d4b67b7108d72bf1f1a8b22f99937c886 (diff) | |
download | mariadb-git-b581f17be222af50b399242353fd6df31b6b05d5.tar.gz |
Fixes for MERGE TABLES and HEAP tables
Diffstat (limited to 'myisammrg')
-rw-r--r-- | myisammrg/mymrgdef.h | 2 | ||||
-rw-r--r-- | myisammrg/myrg_create.c | 11 | ||||
-rw-r--r-- | myisammrg/myrg_open.c | 4 | ||||
-rw-r--r-- | myisammrg/myrg_queue.c | 23 | ||||
-rw-r--r-- | myisammrg/myrg_rfirst.c | 16 | ||||
-rw-r--r-- | myisammrg/myrg_rkey.c | 33 | ||||
-rw-r--r-- | myisammrg/myrg_rlast.c | 16 | ||||
-rw-r--r-- | myisammrg/myrg_rnext.c | 69 | ||||
-rw-r--r-- | myisammrg/myrg_rprev.c | 47 | ||||
-rw-r--r-- | myisammrg/myrg_rrnd.c | 8 |
10 files changed, 112 insertions, 117 deletions
diff --git a/myisammrg/mymrgdef.h b/myisammrg/mymrgdef.h index 945a415525f..564900614e2 100644 --- a/myisammrg/mymrgdef.h +++ b/myisammrg/mymrgdef.h @@ -29,4 +29,4 @@ extern pthread_mutex_t THR_LOCK_open; #endif int _myrg_init_queue(MYRG_INFO *info,int inx,enum ha_rkey_function search_flag); - +int _myrg_finish_scan(MYRG_INFO *info, int inx, enum ha_rkey_function type); diff --git a/myisammrg/myrg_create.c b/myisammrg/myrg_create.c index e5f5b988d80..113831b9d7f 100644 --- a/myisammrg/myrg_create.c +++ b/myisammrg/myrg_create.c @@ -23,8 +23,7 @@ a NULL-pointer last */ -int myrg_create(name,table_names) -const char *name,**table_names; +int myrg_create(const char *name, const char **table_names, my_bool fix_names) { int save_errno; uint errpos; @@ -38,15 +37,19 @@ const char *name,**table_names; goto err; errpos=1; if (table_names) + { for ( ; *table_names ; table_names++) { strmov(buff,*table_names); - fn_same(buff,name,4); + if (fix_names) + fn_same(buff,name,4); *(end=strend(buff))='\n'; - if (my_write(file,*table_names,(uint) (end-buff+1), + end[1]=0; + if (my_write(file,buff,(uint) (end-buff+1), MYF(MY_WME | MY_NABP))) goto err; } + } if (my_close(file,MYF(0))) goto err; DBUG_RETURN(0); diff --git a/myisammrg/myrg_open.c b/myisammrg/myrg_open.c index d3bb0b4e7b6..c12fa1fa52b 100644 --- a/myisammrg/myrg_open.c +++ b/myisammrg/myrg_open.c @@ -58,7 +58,7 @@ int handle_locking; { if ((end=strend(buff))[-1] == '\n') end[-1]='\0'; - if (buff[0]) /* Skipp empty lines */ + if (buff[0] && buff[0] != '#') /* Skipp empty lines and comments */ { last_isam=isam; if (!test_if_hard_path(buff)) @@ -93,7 +93,7 @@ int handle_locking; m_info->options|=isam->s->options; m_info->records+=isam->state->records; m_info->del+=isam->state->del; - m_info->data_file_length=isam->state->data_file_length; + m_info->data_file_length+=isam->state->data_file_length; if (i) isam=(MI_INFO*) (isam->open_list.next->data); } diff --git a/myisammrg/myrg_queue.c b/myisammrg/myrg_queue.c index 4917cbf7cf8..4d94f984722 100644 --- a/myisammrg/myrg_queue.c +++ b/myisammrg/myrg_queue.c @@ -23,31 +23,32 @@ static int queue_key_cmp(void *keyseg, byte *a, byte *b) MI_INFO *aa=((MYRG_TABLE *)a)->table; MI_INFO *bb=((MYRG_TABLE *)b)->table; uint not_used; - - return (_mi_key_cmp((MI_KEYSEG *)keyseg, aa->lastkey, bb->lastkey, - USE_WHOLE_KEY, SEARCH_FIND, ¬_used)); + int ret= _mi_key_cmp((MI_KEYSEG *)keyseg, aa->lastkey, bb->lastkey, + USE_WHOLE_KEY, SEARCH_FIND, ¬_used); + return ret < 0 ? -1 : ret > 0 ? 1 : 0; } /* queue_key_cmp */ + int _myrg_init_queue(MYRG_INFO *info,int inx,enum ha_rkey_function search_flag) { - QUEUE *q=&(info->by_key); + int error=0; + QUEUE *q= &(info->by_key); - if (!q->root) + if (!is_queue_inited(q)) { if (init_queue(q,info->tables, 0, - (myisam_read_vec[search_flag]==SEARCH_SMALLER), + (myisam_readnext_vec[search_flag] == SEARCH_SMALLER), queue_key_cmp, info->open_tables->table->s->keyinfo[inx].seg)) - return my_errno; + error=my_errno; } else { if (reinit_queue(q,info->tables, 0, - (myisam_read_vec[search_flag]==SEARCH_SMALLER), + (myisam_readnext_vec[search_flag] == SEARCH_SMALLER), queue_key_cmp, info->open_tables->table->s->keyinfo[inx].seg)) - return my_errno; + error=my_errno; } - return 0; + return error; } - diff --git a/myisammrg/myrg_rfirst.c b/myisammrg/myrg_rfirst.c index f344eb2318f..3f29414f076 100644 --- a/myisammrg/myrg_rfirst.c +++ b/myisammrg/myrg_rfirst.c @@ -16,7 +16,7 @@ #include "mymrgdef.h" - /* Read first row through a specfic key */ + /* Read first row according to specific key */ int myrg_rfirst(MYRG_INFO *info, byte *buf, int inx) { @@ -29,17 +29,17 @@ int myrg_rfirst(MYRG_INFO *info, byte *buf, int inx) for (table=info->open_tables ; table < info->end_table ; table++) { - err=mi_rfirst(table->table,NULL,inx); - info->last_used_table=table; - - if (err == HA_ERR_END_OF_FILE) - continue; - if (err) + if ((err=mi_rfirst(table->table,NULL,inx))) + { + if (err == HA_ERR_END_OF_FILE) + continue; return err; - + } /* adding to queue */ queue_insert(&(info->by_key),(byte *)table); } + /* We have done a read in all tables */ + info->last_used_table=table; if (!info->by_key.elements) return HA_ERR_END_OF_FILE; diff --git a/myisammrg/myrg_rkey.c b/myisammrg/myrg_rkey.c index c0123588a06..465d61ce3c6 100644 --- a/myisammrg/myrg_rkey.c +++ b/myisammrg/myrg_rkey.c @@ -16,6 +16,17 @@ /* Read record based on a key */ +/* + * HA_READ_KEY_EXACT => SEARCH_BIGGER + * HA_READ_KEY_OR_NEXT => SEARCH_BIGGER + * HA_READ_AFTER_KEY => SEARCH_BIGGER + * HA_READ_PREFIX => SEARCH_BIGGER + * HA_READ_KEY_OR_PREV => SEARCH_SMALLER + * HA_READ_BEFORE_KEY => SEARCH_SMALLER + * HA_READ_PREFIX_LAST => SEARCH_SMALLER + */ + + #include "mymrgdef.h" /* todo: we could store some additional info to speedup lookups: @@ -33,7 +44,7 @@ int myrg_rkey(MYRG_INFO *info,byte *record,int inx, const byte *key, MYRG_TABLE *table; MI_INFO *mi; int err; - byte *buf=((search_flag == HA_READ_KEY_EXACT)?record:0); + byte *buf=((search_flag == HA_READ_KEY_EXACT) ? record: 0); if (_myrg_init_queue(info,inx,search_flag)) return my_errno; @@ -52,13 +63,14 @@ int myrg_rkey(MYRG_INFO *info,byte *record,int inx, const byte *key, { err=_mi_rkey(mi,buf,inx,key_buff,pack_key_length,search_flag,FALSE); } - info->last_used_table=table; + info->last_used_table=table+1; - if (err == HA_ERR_KEY_NOT_FOUND) - continue; if (err) + { + if (err == HA_ERR_KEY_NOT_FOUND) + continue; return err; - + } /* adding to queue */ queue_insert(&(info->by_key),(byte *)table); @@ -76,14 +88,3 @@ int myrg_rkey(MYRG_INFO *info,byte *record,int inx, const byte *key, mi=(info->current_table=(MYRG_TABLE *)queue_top(&(info->by_key)))->table; return mi_rrnd(mi,record,mi->lastpos); } - -/* - * HA_READ_KEY_EXACT => SEARCH_BIGGER - * HA_READ_KEY_OR_NEXT => SEARCH_BIGGER - * HA_READ_AFTER_KEY => SEARCH_BIGGER - * HA_READ_PREFIX => SEARCH_BIGGER - * HA_READ_KEY_OR_PREV => SEARCH_SMALLER - * HA_READ_BEFORE_KEY => SEARCH_SMALLER - * HA_READ_PREFIX_LAST => SEARCH_SMALLER - */ - diff --git a/myisammrg/myrg_rlast.c b/myisammrg/myrg_rlast.c index ab7aacda716..f41844dfd5c 100644 --- a/myisammrg/myrg_rlast.c +++ b/myisammrg/myrg_rlast.c @@ -24,22 +24,22 @@ int myrg_rlast(MYRG_INFO *info, byte *buf, int inx) MI_INFO *mi; int err; - if (_myrg_init_queue(info,inx,HA_READ_KEY_OR_PREV)) + if (_myrg_init_queue(info,inx, HA_READ_KEY_OR_PREV)) return my_errno; for (table=info->open_tables ; table < info->end_table ; table++) { - err=mi_rlast(table->table,NULL,inx); - info->last_used_table=table; - - if (err == HA_ERR_END_OF_FILE) - continue; - if (err) + if ((err=mi_rlast(table->table,NULL,inx))) + { + if (err == HA_ERR_END_OF_FILE) + continue; return err; - + } /* adding to queue */ queue_insert(&(info->by_key),(byte *)table); } + /* We have done a read in all tables */ + info->last_used_table=table; if (!info->by_key.elements) return HA_ERR_END_OF_FILE; diff --git a/myisammrg/myrg_rnext.c b/myisammrg/myrg_rnext.c index e714ce3b139..71a4d081e8a 100644 --- a/myisammrg/myrg_rnext.c +++ b/myisammrg/myrg_rnext.c @@ -22,22 +22,21 @@ int myrg_rnext(MYRG_INFO *info, byte *buf, int inx) { - MYRG_TABLE *table; - MI_INFO *mi; - byte *key_buff; - uint pack_key_length; int err; + MI_INFO *mi; /* at first, do rnext for the table found before */ - err=mi_rnext(info->current_table->table,NULL,inx); - if (err == HA_ERR_END_OF_FILE) + if ((err=mi_rnext(info->current_table->table,NULL,inx))) { - queue_remove(&(info->by_key),0); - if (!info->by_key.elements) - return HA_ERR_END_OF_FILE; + if (err == HA_ERR_END_OF_FILE) + { + queue_remove(&(info->by_key),0); + if (!info->by_key.elements) + return HA_ERR_END_OF_FILE; + } + else + return err; } - else if (err) - return err; else { /* Found here, adding to queue */ @@ -46,30 +45,42 @@ int myrg_rnext(MYRG_INFO *info, byte *buf, int inx) } /* next, let's finish myrg_rkey's initial scan */ - table=info->last_used_table+1; + if ((err=_myrg_finish_scan(info, inx, HA_READ_KEY_OR_NEXT))) + return err; + + /* now, mymerge's read_next is as simple as one queue_top */ + mi=(info->current_table=(MYRG_TABLE *)queue_top(&(info->by_key)))->table; + return mi_rrnd(mi,buf,mi->lastpos); +} + + +/* let's finish myrg_rkey's initial scan */ + +int _myrg_finish_scan(MYRG_INFO *info, int inx, enum ha_rkey_function type) +{ + int err; + MYRG_TABLE *table=info->last_used_table; if (table < info->end_table) { - mi=info->last_used_table->table; - key_buff=(byte*) mi->lastkey+mi->s->base.max_key_length; - pack_key_length=mi->last_rkey_length; + MI_INFO *mi= table[-1].table; + byte *key_buff=(byte*) mi->lastkey+mi->s->base.max_key_length; + uint pack_key_length= mi->last_rkey_length; + for (; table < info->end_table ; table++) { mi=table->table; - err=_mi_rkey(mi,NULL,inx,key_buff,pack_key_length,HA_READ_KEY_OR_NEXT,FALSE); - info->last_used_table=table; - - if (err == HA_ERR_KEY_NOT_FOUND) - continue; - if (err) - return err; - + if ((err=_mi_rkey(mi,NULL,inx,key_buff,pack_key_length, + type,FALSE))) + { + if (err == HA_ERR_KEY_NOT_FOUND) /* If end of file */ + continue; + return err; + } /* Found here, adding to queue */ - queue_insert(&(info->by_key),(byte *)table); + queue_insert(&(info->by_key),(byte *) table); } + /* All tables are now used */ + info->last_used_table=table; } - - /* now, mymerge's read_next is as simple as one queue_top */ - mi=(info->current_table=(MYRG_TABLE *)queue_top(&(info->by_key)))->table; - return mi_rrnd(mi,buf,mi->lastpos); + return 0; } - diff --git a/myisammrg/myrg_rprev.c b/myisammrg/myrg_rprev.c index 0523dc7f4e7..8d7a810696f 100644 --- a/myisammrg/myrg_rprev.c +++ b/myisammrg/myrg_rprev.c @@ -22,22 +22,21 @@ int myrg_rprev(MYRG_INFO *info, byte *buf, int inx) { - MYRG_TABLE *table; - MI_INFO *mi; - byte *key_buff; - uint pack_key_length; int err; + MI_INFO *mi; - /* at first, do rnext for the table found before */ - err=mi_rprev(info->current_table->table,NULL,inx); - if (err == HA_ERR_END_OF_FILE) + /* at first, do rprev for the table found before */ + if ((err=mi_rprev(info->current_table->table,NULL,inx))) { - queue_remove(&(info->by_key),0); - if (!info->by_key.elements) - return HA_ERR_END_OF_FILE; + if (err == HA_ERR_END_OF_FILE) + { + queue_remove(&(info->by_key),0); + if (!info->by_key.elements) + return HA_ERR_END_OF_FILE; + } + else + return err; } - else if (err) - return err; else { /* Found here, adding to queue */ @@ -46,28 +45,8 @@ int myrg_rprev(MYRG_INFO *info, byte *buf, int inx) } /* next, let's finish myrg_rkey's initial scan */ - table=info->last_used_table+1; - if (table < info->end_table) - { - mi=info->last_used_table->table; - key_buff=(byte*) mi->lastkey+mi->s->base.max_key_length; - pack_key_length=mi->last_rkey_length; - for (; table < info->end_table ; table++) - { - mi=table->table; - err=_mi_rkey(mi,NULL,inx,key_buff,pack_key_length, - HA_READ_KEY_OR_PREV,FALSE); - info->last_used_table=table; - - if (err == HA_ERR_KEY_NOT_FOUND) - continue; - if (err) - return err; - - /* Found here, adding to queue */ - queue_insert(&(info->by_key),(byte *)table); - } - } + if ((err=_myrg_finish_scan(info, inx, HA_READ_KEY_OR_PREV))) + return err; /* now, mymerge's read_prev is as simple as one queue_top */ mi=(info->current_table=(MYRG_TABLE *)queue_top(&(info->by_key)))->table; diff --git a/myisammrg/myrg_rrnd.c b/myisammrg/myrg_rrnd.c index da11b230f27..c64f48c93cd 100644 --- a/myisammrg/myrg_rrnd.c +++ b/myisammrg/myrg_rrnd.c @@ -84,10 +84,10 @@ int myrg_rrnd(MYRG_INFO *info,byte *buf,ulonglong filepos) info->end_table-1,filepos); isam_info=info->current_table->table; isam_info->update&= HA_STATE_CHANGED; - return ((*isam_info->s->read_rnd)(isam_info,(byte*) buf, - (ha_rows) (filepos - - info->current_table->file_offset), - 0)); + return ((*isam_info->s->read_rnd) + (isam_info, (byte*) buf, + (ha_rows) (filepos - info->current_table->file_offset), + 0)); } |