summaryrefslogtreecommitdiff
path: root/storage/heap
diff options
context:
space:
mode:
authorDaniel Black <danielgb@au.ibm.com>2018-02-25 15:25:54 +1100
committerGitHub <noreply@github.com>2018-02-25 15:25:54 +1100
commit0805a9565f09a36104a420d9e229e44b1eea8879 (patch)
tree5c5dbf942479c2b7349f1b4505768ddf5a2f8b8d /storage/heap
parent3188131b15c26509e4df3c4b15972d07a20be8bd (diff)
parent8936b175106a3fdfc560e9d33aa58a6372084c5f (diff)
downloadmariadb-git-0805a9565f09a36104a420d9e229e44b1eea8879.tar.gz
Merge branch '10.3' into 10.2-MDEV-10814-dont-dump-query-cache
Diffstat (limited to 'storage/heap')
-rw-r--r--storage/heap/_check.c2
-rw-r--r--storage/heap/ha_heap.cc2
-rw-r--r--storage/heap/heapdef.h20
-rw-r--r--storage/heap/hp_create.c8
-rw-r--r--storage/heap/hp_delete.c4
-rw-r--r--storage/heap/hp_hash.c108
-rw-r--r--storage/heap/hp_rrnd.c2
-rw-r--r--storage/heap/hp_rsame.c2
-rw-r--r--storage/heap/hp_scan.c2
-rw-r--r--storage/heap/hp_write.c4
10 files changed, 75 insertions, 79 deletions
diff --git a/storage/heap/_check.c b/storage/heap/_check.c
index 910a0d20256..fd8652d6a2a 100644
--- a/storage/heap/_check.c
+++ b/storage/heap/_check.c
@@ -79,7 +79,7 @@ int heap_check_heap(HP_INFO *info, my_bool print_status)
}
hp_find_record(info,pos);
- if (!info->current_ptr[share->reclength])
+ if (!info->current_ptr[share->visible])
deleted++;
else
records++;
diff --git a/storage/heap/ha_heap.cc b/storage/heap/ha_heap.cc
index a75efb7fb62..dc7b225f592 100644
--- a/storage/heap/ha_heap.cc
+++ b/storage/heap/ha_heap.cc
@@ -704,7 +704,7 @@ heap_prepare_hp_create_info(TABLE *table_arg, bool internal_table,
}
}
}
- mem_per_row+= MY_ALIGN(share->reclength + 1, sizeof(char*));
+ mem_per_row+= MY_ALIGN(MY_MAX(share->reclength, sizeof(char*)) + 1, sizeof(char*));
if (table_arg->found_next_number_field)
{
keydef[share->next_number_index].flag|= HA_AUTO_KEY;
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_create.c b/storage/heap/hp_create.c
index 431e992e75b..ed669069b96 100644
--- a/storage/heap/hp_create.c
+++ b/storage/heap/hp_create.c
@@ -33,6 +33,7 @@ int heap_create(const char *name, HP_CREATE_INFO *create_info,
uint keys= create_info->keys;
ulong min_records= create_info->min_records;
ulong max_records= create_info->max_records;
+ uint visible_offset;
DBUG_ENTER("heap_create");
if (!create_info->internal_table)
@@ -58,9 +59,9 @@ int heap_create(const char *name, HP_CREATE_INFO *create_info,
/*
We have to store sometimes uchar* del_link in records,
- so the record length should be at least sizeof(uchar*)
+ so the visible_offset must be least at sizeof(uchar*)
*/
- set_if_bigger(reclength, sizeof (uchar*));
+ visible_offset= MY_MAX(reclength, sizeof (char*));
for (i= key_segs= max_length= 0, keyinfo= keydef; i < keys; i++, keyinfo++)
{
@@ -154,7 +155,7 @@ int heap_create(const char *name, HP_CREATE_INFO *create_info,
share->keydef= (HP_KEYDEF*) (share + 1);
share->key_stat_version= 1;
keyseg= (HA_KEYSEG*) (share->keydef + keys);
- init_block(&share->block, reclength + 1, min_records, max_records);
+ init_block(&share->block, visible_offset + 1, min_records, max_records);
/* Fix keys */
memcpy(share->keydef, keydef, (size_t) (sizeof(keydef[0]) * keys));
for (i= 0, keyinfo= share->keydef; i < keys; i++, keyinfo++)
@@ -196,6 +197,7 @@ int heap_create(const char *name, HP_CREATE_INFO *create_info,
share->max_table_size= create_info->max_table_size;
share->data_length= share->index_length= 0;
share->reclength= reclength;
+ share->visible= visible_offset;
share->blength= 1;
share->keys= keys;
share->max_key_length= max_length;
diff --git a/storage/heap/hp_delete.c b/storage/heap/hp_delete.c
index 12f2c65f00b..62f21497f29 100644
--- a/storage/heap/hp_delete.c
+++ b/storage/heap/hp_delete.c
@@ -45,7 +45,7 @@ int heap_delete(HP_INFO *info, const uchar *record)
info->update=HA_STATE_DELETED;
*((uchar**) pos)=share->del_link;
share->del_link=pos;
- pos[share->reclength]=0; /* Record deleted */
+ pos[share->visible]=0; /* Record deleted */
share->deleted++;
share->key_version++;
#if !defined(DBUG_OFF) && defined(EXTRA_HEAP_DEBUG)
@@ -68,7 +68,7 @@ int hp_rb_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo,
const uchar *record, uchar *recpos, int flag)
{
heap_rb_param custom_arg;
- ulong old_allocated;
+ size_t old_allocated;
int res;
if (flag)
diff --git a/storage/heap/hp_hash.c b/storage/heap/hp_hash.c
index eaf284c2015..35a3cd20ee8 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
@@ -263,10 +239,10 @@ ulong hp_hashnr(register HP_KEYDEF *keydef, register const uchar *key)
if (seg->type == HA_KEYTYPE_TEXT)
{
CHARSET_INFO *cs= seg->charset;
- uint length= seg->length;
+ size_t length= seg->length;
if (cs->mbmaxlen > 1)
{
- uint char_length;
+ size_t char_length;
char_length= my_charpos(cs, pos, pos + length, length/cs->mbmaxlen);
set_if_smaller(length, char_length);
}
@@ -275,11 +251,11 @@ ulong hp_hashnr(register HP_KEYDEF *keydef, register const uchar *key)
else if (seg->type == HA_KEYTYPE_VARTEXT1) /* Any VARCHAR segments */
{
CHARSET_INFO *cs= seg->charset;
- uint pack_length= 2; /* Key packing is constant */
- uint length= uint2korr(pos);
+ size_t pack_length= 2; /* Key packing is constant */
+ size_t length= uint2korr(pos);
if (cs->mbmaxlen > 1)
{
- uint char_length;
+ size_t char_length;
char_length= my_charpos(cs, pos +pack_length,
pos +pack_length + length,
seg->length/cs->mbmaxlen);
@@ -324,7 +300,7 @@ ulong hp_rec_hashnr(register HP_KEYDEF *keydef, register const uchar *rec)
if (seg->type == HA_KEYTYPE_TEXT)
{
CHARSET_INFO *cs= seg->charset;
- uint char_length= seg->length;
+ size_t char_length= seg->length;
if (cs->mbmaxlen > 1)
{
char_length= my_charpos(cs, pos, pos + char_length,
@@ -336,11 +312,11 @@ ulong hp_rec_hashnr(register HP_KEYDEF *keydef, register const uchar *rec)
else if (seg->type == HA_KEYTYPE_VARTEXT1) /* Any VARCHAR segments */
{
CHARSET_INFO *cs= seg->charset;
- uint pack_length= seg->bit_start;
- uint length= (pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos));
+ size_t pack_length= seg->bit_start;
+ size_t length= (pack_length == 1 ? (size_t) *(uchar*) pos : uint2korr(pos));
if (cs->mbmaxlen > 1)
{
- uint char_length;
+ size_t char_length;
char_length= my_charpos(cs, pos + pack_length,
pos + pack_length + length,
seg->length/cs->mbmaxlen);
@@ -540,13 +516,13 @@ int hp_rec_key_cmp(HP_KEYDEF *keydef, const uchar *rec1, const uchar *rec2)
if (seg->type == HA_KEYTYPE_TEXT)
{
CHARSET_INFO *cs= seg->charset;
- uint char_length1;
- uint char_length2;
+ size_t char_length1;
+ size_t char_length2;
uchar *pos1= (uchar*)rec1 + seg->start;
uchar *pos2= (uchar*)rec2 + seg->start;
if (cs->mbmaxlen > 1)
{
- uint char_length= seg->length / cs->mbmaxlen;
+ size_t char_length= seg->length / cs->mbmaxlen;
char_length1= my_charpos(cs, pos1, pos1 + seg->length, char_length);
set_if_smaller(char_length1, seg->length);
char_length2= my_charpos(cs, pos2, pos2 + seg->length, char_length);
@@ -565,13 +541,13 @@ int hp_rec_key_cmp(HP_KEYDEF *keydef, const uchar *rec1, const uchar *rec2)
{
uchar *pos1= (uchar*) rec1 + seg->start;
uchar *pos2= (uchar*) rec2 + seg->start;
- uint char_length1, char_length2;
- uint pack_length= seg->bit_start;
+ size_t char_length1, char_length2;
+ size_t pack_length= seg->bit_start;
CHARSET_INFO *cs= seg->charset;
if (pack_length == 1)
{
- char_length1= (uint) *(uchar*) pos1++;
- char_length2= (uint) *(uchar*) pos2++;
+ char_length1= (size_t) *(uchar*) pos1++;
+ char_length2= (size_t) *(uchar*) pos2++;
}
else
{
@@ -582,9 +558,9 @@ int hp_rec_key_cmp(HP_KEYDEF *keydef, const uchar *rec1, const uchar *rec2)
}
if (cs->mbmaxlen > 1)
{
- uint safe_length1= char_length1;
- uint safe_length2= char_length2;
- uint char_length= seg->length / cs->mbmaxlen;
+ size_t safe_length1= char_length1;
+ size_t safe_length2= char_length2;
+ size_t char_length= seg->length / cs->mbmaxlen;
char_length1= my_charpos(cs, pos1, pos1 + char_length1, char_length);
set_if_smaller(char_length1, safe_length1);
char_length2= my_charpos(cs, pos2, pos2 + char_length2, char_length);
@@ -647,12 +623,12 @@ int hp_key_cmp(HP_KEYDEF *keydef, const uchar *rec, const uchar *key)
if (seg->type == HA_KEYTYPE_TEXT)
{
CHARSET_INFO *cs= seg->charset;
- uint char_length_key;
- uint char_length_rec;
+ size_t char_length_key;
+ size_t char_length_rec;
uchar *pos= (uchar*) rec + seg->start;
if (cs->mbmaxlen > 1)
{
- uint char_length= seg->length / cs->mbmaxlen;
+ size_t char_length= seg->length / cs->mbmaxlen;
char_length_key= my_charpos(cs, key, key + seg->length, char_length);
set_if_smaller(char_length_key, seg->length);
char_length_rec= my_charpos(cs, pos, pos + seg->length, char_length);
@@ -673,16 +649,16 @@ int hp_key_cmp(HP_KEYDEF *keydef, const uchar *rec, const uchar *key)
{
uchar *pos= (uchar*) rec + seg->start;
CHARSET_INFO *cs= seg->charset;
- uint pack_length= seg->bit_start;
- uint char_length_rec= (pack_length == 1 ? (uint) *(uchar*) pos :
+ size_t pack_length= seg->bit_start;
+ size_t char_length_rec= (pack_length == 1 ? (size_t) *(uchar*) pos :
uint2korr(pos));
/* Key segments are always packed with 2 bytes */
- uint char_length_key= uint2korr(key);
+ size_t char_length_key= uint2korr(key);
pos+= pack_length;
key+= 2; /* skip key pack length */
if (cs->mbmaxlen > 1)
{
- uint char_length1, char_length2;
+ size_t char_length1, char_length2;
char_length1= char_length2= seg->length / cs->mbmaxlen;
char_length1= my_charpos(cs, key, key + char_length_key, char_length1);
set_if_smaller(char_length_key, char_length1);
@@ -727,7 +703,7 @@ void hp_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec)
for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
{
CHARSET_INFO *cs= seg->charset;
- uint char_length= seg->length;
+ size_t char_length= seg->length;
uchar *pos= (uchar*) rec + seg->start;
if (seg->null_bit)
*key++= MY_TEST(rec[seg->null_pos] & seg->null_bit);
@@ -766,7 +742,7 @@ uint hp_rb_make_key(HP_KEYDEF *keydef, uchar *key,
for (seg= keydef->seg, endseg= seg + keydef->keysegs; seg < endseg; seg++)
{
- uint char_length;
+ size_t char_length;
if (seg->null_bit)
{
if (!(*key++= 1 - MY_TEST(rec[seg->null_pos] & seg->null_bit)))
@@ -814,9 +790,9 @@ uint hp_rb_make_key(HP_KEYDEF *keydef, uchar *key,
if (seg->flag & HA_VAR_LENGTH_PART)
{
uchar *pos= (uchar*) rec + seg->start;
- uint length= seg->length;
- uint pack_length= seg->bit_start;
- uint tmp_length= (pack_length == 1 ? (uint) *(uchar*) pos :
+ size_t length= seg->length;
+ size_t pack_length= seg->bit_start;
+ size_t tmp_length= (pack_length == 1 ? (uint) *(uchar*) pos :
uint2korr(pos));
CHARSET_INFO *cs= seg->charset;
char_length= length/cs->mbmaxlen;
@@ -864,7 +840,7 @@ uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old,
for (seg= keydef->seg, endseg= seg + keydef->keysegs;
seg < endseg && keypart_map; old+= seg->length, seg++)
{
- uint char_length;
+ size_t char_length;
keypart_map>>= 1;
if (seg->null_bit)
{
@@ -891,8 +867,8 @@ uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old,
if (seg->flag & (HA_VAR_LENGTH_PART | HA_BLOB_PART))
{
/* Length of key-part used with heap_rkey() always 2 */
- uint tmp_length=uint2korr(old);
- uint length= seg->length;
+ size_t tmp_length=uint2korr(old);
+ size_t length= seg->length;
CHARSET_INFO *cs= seg->charset;
char_length= length/cs->mbmaxlen;
diff --git a/storage/heap/hp_rrnd.c b/storage/heap/hp_rrnd.c
index 6bf1888275e..1f2a26cb3ed 100644
--- a/storage/heap/hp_rrnd.c
+++ b/storage/heap/hp_rrnd.c
@@ -37,7 +37,7 @@ int heap_rrnd(register HP_INFO *info, uchar *record, uchar *pos)
info->update= 0;
DBUG_RETURN(my_errno= HA_ERR_END_OF_FILE);
}
- if (!info->current_ptr[share->reclength])
+ if (!info->current_ptr[share->visible])
{
info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
DBUG_RETURN(my_errno=HA_ERR_RECORD_DELETED);
diff --git a/storage/heap/hp_rsame.c b/storage/heap/hp_rsame.c
index 40c5a18f974..19767fd752b 100644
--- a/storage/heap/hp_rsame.c
+++ b/storage/heap/hp_rsame.c
@@ -32,7 +32,7 @@ int heap_rsame(register HP_INFO *info, uchar *record, int inx)
DBUG_ENTER("heap_rsame");
test_active(info);
- if (info->current_ptr[share->reclength])
+ if (info->current_ptr[share->visible])
{
if (inx < -1 || inx >= (int) share->keys)
{
diff --git a/storage/heap/hp_scan.c b/storage/heap/hp_scan.c
index 39a6f2082a3..65726c37e1f 100644
--- a/storage/heap/hp_scan.c
+++ b/storage/heap/hp_scan.c
@@ -62,7 +62,7 @@ int heap_scan(register HP_INFO *info, uchar *record)
}
hp_find_record(info, pos);
}
- if (!info->current_ptr[share->reclength])
+ if (!info->current_ptr[share->visible])
{
DBUG_PRINT("warning",("Found deleted record"));
info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
diff --git a/storage/heap/hp_write.c b/storage/heap/hp_write.c
index 392662f69ae..a1e4de446d0 100644
--- a/storage/heap/hp_write.c
+++ b/storage/heap/hp_write.c
@@ -54,7 +54,7 @@ int heap_write(HP_INFO *info, const uchar *record)
}
memcpy(pos,record,(size_t) share->reclength);
- pos[share->reclength]=1; /* Mark record as not deleted */
+ pos[share->visible]= 1; /* Mark record as not deleted */
if (++share->records == share->blength)
share->blength+= share->blength;
info->s->key_version++;
@@ -92,7 +92,7 @@ err:
share->deleted++;
*((uchar**) pos)=share->del_link;
share->del_link=pos;
- pos[share->reclength]=0; /* Record deleted */
+ pos[share->visible]= 0; /* Record deleted */
DBUG_RETURN(my_errno);
} /* heap_write */