~vadim-tk/percona-server/percona-5.5.15-galera

« back to all changes in this revision

Viewing changes to storage/myisam/rt_key.c

  • Committer: root
  • Date: 2011-09-10 16:37:18 UTC
  • Revision ID: root@r815.office.percona.com-20110910163718-ydh4zj8hcdgoyavb
Porting Galera to 5.5.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 MySQL AB & Ramil Kalimullin
 
2
   
 
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.
 
6
   
 
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.
 
11
   
 
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 */
 
15
 
 
16
#include "myisamdef.h"
 
17
 
 
18
#ifdef HAVE_RTREE_KEYS
 
19
#include "rt_index.h"
 
20
#include "rt_key.h"
 
21
#include "rt_mbr.h"
 
22
 
 
23
/*
 
24
  Add key to the page
 
25
 
 
26
  RESULT VALUES
 
27
    -1  Error
 
28
    0   Not split
 
29
    1   Split
 
30
*/
 
31
 
 
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)
 
34
{
 
35
  uint page_size = mi_getint(page_buf);
 
36
  uint nod_flag = mi_test_if_nod(page_buf);
 
37
  DBUG_ENTER("rtree_add_key");
 
38
 
 
39
  if (page_size + key_length + info->s->base.rec_reflength <=
 
40
      keyinfo->block_length)
 
41
  {
 
42
    /* split won't be necessary */
 
43
    if (nod_flag)
 
44
    {
 
45
      /* save key */
 
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;
 
49
    }
 
50
    else
 
51
    {
 
52
      /* save key */
 
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;
 
59
    }
 
60
    mi_putint(page_buf, page_size, nod_flag);
 
61
    DBUG_RETURN(0);
 
62
  }
 
63
 
 
64
  DBUG_RETURN((rtree_split_page(info, keyinfo, page_buf, key, key_length,
 
65
                                new_page) ? -1 : 1));
 
66
}
 
67
 
 
68
/*
 
69
  Delete key from the page
 
70
*/
 
71
int rtree_delete_key(MI_INFO *info, uchar *page_buf, uchar *key, 
 
72
                     uint key_length, uint nod_flag)
 
73
{
 
74
  uint16 page_size = mi_getint(page_buf);
 
75
  uchar *key_start;
 
76
 
 
77
  key_start= key - nod_flag;
 
78
  if (!nod_flag)
 
79
    key_length += info->s->base.rec_reflength;
 
80
 
 
81
  memmove(key_start, key + key_length, page_size - key_length -
 
82
          (key - page_buf));
 
83
  page_size-= key_length + nod_flag;
 
84
 
 
85
  mi_putint(page_buf, page_size, nod_flag);
 
86
  return 0;
 
87
}
 
88
 
 
89
 
 
90
/*
 
91
  Calculate and store key MBR
 
92
*/
 
93
 
 
94
int rtree_set_key_mbr(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, 
 
95
                      uint key_length, my_off_t child_page)
 
96
{
 
97
  DBUG_ENTER("rtree_set_key_mbr");
 
98
 
 
99
  if (!_mi_fetch_keypage(info, keyinfo, child_page,
 
100
                         DFLT_INIT_HITS, info->buff, 0))
 
101
    DBUG_RETURN(-1); /* purecov: inspected */
 
102
 
 
103
  DBUG_RETURN(rtree_page_mbr(info, keyinfo->seg, info->buff, key, key_length));
 
104
}
 
105
 
 
106
#endif /*HAVE_RTREE_KEYS*/