~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/hp_delete.cc

Merge Monty.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* remove current record in heap-database */
17
17
 
18
 
#include "heapdef.h"
 
18
#include "heap_priv.h"
19
19
 
20
 
int heap_delete(HP_INFO *info, const uchar *record)
 
20
int heap_delete(HP_INFO *info, const unsigned char *record)
21
21
{
22
 
  uchar *pos;
 
22
  unsigned char *pos;
23
23
  HP_SHARE *share=info->s;
24
24
  HP_KEYDEF *keydef, *end, *p_lastinx;
 
25
  uint32_t rec_length, chunk_count;
25
26
 
26
27
  test_active(info);
27
28
 
28
29
  if (info->opt_flag & READ_CHECK_USED)
29
 
    return(my_errno);                   /* Record changed */
 
30
    return(errno);                      /* Record changed */
30
31
  share->changed=1;
31
32
 
 
33
  rec_length = hp_get_encoded_data_length(share, record, &chunk_count);
 
34
 
32
35
  if ( --(share->records) < share->blength >> 1) share->blength>>=1;
33
36
  pos=info->current_ptr;
34
37
 
35
38
  p_lastinx = share->keydef + info->lastinx;
36
 
  for (keydef = share->keydef, end = keydef + share->keys; keydef < end; 
 
39
  for (keydef = share->keydef, end = keydef + share->keys; keydef < end;
37
40
       keydef++)
38
41
  {
39
42
    if ((*keydef->delete_key)(info, keydef, record, pos, keydef == p_lastinx))
41
44
  }
42
45
 
43
46
  info->update=HA_STATE_DELETED;
44
 
  *((uchar**) pos)=share->del_link;
45
 
  share->del_link=pos;
46
 
  pos[share->reclength]=0;              /* Record deleted */
47
 
  share->deleted++;
 
47
  hp_free_chunks(&share->recordspace, pos);
48
48
  info->current_hash_ptr=0;
49
49
 
50
50
  return(0);
51
51
err:
52
52
  if (++(share->records) == share->blength)
53
53
    share->blength+= share->blength;
54
 
  return(my_errno);
 
54
  return(errno);
55
55
}
56
56
 
57
57
 
60
60
*/
61
61
 
62
62
int hp_rb_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo,
63
 
                   const uchar *record, uchar *recpos, int flag)
 
63
                   const unsigned char *record, unsigned char *recpos, int flag)
64
64
{
65
65
  heap_rb_param custom_arg;
66
 
  uint old_allocated;
 
66
  uint32_t old_allocated;
67
67
  int res;
68
68
 
69
 
  if (flag) 
 
69
  if (flag)
70
70
    info->last_pos= NULL; /* For heap_rnext/heap_rprev */
71
71
 
72
72
  custom_arg.keyseg= keyinfo->seg;
97
97
*/
98
98
 
99
99
int hp_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo,
100
 
                  const uchar *record, uchar *recpos, int flag)
 
100
                  const unsigned char *record, unsigned char *recpos, int flag)
101
101
{
102
 
  ulong blength,pos2,pos_hashnr,lastpos_hashnr;
 
102
  uint32_t blength,pos2,pos_hashnr,lastpos_hashnr;
103
103
  HASH_INFO *lastpos,*gpos,*pos,*pos3,*empty,*last_ptr;
104
104
  HP_SHARE *share=info->s;
105
105
 
106
106
  blength=share->blength;
107
107
  if (share->records+1 == blength)
108
108
    blength+= blength;
 
109
 
 
110
  /* find the very last HASH_INFO pointer in the index */
 
111
  /* note that records has already been decremented */
109
112
  lastpos=hp_find_hash(&keyinfo->block,share->records);
110
113
  last_ptr=0;
111
114
 
122
125
    gpos=pos;
123
126
    if (!(pos=pos->next_key))
124
127
    {
125
 
      return(my_errno=HA_ERR_CRASHED);  /* This shouldn't happend */
 
128
      return(errno=HA_ERR_CRASHED);     /* This shouldn't happend */
126
129
    }
127
130
  }
128
131
 
135
138
    info->current_ptr = last_ptr ? last_ptr->ptr_to_rec : 0;
136
139
  }
137
140
  empty=pos;
138
 
  if (gpos)
139
 
    gpos->next_key=pos->next_key;       /* unlink current ptr */
 
141
  if (gpos) {
 
142
    /* gpos says we have previous HASH_INFO, change previous to point to next, this way unlinking "empty" */
 
143
    gpos->next_key=pos->next_key;
 
144
  }
140
145
  else if (pos->next_key)
141
146
  {
 
147
    /* no previous gpos, this pos is the first in the list and it has pointer to "next" */
 
148
    /* move next HASH_INFO data to our pos, to free up space at the next position */
 
149
    /* remember next pos as "empty", nobody refers to "empty" at this point */
142
150
    empty=pos->next_key;
143
151
    pos->ptr_to_rec=empty->ptr_to_rec;
144
152
    pos->next_key=empty->next_key;
145
153
  }
146
154
  else
 
155
  {
 
156
    /* this was the only HASH_INFO at this position */
147
157
    keyinfo->hash_buckets--;
 
158
  }
148
159
 
149
160
  if (empty == lastpos)                 /* deleted last hash key */
150
161
    return (0);