Commit ea5a7a3d authored by ram@deer.(none)'s avatar ram@deer.(none)

fix for r-tree code (memory overlap reported by valgrind)

new comments.
parent 669365b4
...@@ -100,6 +100,7 @@ peter@linux.local ...@@ -100,6 +100,7 @@ peter@linux.local
peter@mysql.com peter@mysql.com
peterg@mysql.com peterg@mysql.com
pgulutzan@linux.local pgulutzan@linux.local
ram@deer.(none)
ram@gw.mysql.r18.ru ram@gw.mysql.r18.ru
ram@gw.udmsearch.izhnet.ru ram@gw.udmsearch.izhnet.ru
ram@mysql.r18.ru ram@mysql.r18.ru
......
...@@ -508,6 +508,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) ...@@ -508,6 +508,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
&info.buff,(share->base.max_key_block_length*2+ &info.buff,(share->base.max_key_block_length*2+
share->base.max_key_length), share->base.max_key_length),
&info.lastkey,share->base.max_key_length*3+1, &info.lastkey,share->base.max_key_length*3+1,
&info.first_mbr_key, share->base.max_key_length,
&info.filename,strlen(org_name)+1, &info.filename,strlen(org_name)+1,
&info.rtree_recursion_state,have_rtree ? 1024 : 0, &info.rtree_recursion_state,have_rtree ? 1024 : 0,
NullS)) NullS))
......
...@@ -229,6 +229,7 @@ struct st_myisam_info { ...@@ -229,6 +229,7 @@ struct st_myisam_info {
char *filename; /* parameter to open filename */ char *filename; /* parameter to open filename */
uchar *buff, /* Temp area for key */ uchar *buff, /* Temp area for key */
*lastkey,*lastkey2; /* Last used search key */ *lastkey,*lastkey2; /* Last used search key */
uchar *first_mbr_key; /* Searhed spatial key */
byte *rec_buff; /* Tempbuff for recordpack */ byte *rec_buff; /* Tempbuff for recordpack */
uchar *int_keypos, /* Save position for next/previous */ uchar *int_keypos, /* Save position for next/previous */
*int_maxpos; /* -""- */ *int_maxpos; /* -""- */
......
...@@ -86,7 +86,7 @@ static int rtree_find_req(MI_INFO *info, MI_KEYDEF *keyinfo, uint search_flag, ...@@ -86,7 +86,7 @@ static int rtree_find_req(MI_INFO *info, MI_KEYDEF *keyinfo, uint search_flag,
if (nod_flag) if (nod_flag)
{ {
/* this is an internal node in the tree */ /* this is an internal node in the tree */
if (!(res = rtree_key_cmp(keyinfo->seg, info->lastkey2, k, if (!(res = rtree_key_cmp(keyinfo->seg, info->first_mbr_key, k,
info->last_rkey_length, nod_cmp_flag))) info->last_rkey_length, nod_cmp_flag)))
{ {
switch ((res = rtree_find_req(info, keyinfo, search_flag, nod_cmp_flag, switch ((res = rtree_find_req(info, keyinfo, search_flag, nod_cmp_flag,
...@@ -107,7 +107,7 @@ static int rtree_find_req(MI_INFO *info, MI_KEYDEF *keyinfo, uint search_flag, ...@@ -107,7 +107,7 @@ static int rtree_find_req(MI_INFO *info, MI_KEYDEF *keyinfo, uint search_flag,
else else
{ {
/* this is a leaf */ /* this is a leaf */
if (!rtree_key_cmp(keyinfo->seg, info->lastkey2, k, if (!rtree_key_cmp(keyinfo->seg, info->first_mbr_key, k,
info->last_rkey_length, search_flag)) info->last_rkey_length, search_flag))
{ {
uchar *after_key = rt_PAGE_NEXT_KEY(k, k_len, nod_flag); uchar *after_key = rt_PAGE_NEXT_KEY(k, k_len, nod_flag);
...@@ -180,7 +180,8 @@ int rtree_find_first(MI_INFO *info, uint keynr, uchar *key, uint key_length, ...@@ -180,7 +180,8 @@ int rtree_find_first(MI_INFO *info, uint keynr, uchar *key, uint key_length,
} }
/* Save searched key */ /* Save searched key */
memcpy(info->lastkey2, key, keyinfo->keylength - info->s->base.rec_reflength); memcpy(info->first_mbr_key, key, keyinfo->keylength -
info->s->base.rec_reflength);
info->last_rkey_length = key_length; info->last_rkey_length = key_length;
info->rtree_recursion_depth = -1; info->rtree_recursion_depth = -1;
...@@ -195,6 +196,12 @@ int rtree_find_first(MI_INFO *info, uint keynr, uchar *key, uint key_length, ...@@ -195,6 +196,12 @@ int rtree_find_first(MI_INFO *info, uint keynr, uchar *key, uint key_length,
/* /*
Find next key in r-tree according to search_flag condition Find next key in r-tree according to search_flag condition
SYNOPSIS
rtree_find_next()
info Handler to MyISAM file
uint keynr Key number to use
search_flag Bitmap of flags how to do the search
RETURN RETURN
-1 Error -1 Error
0 Found 0 Found
...@@ -217,7 +224,7 @@ int rtree_find_next(MI_INFO *info, uint keynr, uint search_flag) ...@@ -217,7 +224,7 @@ int rtree_find_next(MI_INFO *info, uint keynr, uint search_flag)
while (key < info->int_maxpos) while (key < info->int_maxpos)
{ {
if (!rtree_key_cmp(keyinfo->seg, info->lastkey2, key, if (!rtree_key_cmp(keyinfo->seg, info->first_mbr_key, key,
info->last_rkey_length, search_flag)) info->last_rkey_length, search_flag))
{ {
uchar *after_key = key + keyinfo->keylength; uchar *after_key = key + keyinfo->keylength;
...@@ -353,13 +360,16 @@ err1: ...@@ -353,13 +360,16 @@ err1:
return -1; return -1;
} }
/* /*
Get first key in r-tree Get first key in r-tree
Result values:
-1 - error RETURN
0 - found -1 Error
1 - not found 0 Found
1 Not found
*/ */
int rtree_get_first(MI_INFO *info, uint keynr, uint key_length) int rtree_get_first(MI_INFO *info, uint keynr, uint key_length)
{ {
my_off_t root; my_off_t root;
...@@ -377,12 +387,16 @@ int rtree_get_first(MI_INFO *info, uint keynr, uint key_length) ...@@ -377,12 +387,16 @@ int rtree_get_first(MI_INFO *info, uint keynr, uint key_length)
return rtree_get_req(info, &keyinfo[keynr], key_length, root, 0); return rtree_get_req(info, &keyinfo[keynr], key_length, root, 0);
} }
/* Get next key in r-tree
Result values: /*
-1 - error Get next key in r-tree
0 - found
1 - not found RETURN
-1 Error
0 Found
1 Not found
*/ */
int rtree_get_next(MI_INFO *info, uint keynr, uint key_length) int rtree_get_next(MI_INFO *info, uint keynr, uint key_length)
{ {
my_off_t root; my_off_t root;
...@@ -421,13 +435,16 @@ int rtree_get_next(MI_INFO *info, uint keynr, uint key_length) ...@@ -421,13 +435,16 @@ int rtree_get_next(MI_INFO *info, uint keynr, uint key_length)
} }
} }
/* /*
Go down and insert key into tree Go down and insert key into tree
Result values:
-1 - error RETURN
0 - child was not split -1 Error
1 - child was split 0 Child was not split
1 Child was split
*/ */
static int rtree_insert_req(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, static int rtree_insert_req(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key,
uint key_length, my_off_t page, my_off_t *new_page, uint key_length, my_off_t page, my_off_t *new_page,
int ins_level, int level) int ins_level, int level)
...@@ -504,13 +521,16 @@ err1: ...@@ -504,13 +521,16 @@ err1:
return -1; return -1;
} }
/* /*
Insert key into the tree Insert key into the tree
Result values:
-1 - error RETURN
0 - root was not split -1 Error
1 - root was split 0 Root was not split
1 Root was split
*/ */
static int rtree_insert_level(MI_INFO *info, uint keynr, uchar *key, static int rtree_insert_level(MI_INFO *info, uint keynr, uchar *key,
uint key_length, int ins_level) uint key_length, int ins_level)
{ {
...@@ -594,20 +614,29 @@ err1: ...@@ -594,20 +614,29 @@ err1:
return res; return res;
} }
/* /*
Insert key into the tree - interface function Insert key into the tree - interface function
Result values:
-1 - error RETURN
0 - OK -1 Error
0 OK
*/ */
int rtree_insert(MI_INFO *info, uint keynr, uchar *key, uint key_length) int rtree_insert(MI_INFO *info, uint keynr, uchar *key, uint key_length)
{ {
return (rtree_insert_level(info, keynr, key, key_length, -1) == -1) ? -1 : 0; return (rtree_insert_level(info, keynr, key, key_length, -1) == -1) ? -1 : 0;
} }
/* /*
Fill reinsert page buffer Fill reinsert page buffer
RETURN
-1 Error
0 OK
*/ */
static int rtree_fill_reinsert_list(stPageList *ReinsertList, my_off_t page, static int rtree_fill_reinsert_list(stPageList *ReinsertList, my_off_t page,
int level) int level)
{ {
...@@ -628,14 +657,17 @@ err1: ...@@ -628,14 +657,17 @@ err1:
return -1; return -1;
} }
/* /*
Go down and delete key from the tree Go down and delete key from the tree
Result values:
-1 - error RETURN
0 - deleted -1 Error
1 - not found 0 Deleted
2 - empty leaf 1 Not found
2 Empty leaf
*/ */
static int rtree_delete_req(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, static int rtree_delete_req(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key,
uint key_length, my_off_t page, uint *page_size, uint key_length, my_off_t page, uint *page_size,
stPageList *ReinsertList, int level) stPageList *ReinsertList, int level)
...@@ -754,12 +786,15 @@ err1: ...@@ -754,12 +786,15 @@ err1:
return -1; return -1;
} }
/* /*
Delete key - interface function Delete key - interface function
Result values:
-1 - error RETURN
0 - deleted -1 Error
0 Deleted
*/ */
int rtree_delete(MI_INFO *info, uint keynr, uchar *key, uint key_length) int rtree_delete(MI_INFO *info, uint keynr, uchar *key, uint key_length)
{ {
uint page_size; uint page_size;
...@@ -860,9 +895,14 @@ err1: ...@@ -860,9 +895,14 @@ err1:
} }
} }
/* /*
Estimate number of suitable keys in the tree Estimate number of suitable keys in the tree
RETURN
estimated value
*/ */
ha_rows rtree_estimate(MI_INFO *info, uint keynr, uchar *key, ha_rows rtree_estimate(MI_INFO *info, uint keynr, uchar *key,
uint key_length, uint flag) uint key_length, uint flag)
{ {
......
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