1 /* Copyright (c) 2000, 2002-2005, 2007 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 #include "myisamdef.h"
18 #ifdef HAVE_RTREE_KEYS
32 int rtree_add_key(MI_INFO
*info
, MI_KEYDEF
*keyinfo
, uchar
*key
,
33 uint key_length
, uchar
*page_buf
, my_off_t
*new_page
)
35 uint page_size
= mi_getint(page_buf
);
36 uint nod_flag
= mi_test_if_nod(page_buf
);
37 DBUG_ENTER("rtree_add_key");
39 if (page_size
+ key_length
+ info
->s
->base
.rec_reflength
<=
40 keyinfo
->block_length
)
42 /* split won't be necessary */
46 DBUG_ASSERT(_mi_kpos(nod_flag
, key
) < info
->state
->key_file_length
);
47 memcpy(rt_PAGE_END(page_buf
), key
- nod_flag
, key_length
+ nod_flag
);
48 page_size
+= key_length
+ nod_flag
;
53 DBUG_ASSERT(_mi_dpos(info
, nod_flag
, key
+ key_length
+
54 info
->s
->base
.rec_reflength
) <
55 info
->state
->data_file_length
+ info
->s
->base
.pack_reclength
);
56 memcpy(rt_PAGE_END(page_buf
), key
, key_length
+
57 info
->s
->base
.rec_reflength
);
58 page_size
+= key_length
+ info
->s
->base
.rec_reflength
;
60 mi_putint(page_buf
, page_size
, nod_flag
);
64 DBUG_RETURN((rtree_split_page(info
, keyinfo
, page_buf
, key
, key_length
,
69 Delete key from the page
71 int rtree_delete_key(MI_INFO
*info
, uchar
*page_buf
, uchar
*key
,
72 uint key_length
, uint nod_flag
)
74 uint16 page_size
= mi_getint(page_buf
);
77 key_start
= key
- nod_flag
;
79 key_length
+= info
->s
->base
.rec_reflength
;
81 memmove(key_start
, key
+ key_length
, page_size
- key_length
-
83 page_size
-= key_length
+ nod_flag
;
85 mi_putint(page_buf
, page_size
, nod_flag
);
91 Calculate and store key MBR
94 int rtree_set_key_mbr(MI_INFO
*info
, MI_KEYDEF
*keyinfo
, uchar
*key
,
95 uint key_length
, my_off_t child_page
)
97 DBUG_ENTER("rtree_set_key_mbr");
99 if (!_mi_fetch_keypage(info
, keyinfo
, child_page
,
100 DFLT_INIT_HITS
, info
->buff
, 0))
101 DBUG_RETURN(-1); /* purecov: inspected */
103 DBUG_RETURN(rtree_page_mbr(info
, keyinfo
->seg
, info
->buff
, key
, key_length
));
106 #endif /*HAVE_RTREE_KEYS*/