summaryrefslogtreecommitdiff
path: root/heap/hp_write.c
diff options
context:
space:
mode:
authorunknown <sergefp@mysql.com>2004-09-08 02:07:53 +0400
committerunknown <sergefp@mysql.com>2004-09-08 02:07:53 +0400
commit99e1b8179eb88ad64e8cae7a6acd7822b94dda1f (patch)
tree5fb9bac74cdad46fce2efb3c783f9a02367489bd /heap/hp_write.c
parentc1f297058d39408e64902c852fb141e4c3dd64c1 (diff)
downloadmariadb-git-99e1b8179eb88ad64e8cae7a6acd7822b94dda1f.tar.gz
Fix for bug#5138: hash indexes on heap tables support statistics.
KEY::rec_per_key is updated every time 1/HEAP_STATS_UPDATE_THRESHOLD part of table records has been changed. heap/_check.c: Hash indexes on heap tables now support statistics - number of hash buckets. The value is updated on any insert/delete operation. heap/hp_clear.c: Hash indexes on heap tables now support statistics - number of hash buckets. The value is updated on any insert/delete operation. heap/hp_create.c: Hash indexes on heap tables now support statistics - number of hash buckets. The value is updated on any insert/delete operation. heap/hp_delete.c: Hash indexes on heap tables now support statistics - number of hash buckets. The value is updated on any insert/delete operation. heap/hp_hash.c: Hash indexes on heap tables now support statistics - number of hash buckets. The value is updated on any insert/delete operation. heap/hp_write.c: Hash indexes on heap tables now support statistics - number of hash buckets. The value is updated on any insert/delete operation. include/heap.h: Hash indexes on heap tables now support statistics - number of hash buckets. The value is updated on any insert/delete operation. mysql-test/r/heap.result: Fix for bug#5138: store/use statistics for hash indexes on heap tables mysql-test/r/heap_hash.result: Fix for bug#5138: store/use statistics for hash indexes on heap tables mysql-test/r/myisam.result: Fix for bug#5138: store/use statistics for hash indexes on heap tables mysql-test/t/heap_hash.test: Fix for bug#5138: store/use statistics for hash indexes on heap tables sql/structs.h: Added comments
Diffstat (limited to 'heap/hp_write.c')
-rw-r--r--heap/hp_write.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/heap/hp_write.c b/heap/hp_write.c
index 3b0ec76d616..853360976bf 100644
--- a/heap/hp_write.c
+++ b/heap/hp_write.c
@@ -36,7 +36,7 @@ int heap_write(HP_INFO *info, const byte *record)
byte *pos;
HP_SHARE *share=info->s;
DBUG_ENTER("heap_write");
-
+ printf("heap_write\n");
#ifndef DBUG_OFF
if (info->mode & O_RDONLY)
{
@@ -180,15 +180,31 @@ int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
DBUG_RETURN(-1); /* No more memory */
halfbuff= (long) share->blength >> 1;
pos= hp_find_hash(&keyinfo->block,(first_index=share->records-halfbuff));
-
+
+ /*
+ We're about to add one more hash position, with hash_mask=#records.
+ Entries that should be relocated to that position are currently members
+ of the list that starts at #first_index position.
+ At #first_index position there may be either:
+ a) A list of items with hash_mask=first_index. The list contains
+ 1) entries that should be relocated to the list that starts at new
+ position we're adding
+ 2) entries that should be left in the list starting at #first_index
+ position
+ or
+ b) An entry with hashnr != first_index. We don't need to move it.
+ */
if (pos != empty) /* If some records */
{
do
{
hashnr = hp_rec_hashnr(keyinfo, pos->ptr_to_rec);
if (flag == 0) /* First loop; Check if ok */
+ {
+ /* Bail out if we're dealing with case b) from above comment */
if (hp_mask(hashnr, share->blength, share->records) != first_index)
break;
+ }
if (!(hashnr & halfbuff))
{ /* Key will not move */
if (!(flag & LOWFIND))
@@ -245,6 +261,9 @@ int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
}
}
while ((pos=pos->next_key));
+
+ if ((flag & (LOWFIND | HIGHFIND)) == (LOWFIND | HIGHFIND))
+ keyinfo->hash_buckets++;
if ((flag & (LOWFIND | LOWUSED)) == LOWFIND)
{
@@ -265,6 +284,7 @@ int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
{
pos->ptr_to_rec=recpos;
pos->next_key=0;
+ keyinfo->hash_buckets++;
}
else
{
@@ -280,6 +300,7 @@ int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
}
else
{
+ keyinfo->hash_buckets++;
pos->ptr_to_rec=recpos;
pos->next_key=0;
hp_movelink(pos, gpos, empty);