~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to storage/maria/ma_rt_key.c

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2006 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 "maria_def.h"
 
17
#include "trnman.h"
 
18
#include "ma_key_recover.h"
 
19
 
 
20
#ifdef HAVE_RTREE_KEYS
 
21
#include "ma_rt_index.h"
 
22
#include "ma_rt_key.h"
 
23
#include "ma_rt_mbr.h"
 
24
 
 
25
/*
 
26
  Add key to the page
 
27
 
 
28
  RESULT VALUES
 
29
    -1  Error
 
30
    0   Not split
 
31
    1   Split
 
32
*/
 
33
 
 
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)
 
36
{
 
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");
 
43
 
 
44
  if (page_size + tot_key_length <=
 
45
      (uint)(key->keyinfo->block_length - KEYPAGE_CHECKSUM_SIZE))
 
46
  {
 
47
    /* split won't be necessary */
 
48
    if (nod_flag)
 
49
    {
 
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;
 
54
    }
 
55
    /* save key */
 
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))
 
62
      DBUG_RETURN(-1);
 
63
    DBUG_RETURN(0);
 
64
  }
 
65
  DBUG_RETURN(maria_rtree_split_page(info, key, page, page_buf, new_page)
 
66
              ? -1 : 1);
 
67
}
 
68
 
 
69
 
 
70
/*
 
71
  Delete key from the page
 
72
 
 
73
  Notes
 
74
  key_length is only the data part of the key
 
75
*/
 
76
 
 
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)
 
79
{
 
80
  MARIA_SHARE *share= info->s;
 
81
  uint16 page_size= _ma_get_page_used(share, page_buf);
 
82
  uint key_length_with_nod_flag;
 
83
  uchar *key_start;
 
84
 
 
85
  key_start= key - nod_flag;
 
86
  if (!nod_flag)
 
87
    key_length+= share->base.rec_reflength;
 
88
 
 
89
  memmove(key_start, key + key_length, page_size - key_length -
 
90
          (key - page_buf));
 
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))
 
97
 
 
98
    return -1;
 
99
  return 0;
 
100
}
 
101
 
 
102
 
 
103
/*
 
104
  Calculate and store key MBR into *key.
 
105
*/
 
106
 
 
107
int maria_rtree_set_key_mbr(MARIA_HA *info, MARIA_KEY *key,
 
108
                            my_off_t child_page)
 
109
{
 
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))
 
114
    DBUG_RETURN(-1);
 
115
 
 
116
  DBUG_RETURN(maria_rtree_page_mbr(info, key->keyinfo->seg,
 
117
                                   info->buff, key->data,
 
118
                                   key->data_length));
 
119
}
 
120
 
 
121
#endif /*HAVE_RTREE_KEYS*/