Commit 99e1b817 authored by unknown's avatar unknown
Browse files

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
parent c1f29705
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
@@ -102,9 +102,11 @@ static int check_one_key(HP_KEYDEF *keydef, uint keynr, ulong records,
  int error;
  uint i,found,max_links,seek,links;
  uint rec_link;				/* Only used with debugging */
  uint hash_buckets_found;
  HASH_INFO *hash_info;

  error=0;
  hash_buckets_found= 0;
  for (i=found=max_links=seek=0 ; i < records ; i++)
  {
    hash_info=hp_find_hash(&keydef->block,i);
@@ -128,21 +130,32 @@ static int check_one_key(HP_KEYDEF *keydef, uint keynr, ulong records,
	  found++;
      }
      if (links > max_links) max_links=links;
      hash_buckets_found++;
    }
  }
  if (found != records)
  {
    DBUG_PRINT("error",("Found %ld of %ld records"));
    DBUG_PRINT("error",("Found %ld of %ld records", found, records));
    error=1;
  }
  if (keydef->hash_buckets != hash_buckets_found)
  {
    DBUG_PRINT("error",("Found %ld buckets, stats shows %ld buckets",
                        hash_buckets_found, keydef->hash_buckets));
    error=1;
  }
  DBUG_PRINT("info",
	     ("records: %ld   seeks: %d   max links: %d   hitrate: %.2f",
	     ("records: %ld   seeks: %d   max links: %d   hitrate: %.2f   "
              "buckets: %d",
	      records,seek,max_links,
	      (float) seek / (float) (records ? records : 1)));
	      (float) seek / (float) (records ? records : 1), 
              hash_buckets_found));
  if (print_status)
    printf("Key: %d  records: %ld   seeks: %d   max links: %d   hitrate: %.2f\n",
    printf("Key: %d  records: %ld   seeks: %d   max links: %d   "
           "hitrate: %.2f   buckets: %d\n",
	   keynr, records, seek, max_links,
	   (float) seek / (float) (records ? records : 1));
	   (float) seek / (float) (records ? records : 1), 
           hash_buckets_found);
  return error;
}

+1 −0
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ void hp_clear_keys(HP_SHARE *info)
        VOID(hp_free_level(block,block->levels,block->root,(byte*) 0));
      block->levels=0;
      block->last_allocated=0;
      keyinfo->hash_buckets= 0;
    }
  }
  info->index_length=0;
+1 −0
Original line number Diff line number Diff line
@@ -128,6 +128,7 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
		   max_records);
	keyinfo->delete_key= hp_delete_key;
	keyinfo->write_key= hp_write_key;
        keyinfo->hash_buckets= 0;
      }
    }
    share->min_records= min_records;
+7 −1
Original line number Diff line number Diff line
@@ -151,6 +151,8 @@ int hp_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo,
    pos->ptr_to_rec=empty->ptr_to_rec;
    pos->next_key=empty->next_key;
  }
  else
    keyinfo->hash_buckets--;

  if (empty == lastpos)			/* deleted last hash key */
    DBUG_RETURN (0);
@@ -187,7 +189,11 @@ int hp_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo,
    }
    pos3= pos;				/* Link pos->next after lastpos */
  }
  else pos3= 0;				/* Different positions merge */
  else
  {
    pos3= 0;				/* Different positions merge */
    keyinfo->hash_buckets--;
  }

  empty[0]=lastpos[0];
  hp_movelink(pos3, empty, pos->next_key);
+18 −2
Original line number Diff line number Diff line
@@ -196,7 +196,18 @@ byte *hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo, const byte *key,
}


	/* Calculate pos according to keys */
/*
  Calculate position number for hash value.
  SYNOPSIS
    hp_mask()
      hashnr     Hash value
      buffmax    Value such that
                 2^(n-1) < maxlength <= 2^n = buffmax
      maxlength  
  
  RETURN
    Array index, in [0..maxlength)
*/

ulong hp_mask(ulong hashnr, ulong buffmax, ulong maxlength)
{
@@ -205,7 +216,12 @@ ulong hp_mask(ulong hashnr, ulong buffmax, ulong maxlength)
}


	/* Change link from pos to new_link */
/*
  Change
    next_link -> ... -> X -> pos
  to
    next_link -> ... -> X -> newlink
*/

void hp_movelink(HASH_INFO *pos, HASH_INFO *next_link, HASH_INFO *newlink)
{
Loading