Commit 9323e733 authored by monty@tik.mysql.com's avatar monty@tik.mysql.com

Changed meaning of HA_EXTRA_RESET and start of hidden primary keys for BDB tables

parent 00625e0f
bk@work.mysql.com monty@tik.mysql.com
davida@work.mysql.com
jamppa@work.mysql.com
jcole@ham.spaceapes.com
jcole@jcole.burghcom.com
jcole@nslinux.bedford.progress.com
jcole@tetra.bedford.progress.com
jcole@tetra.spaceapes.com
matt@work.mysql.com
monty@donna.mysql.com
monty@work.mysql.com
mwagner@evoq.home.mwagner.org
nusphere@main.burghcom.com
paul@central.snake.net
paul@work.mysql.com
sasha@mysql.sashanet.com
sasha@work.mysql.com
serg@infomag.ape.relarn.ru
serg@serg.mysql.com
serg@work.mysql.com
sinisa@work.mysql.com
spurr@nslinux.bedford.progress.com
tim@localhost.polyesthetic.msg
tim@threads.polyesthetic.msg
tim@work.mysql.com
tonu@work.mysql.com
...@@ -29,6 +29,7 @@ int heap_extra(register HP_INFO *info, enum ha_extra_function function) ...@@ -29,6 +29,7 @@ int heap_extra(register HP_INFO *info, enum ha_extra_function function)
switch (function) { switch (function) {
case HA_EXTRA_RESET: case HA_EXTRA_RESET:
case HA_EXTRA_RESET_STATE:
info->lastinx= -1; info->lastinx= -1;
info->current_record= (ulong) ~0L; info->current_record= (ulong) ~0L;
info->current_hash_ptr=0; info->current_hash_ptr=0;
......
...@@ -87,7 +87,8 @@ enum ha_extra_function { ...@@ -87,7 +87,8 @@ enum ha_extra_function {
HA_EXTRA_REINIT_CACHE=20, /* init cache from current record */ HA_EXTRA_REINIT_CACHE=20, /* init cache from current record */
HA_EXTRA_FORCE_REOPEN=21, /* Datafile have changed on disk */ HA_EXTRA_FORCE_REOPEN=21, /* Datafile have changed on disk */
HA_EXTRA_FLUSH, /* Flush tables to disk */ HA_EXTRA_FLUSH, /* Flush tables to disk */
HA_EXTRA_NO_ROWS /* Don't write rows */ HA_EXTRA_NO_ROWS, /* Don't write rows */
HA_EXTRA_RESET_STATE /* Reset positions */
}; };
/* The following is parameter to ha_panic() */ /* The following is parameter to ha_panic() */
......
...@@ -36,6 +36,14 @@ int nisam_extra(N_INFO *info, enum ha_extra_function function) ...@@ -36,6 +36,14 @@ int nisam_extra(N_INFO *info, enum ha_extra_function function)
switch (function) { switch (function) {
case HA_EXTRA_RESET: case HA_EXTRA_RESET:
if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
{
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
error=end_io_cache(&info->rec_cache);
}
info->opt_flag&= ~(KEY_READ_USED | REMEMBER_OLD_POS);
case HA_EXTRA_RESET_STATE:
info->lastinx= 0; /* Use first index as def */ info->lastinx= 0; /* Use first index as def */
info->int_pos=info->lastpos= NI_POS_ERROR; info->int_pos=info->lastpos= NI_POS_ERROR;
info->page_changed=1; info->page_changed=1;
......
...@@ -2012,8 +2012,8 @@ static int mrg_rrnd(MRG_INFO *info,byte *buf) ...@@ -2012,8 +2012,8 @@ static int mrg_rrnd(MRG_INFO *info,byte *buf)
{ {
isam_info= *(info->current=info->file); isam_info= *(info->current=info->file);
info->end=info->current+info->count; info->end=info->current+info->count;
nisam_extra(isam_info,HA_EXTRA_CACHE);
nisam_extra(isam_info,HA_EXTRA_RESET); nisam_extra(isam_info,HA_EXTRA_RESET);
nisam_extra(isam_info,HA_EXTRA_CACHE);
filepos=isam_info->s->pack.header_length; filepos=isam_info->s->pack.header_length;
} }
else else
...@@ -2035,8 +2035,8 @@ static int mrg_rrnd(MRG_INFO *info,byte *buf) ...@@ -2035,8 +2035,8 @@ static int mrg_rrnd(MRG_INFO *info,byte *buf)
info->current++; info->current++;
isam_info= *info->current; isam_info= *info->current;
filepos=isam_info->s->pack.header_length; filepos=isam_info->s->pack.header_length;
nisam_extra(isam_info,HA_EXTRA_CACHE);
nisam_extra(isam_info,HA_EXTRA_RESET); nisam_extra(isam_info,HA_EXTRA_RESET);
nisam_extra(isam_info,HA_EXTRA_CACHE);
} }
} }
......
...@@ -32,9 +32,9 @@ enum ha_extra_function function; ...@@ -32,9 +32,9 @@ enum ha_extra_function function;
info->cache_in_use=1; info->cache_in_use=1;
else else
{ {
if (function == HA_EXTRA_NO_CACHE) if (function == HA_EXTRA_NO_CACHE || function == HA_EXTRA_RESET)
info->cache_in_use=0; info->cache_in_use=0;
if (function == HA_EXTRA_RESET) if (function == HA_EXTRA_RESET || function == HA_EXTRA_RESET_STATE)
{ {
info->current_table=0; info->current_table=0;
info->last_used_table=info->open_tables; info->last_used_table=info->open_tables;
......
...@@ -37,6 +37,24 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function) ...@@ -37,6 +37,24 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function)
switch (function) { switch (function) {
case HA_EXTRA_RESET: case HA_EXTRA_RESET:
/*
Free buffers and reset the following flags:
EXTRA_CACHE, EXTRA_WRITE_CACHE, EXTRA_KEYREAD, EXTRA_QUICK
*/
if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
{
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
error=end_io_cache(&info->rec_cache);
}
#if defined(HAVE_MMAP) && defined(HAVE_MADVICE)
if (info->opt_flag & MEMMAP_USED)
madvise(share->file_map,share->state.state.data_file_length,MADV_RANDOM);
#endif
info->opt_flag&= ~(KEY_READ_USED | REMEMBER_OLD_POS);
info->quick_mode=0;
/* Fall through */
case HA_EXTRA_RESET_STATE: /* Reset state (don't free buffers) */
info->lastinx= 0; /* Use first index as def */ info->lastinx= 0; /* Use first index as def */
info->last_search_keypage=info->lastpos= HA_OFFSET_ERROR; info->last_search_keypage=info->lastpos= HA_OFFSET_ERROR;
info->page_changed=1; info->page_changed=1;
......
...@@ -2104,8 +2104,8 @@ static int mrg_rrnd(MRG_INFO *info,byte *buf) ...@@ -2104,8 +2104,8 @@ static int mrg_rrnd(MRG_INFO *info,byte *buf)
{ {
isam_info= *(info->current=info->file); isam_info= *(info->current=info->file);
info->end=info->current+info->count; info->end=info->current+info->count;
mi_extra(isam_info,HA_EXTRA_CACHE);
mi_extra(isam_info,HA_EXTRA_RESET); mi_extra(isam_info,HA_EXTRA_RESET);
mi_extra(isam_info,HA_EXTRA_CACHE);
filepos=isam_info->s->pack.header_length; filepos=isam_info->s->pack.header_length;
} }
else else
...@@ -2127,8 +2127,8 @@ static int mrg_rrnd(MRG_INFO *info,byte *buf) ...@@ -2127,8 +2127,8 @@ static int mrg_rrnd(MRG_INFO *info,byte *buf)
info->current++; info->current++;
isam_info= *info->current; isam_info= *info->current;
filepos=isam_info->s->pack.header_length; filepos=isam_info->s->pack.header_length;
mi_extra(isam_info,HA_EXTRA_CACHE);
mi_extra(isam_info,HA_EXTRA_RESET); mi_extra(isam_info,HA_EXTRA_RESET);
mi_extra(isam_info,HA_EXTRA_CACHE);
} }
} }
......
...@@ -31,9 +31,9 @@ int myrg_extra(MYRG_INFO *info,enum ha_extra_function function) ...@@ -31,9 +31,9 @@ int myrg_extra(MYRG_INFO *info,enum ha_extra_function function)
info->cache_in_use=1; info->cache_in_use=1;
else else
{ {
if (function == HA_EXTRA_NO_CACHE) if (function == HA_EXTRA_NO_CACHE || function == HA_EXTRA_RESET)
info->cache_in_use=0; info->cache_in_use=0;
if (function == HA_EXTRA_RESET) if (function == HA_EXTRA_RESET || function == HA_EXTRA_RESET_STATE)
{ {
info->current_table=0; info->current_table=0;
info->last_used_table=info->open_tables; info->last_used_table=info->open_tables;
......
...@@ -330,7 +330,9 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select, ...@@ -330,7 +330,9 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
next_pos=ref_pos; next_pos=ref_pos;
if (! indexfile && ! quick_select) if (! indexfile && ! quick_select)
{ {
file->reset(); file->reset(); // QQ; Shouldn't be needed
if (table->keyread) // QQ Can be removed after the reset
file->extra(HA_EXTRA_KEYREAD); // QQ is removed
next_pos=(byte*) 0; /* Find records in sequence */ next_pos=(byte*) 0; /* Find records in sequence */
file->rnd_init(); file->rnd_init();
file->extra(HA_EXTRA_CACHE); /* Quicker reads */ file->extra(HA_EXTRA_CACHE); /* Quicker reads */
......
...@@ -319,8 +319,14 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked) ...@@ -319,8 +319,14 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked)
/* Open other keys */ /* Open other keys */
bzero((char*) key_file,sizeof(*key_file)*table->keys); bzero((char*) key_file,sizeof(*key_file)*table->keys);
key_used_on_scan=primary_key=table->primary_key; if ((key_used_on_scan=primary_key=table->primary_key) < MAX_KEY)
key_file[primary_key]=file; key_file[primary_key]=file;
else // No primary key
{
hidden_primary_key=1;
if (!share->primary_key_inited)
update_auto_primary_key();
}
bzero((char*) &current_row,sizeof(current_row)); bzero((char*) &current_row,sizeof(current_row));
DB **ptr=key_file; DB **ptr=key_file;
...@@ -1387,8 +1393,6 @@ static BDB_SHARE *get_share(const char *table_name) ...@@ -1387,8 +1393,6 @@ static BDB_SHARE *get_share(const char *table_name)
if ((share=(BDB_SHARE *) my_malloc(sizeof(*share)+length+1, if ((share=(BDB_SHARE *) my_malloc(sizeof(*share)+length+1,
MYF(MY_WME | MY_ZEROFILL)))) MYF(MY_WME | MY_ZEROFILL))))
{ {
// pthread_mutex_init(&share->mutex);
// pthread_cond_init(&share->cond);
share->table_name_length=length; share->table_name_length=length;
share->table_name=(char*) (share+1); share->table_name=(char*) (share+1);
strmov(share->table_name,table_name); strmov(share->table_name,table_name);
...@@ -1399,6 +1403,7 @@ static BDB_SHARE *get_share(const char *table_name) ...@@ -1399,6 +1403,7 @@ static BDB_SHARE *get_share(const char *table_name)
return 0; return 0;
} }
thr_lock_init(&share->lock); thr_lock_init(&share->lock);
pthread_mutex_init(&share->mutex);
} }
} }
share->use_count++; share->use_count++;
...@@ -1413,10 +1418,26 @@ static void free_share(BDB_SHARE *share) ...@@ -1413,10 +1418,26 @@ static void free_share(BDB_SHARE *share)
{ {
hash_delete(&bdb_open_tables, (gptr) share); hash_delete(&bdb_open_tables, (gptr) share);
thr_lock_delete(&share->lock); thr_lock_delete(&share->lock);
// pthread_mutex_destroy(&share->mutex); pthread_mutex_destroy(&share->mutex);
my_free((gptr) share, MYF(0)); my_free((gptr) share, MYF(0));
} }
pthread_mutex_unlock(&bdb_mutex); pthread_mutex_unlock(&bdb_mutex);
} }
void ha_berkeley::update_auto_primary_key()
{
(void) extra(HA_EXTRA_KEYREAD);
pthread_mutex_lock(&share->mutex);
if (!share->primary_key_inited)
{
index_init(primary_key);
if (!index_last(table->record[1]))
share->auto_ident=current_ident;
index_end();
}
pthread_mutex_unlock(&share->mutex);
(void) extra(HA_EXTRA_NO_KEYREAD);
}
#endif /* HAVE_BERKELEY_DB */ #endif /* HAVE_BERKELEY_DB */
...@@ -24,9 +24,12 @@ ...@@ -24,9 +24,12 @@
#include <db.h> #include <db.h>
typedef struct st_berkeley_share { typedef struct st_berkeley_share {
ulonglong auto_ident;
THR_LOCK lock; THR_LOCK lock;
pthread_mutex_t mutex;
char *table_name; char *table_name;
uint table_name_length,use_count; uint table_name_length,use_count;
my_bool inited;
} BDB_SHARE; } BDB_SHARE;
class ha_berkeley: public handler class ha_berkeley: public handler
...@@ -44,7 +47,7 @@ class ha_berkeley: public handler ...@@ -44,7 +47,7 @@ class ha_berkeley: public handler
ulong int_option_flag; ulong int_option_flag;
ulong alloced_rec_buff_length; ulong alloced_rec_buff_length;
uint primary_key,last_dup_key; uint primary_key,last_dup_key;
bool fixed_length_row, fixed_length_primary_key; bool fixed_length_row, fixed_length_primary_key, hidden_primary_key;
bool fix_rec_buff_for_blob(ulong length); bool fix_rec_buff_for_blob(ulong length);
ulong max_row_length(const byte *buf); ulong max_row_length(const byte *buf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment