~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/hp_rkey.cc

  • Committer: Monty Taylor
  • Date: 2009-04-25 20:45:19 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 1003.
  • Revision ID: mordred@inaugust.com-20090425204519-lgrl7mz2r66v0jby
Blackhole.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2004, 2006 MySQL AB
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 "heap_priv.h"
17
 
 
18
 
#include <string.h>
19
 
 
20
 
using namespace drizzled;
21
 
 
22
 
int heap_rkey(HP_INFO *info, unsigned char *record, int inx, const unsigned char *key,
23
 
              key_part_map keypart_map, enum ha_rkey_function find_flag)
24
 
{
25
 
  unsigned char *pos;
26
 
  HP_SHARE *share= info->s;
27
 
  HP_KEYDEF *keyinfo= share->keydef + inx;
28
 
 
29
 
  if ((uint) inx >= share->keys)
30
 
  {
31
 
    return(errno= HA_ERR_WRONG_INDEX);
32
 
  }
33
 
  info->lastinx= inx;
34
 
  info->current_record= UINT32_MAX;             /* For heap_rrnd() */
35
 
 
36
 
  if (keyinfo->algorithm == HA_KEY_ALG_BTREE)
37
 
  {
38
 
    heap_rb_param custom_arg;
39
 
 
40
 
    custom_arg.keyseg= info->s->keydef[inx].seg;
41
 
    custom_arg.key_length= info->lastkey_len=
42
 
      hp_rb_pack_key(keyinfo, (unsigned char*) info->lastkey,
43
 
                     (unsigned char*) key, keypart_map);
44
 
    custom_arg.search_flag= SEARCH_FIND | SEARCH_SAME;
45
 
    /* for next rkey() after deletion */
46
 
    if (find_flag == HA_READ_AFTER_KEY)
47
 
      info->last_find_flag= HA_READ_KEY_OR_NEXT;
48
 
    else if (find_flag == HA_READ_BEFORE_KEY)
49
 
      info->last_find_flag= HA_READ_KEY_OR_PREV;
50
 
    else
51
 
      info->last_find_flag= find_flag;
52
 
    if (!(pos= (unsigned char *)tree_search_key(&keyinfo->rb_tree,
53
 
                                                info->lastkey, info->parents,
54
 
                                                &info->last_pos,
55
 
                                                find_flag, &custom_arg)))
56
 
    {
57
 
      info->update= 0;
58
 
      return(errno= HA_ERR_KEY_NOT_FOUND);
59
 
    }
60
 
    memcpy(&pos, pos + (*keyinfo->get_key_length)(keyinfo, pos), sizeof(unsigned char*));
61
 
    info->current_ptr= pos;
62
 
  }
63
 
  else
64
 
  {
65
 
    if (!(pos= hp_search(info, share->keydef + inx, key, 0)))
66
 
    {
67
 
      info->update= 0;
68
 
      return(errno);
69
 
    }
70
 
    if (!(keyinfo->flag & HA_NOSAME))
71
 
      memcpy(info->lastkey, key, (size_t) keyinfo->length);
72
 
  }
73
 
  hp_extract_record(share, record, pos);
74
 
  info->update= HA_STATE_AKTIV;
75
 
  return(0);
76
 
}
77
 
 
78
 
 
79
 
        /* Quick find of record */
80
 
 
81
 
unsigned char* heap_find(HP_INFO *info, int inx, const unsigned char *key)
82
 
{
83
 
  return hp_search(info, info->s->keydef + inx, key, 0);
84
 
}