1
/* Copyright (C) 2006 MySQL AB & Ramil Kalimullin
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "maria_def.h"
18
#include "ma_key_recover.h"
20
#ifdef HAVE_RTREE_KEYS
21
#include "ma_rt_index.h"
22
#include "ma_rt_key.h"
23
#include "ma_rt_mbr.h"
34
int maria_rtree_add_key(MARIA_HA *info, const MARIA_KEY *key,
35
uchar *page_buf, my_off_t page, my_off_t *new_page)
37
MARIA_SHARE *share= info->s;
38
uint page_size= _ma_get_page_used(share, page_buf);
39
uint nod_flag= _ma_test_if_nod(share, page_buf);
40
uchar *key_pos= rt_PAGE_END(share, page_buf);
41
uint tot_key_length= key->data_length + key->ref_length + nod_flag;
42
DBUG_ENTER("maria_rtree_add_key");
44
if (page_size + tot_key_length <=
45
(uint)(key->keyinfo->block_length - KEYPAGE_CHECKSUM_SIZE))
47
/* split won't be necessary */
50
DBUG_ASSERT(_ma_kpos(nod_flag, key->data) <
51
info->state->key_file_length);
52
/* We don't store reference to row on nod pages for rtree index */
53
tot_key_length-= key->ref_length;
56
memcpy(key_pos, key->data - nod_flag, tot_key_length);
57
page_size+= tot_key_length;
58
_ma_store_page_used(share, page_buf, page_size);
59
if (share->now_transactional &&
60
_ma_log_add(info, page, page_buf, key_pos - page_buf,
61
key_pos, tot_key_length, tot_key_length, 0))
65
DBUG_RETURN(maria_rtree_split_page(info, key, page, page_buf, new_page)
71
Delete key from the page
74
key_length is only the data part of the key
77
int maria_rtree_delete_key(MARIA_HA *info, uchar *page_buf, uchar *key,
78
uint key_length, uint nod_flag, my_off_t page)
80
MARIA_SHARE *share= info->s;
81
uint16 page_size= _ma_get_page_used(share, page_buf);
82
uint key_length_with_nod_flag;
85
key_start= key - nod_flag;
87
key_length+= share->base.rec_reflength;
89
memmove(key_start, key + key_length, page_size - key_length -
91
key_length_with_nod_flag= key_length + nod_flag;
92
page_size-= key_length_with_nod_flag;
93
_ma_store_page_used(share, page_buf, page_size);
94
if (share->now_transactional &&
95
_ma_log_delete(info, page, page_buf, key_start, 0,
96
key_length_with_nod_flag))
104
Calculate and store key MBR into *key.
107
int maria_rtree_set_key_mbr(MARIA_HA *info, MARIA_KEY *key,
110
DBUG_ENTER("maria_rtree_set_key_mbr");
111
if (!_ma_fetch_keypage(info, key->keyinfo, child_page,
112
PAGECACHE_LOCK_LEFT_UNLOCKED,
113
DFLT_INIT_HITS, info->buff, 0, 0))
116
DBUG_RETURN(maria_rtree_page_mbr(info, key->keyinfo->seg,
117
info->buff, key->data,
121
#endif /*HAVE_RTREE_KEYS*/