diff options
author | ram@mysql.r18.ru <> | 2002-10-07 17:49:03 +0500 |
---|---|---|
committer | ram@mysql.r18.ru <> | 2002-10-07 17:49:03 +0500 |
commit | 2e1a0c031a0ea3d7505690c6999d5d13e2a3dfe6 (patch) | |
tree | ebf4b60cc6d75288281e8c8da41994ba6bc7d89f /sql/ha_heap.cc | |
parent | 6976c7cf3c83e3c51770ebd7304b7f69a76a28f0 (diff) | |
download | mariadb-git-2e1a0c031a0ea3d7505690c6999d5d13e2a3dfe6.tar.gz |
auto_increment for heap tables
test case
Diffstat (limited to 'sql/ha_heap.cc')
-rw-r--r-- | sql/ha_heap.cc | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index 5c314462666..6cfd3c881cc 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -35,7 +35,9 @@ int ha_heap::open(const char *name, int mode, uint test_if_locked) { if (!(file= heap_open(name, mode)) && my_errno == ENOENT) { - if (!create(name, table, NULL)) + HA_CREATE_INFO create_info; + bzero(&create_info, sizeof(create_info)); + if (!create(name, table, &create_info)) file= heap_open(name, mode); } return (file ? 0 : 1); @@ -51,6 +53,8 @@ int ha_heap::write_row(byte * buf) statistic_increment(ha_write_count,&LOCK_status); if (table->time_stamp) update_timestamp(buf+table->time_stamp-1); + if (table->next_number_field && buf == table->record[0]) + update_auto_increment(); return heap_write(file,buf); } @@ -161,6 +165,8 @@ void ha_heap::info(uint flag) index_file_length=info.index_length; max_data_file_length= info.max_records* info.reclength; delete_length= info.deleted * info.reclength; + if (flag & HA_STATUS_AUTO) + auto_increment_value= info.auto_increment; } int ha_heap::extra(enum ha_extra_function operation) @@ -234,11 +240,11 @@ ha_rows ha_heap::records_in_range(int inx, } } - int ha_heap::create(const char *name, TABLE *table, HA_CREATE_INFO *create_info) { uint key, parts, mem_per_row= 0; + uint auto_key= 0, auto_key_type= 0; ulong max_rows; HP_KEYDEF *keydef; HA_KEYSEG *seg; @@ -296,19 +302,42 @@ int ha_heap::create(const char *name, TABLE *table, seg->null_bit= 0; seg->null_pos= 0; } + if (field->flags & AUTO_INCREMENT_FLAG) + { + auto_key= key + 1; + auto_key_type= field->key_type(); + } } } mem_per_row+= MY_ALIGN(table->reclength + 1, sizeof(char*)); max_rows = (ulong) (current_thd->variables.max_heap_table_size / mem_per_row); + HP_CREATE_INFO hp_create_info; + hp_create_info.auto_key= auto_key; + hp_create_info.auto_key_type= auto_key_type; + hp_create_info.auto_increment= (create_info->auto_increment_value ? + create_info->auto_increment_value - 1 : 0); error= heap_create(fn_format(buff,name,"","",4+2), table->keys,keydef, table->reclength, ((table->max_rows < max_rows && table->max_rows) ? table->max_rows : max_rows), - table->min_rows); + table->min_rows, &hp_create_info); my_free((gptr) keydef, MYF(0)); if (file) info(HA_STATUS_NO_LOCK | HA_STATUS_CONST | HA_STATUS_VARIABLE); ref_length= sizeof(HEAP_PTR); return (error); } + +void ha_heap::update_create_info(HA_CREATE_INFO *create_info) +{ + table->file->info(HA_STATUS_AUTO); + if (!(create_info->used_fields & HA_CREATE_USED_AUTO)) + create_info->auto_increment_value= auto_increment_value; +} + +longlong ha_heap::get_auto_increment() +{ + ha_heap::info(HA_STATUS_AUTO); + return auto_increment_value; +} |