summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2017-11-10 19:02:27 +0200
committerMonty <monty@mariadb.org>2017-11-23 10:04:12 +0200
commite69466d0231aa55f223d1f1199913d1a1ec13025 (patch)
tree0139580ee3a67b5272dede0d79bc61328ba80b2d
parentd8ada081526c9dedb004a2dcf216f1a0596a9c57 (diff)
downloadmariadb-git-e69466d0231aa55f223d1f1199913d1a1ec13025.tar.gz
Improve performance of heap tables
- make hp_mask an inline function (short and called 16 times) - Simplify hp_search. Biggest benefit is for doing key lookup without a matching row. Matching rows may be a bit slower, but is offseted by having hp_mask inlined.
-rw-r--r--storage/heap/heapdef.h20
-rw-r--r--storage/heap/hp_hash.c40
2 files changed, 27 insertions, 33 deletions
diff --git a/storage/heap/heapdef.h b/storage/heap/heapdef.h
index 8d9d1f81c53..a20fe6836a2 100644
--- a/storage/heap/heapdef.h
+++ b/storage/heap/heapdef.h
@@ -83,7 +83,6 @@ extern uchar *hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo,
const uchar *key, HASH_INFO *pos);
extern ulong hp_hashnr(HP_KEYDEF *keyinfo,const uchar *key);
extern ulong hp_rec_hashnr(HP_KEYDEF *keyinfo,const uchar *rec);
-extern ulong hp_mask(ulong hashnr,ulong buffmax,ulong maxlength);
extern void hp_movelink(HASH_INFO *pos,HASH_INFO *next_link,
HASH_INFO *newlink);
extern int hp_rec_key_cmp(HP_KEYDEF *keydef,const uchar *rec1,
@@ -111,3 +110,22 @@ void init_heap_psi_keys();
#endif /* HAVE_PSI_INTERFACE */
C_MODE_END
+
+/*
+ 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)
+*/
+
+static inline ulong hp_mask(ulong hashnr, ulong buffmax, ulong maxlength)
+{
+ if ((hashnr & (buffmax-1)) < maxlength) return (hashnr & (buffmax-1));
+ return (hashnr & ((buffmax >> 1) -1));
+}
diff --git a/storage/heap/hp_hash.c b/storage/heap/hp_hash.c
index eaf284c2015..eca8f71458b 100644
--- a/storage/heap/hp_hash.c
+++ b/storage/heap/hp_hash.c
@@ -100,18 +100,20 @@ uchar *hp_search(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key,
uint nextflag)
{
reg1 HASH_INFO *pos,*prev_ptr;
- int flag;
uint old_nextflag;
HP_SHARE *share=info->s;
DBUG_ENTER("hp_search");
old_nextflag=nextflag;
- flag=1;
prev_ptr=0;
if (share->records)
{
- pos=hp_find_hash(&keyinfo->block, hp_mask(hp_hashnr(keyinfo, key),
- share->blength, share->records));
+ ulong search_pos=
+ hp_mask(hp_hashnr(keyinfo, key), share->blength, share->records);
+ pos=hp_find_hash(&keyinfo->block, search_pos);
+ if (search_pos !=
+ hp_mask(pos->hash_of_key, share->blength, share->records))
+ goto not_found; /* Wrong link */
do
{
if (!hp_key_cmp(keyinfo, pos->ptr_to_rec, key))
@@ -142,17 +144,11 @@ uchar *hp_search(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key,
}
}
}
- if (flag)
- {
- flag=0; /* Reset flag */
- if (hp_find_hash(&keyinfo->block,
- hp_mask(pos->hash_of_key,
- share->blength, share->records)) != pos)
- break; /* Wrong link */
- }
}
while ((pos=pos->next_key));
}
+
+not_found:
my_errno=HA_ERR_KEY_NOT_FOUND;
if (nextflag == 2 && ! info->current_ptr)
{
@@ -195,26 +191,6 @@ uchar *hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key,
/*
- 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)
-{
- if ((hashnr & (buffmax-1)) < maxlength) return (hashnr & (buffmax-1));
- return (hashnr & ((buffmax >> 1) -1));
-}
-
-
-/*
Change
next_link -> ... -> X -> pos
to