~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_delete.c

Renamed more stuff to drizzle.

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 "heap_priv.h"
 
18
#include "heapdef.h"
19
19
 
20
 
int heap_delete(HP_INFO *info, const unsigned char *record)
 
20
int heap_delete(HP_INFO *info, const uchar *record)
21
21
{
22
 
  unsigned char *pos;
23
 
  HP_SHARE *share=info->getShare();
 
22
  uchar *pos;
 
23
  HP_SHARE *share=info->s;
24
24
  HP_KEYDEF *keydef, *end, *p_lastinx;
 
25
  DBUG_ENTER("heap_delete");
 
26
  DBUG_PRINT("enter",("info: 0x%lx  record: 0x%lx", (long) info, (long) record));
25
27
 
26
28
  test_active(info);
27
29
 
28
 
  if (info->opt_flag & READ_CHECK_USED)
29
 
    return(errno);                      /* Record changed */
 
30
  if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,record))
 
31
    DBUG_RETURN(my_errno);                      /* Record changed */
30
32
  share->changed=1;
31
33
 
32
34
  if ( --(share->records) < share->blength >> 1) share->blength>>=1;
33
35
  pos=info->current_ptr;
34
36
 
35
37
  p_lastinx = share->keydef + info->lastinx;
36
 
  for (keydef = share->keydef, end = keydef + share->keys; keydef < end;
 
38
  for (keydef = share->keydef, end = keydef + share->keys; keydef < end; 
37
39
       keydef++)
38
40
  {
39
 
    if (hp_delete_key(info, keydef, record, pos, keydef == p_lastinx))
 
41
    if ((*keydef->delete_key)(info, keydef, record, pos, keydef == p_lastinx))
40
42
      goto err;
41
43
  }
42
44
 
43
45
  info->update=HA_STATE_DELETED;
44
 
  hp_free_chunks(&share->recordspace, pos);
 
46
  *((uchar**) pos)=share->del_link;
 
47
  share->del_link=pos;
 
48
  pos[share->reclength]=0;              /* Record deleted */
 
49
  share->deleted++;
45
50
  info->current_hash_ptr=0;
 
51
#if !defined(DBUG_OFF) && defined(EXTRA_HEAP_DEBUG)
 
52
  DBUG_EXECUTE("check_heap",heap_check_heap(info, 0););
 
53
#endif
46
54
 
47
 
  return(0);
 
55
  DBUG_RETURN(0);
48
56
err:
49
57
  if (++(share->records) == share->blength)
50
58
    share->blength+= share->blength;
51
 
  return(errno);
 
59
  DBUG_RETURN(my_errno);
 
60
}
 
61
 
 
62
 
 
63
/*
 
64
  Remove one key from rb-tree
 
65
*/
 
66
 
 
67
int hp_rb_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo,
 
68
                   const uchar *record, uchar *recpos, int flag)
 
69
{
 
70
  heap_rb_param custom_arg;
 
71
  uint old_allocated;
 
72
  int res;
 
73
 
 
74
  if (flag) 
 
75
    info->last_pos= NULL; /* For heap_rnext/heap_rprev */
 
76
 
 
77
  custom_arg.keyseg= keyinfo->seg;
 
78
  custom_arg.key_length= hp_rb_make_key(keyinfo, info->recbuf, record, recpos);
 
79
  custom_arg.search_flag= SEARCH_SAME;
 
80
  old_allocated= keyinfo->rb_tree.allocated;
 
81
  res= tree_delete(&keyinfo->rb_tree, info->recbuf, custom_arg.key_length,
 
82
                   &custom_arg);
 
83
  info->s->index_length-= (old_allocated - keyinfo->rb_tree.allocated);
 
84
  return res;
52
85
}
53
86
 
54
87
 
69
102
*/
70
103
 
71
104
int hp_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo,
72
 
                  const unsigned char *record, unsigned char *recpos, int flag)
 
105
                  const uchar *record, uchar *recpos, int flag)
73
106
{
74
 
  uint32_t blength,pos2,pos_hashnr,lastpos_hashnr;
 
107
  ulong blength,pos2,pos_hashnr,lastpos_hashnr;
75
108
  HASH_INFO *lastpos,*gpos,*pos,*pos3,*empty,*last_ptr;
76
 
  HP_SHARE *share=info->getShare();
 
109
  HP_SHARE *share=info->s;
 
110
  DBUG_ENTER("hp_delete_key");
77
111
 
78
112
  blength=share->blength;
79
113
  if (share->records+1 == blength)
80
114
    blength+= blength;
81
 
 
82
 
  /* find the very last HASH_INFO pointer in the index */
83
 
  /* note that records has already been decremented */
84
115
  lastpos=hp_find_hash(&keyinfo->block,share->records);
85
116
  last_ptr=0;
86
117
 
97
128
    gpos=pos;
98
129
    if (!(pos=pos->next_key))
99
130
    {
100
 
      return(errno=HA_ERR_CRASHED);     /* This shouldn't happend */
 
131
      DBUG_RETURN(my_errno=HA_ERR_CRASHED);     /* This shouldn't happend */
101
132
    }
102
133
  }
103
134
 
108
139
    /* Save for heap_rnext/heap_rprev */
109
140
    info->current_hash_ptr=last_ptr;
110
141
    info->current_ptr = last_ptr ? last_ptr->ptr_to_rec : 0;
 
142
    DBUG_PRINT("info",("Corrected current_ptr to point at: 0x%lx",
 
143
                       (long) info->current_ptr));
111
144
  }
112
145
  empty=pos;
113
 
  if (gpos) {
114
 
    /* gpos says we have previous HASH_INFO, change previous to point to next, this way unlinking "empty" */
115
 
    gpos->next_key=pos->next_key;
116
 
  }
 
146
  if (gpos)
 
147
    gpos->next_key=pos->next_key;       /* unlink current ptr */
117
148
  else if (pos->next_key)
118
149
  {
119
 
    /* no previous gpos, this pos is the first in the list and it has pointer to "next" */
120
 
    /* move next HASH_INFO data to our pos, to free up space at the next position */
121
 
    /* remember next pos as "empty", nobody refers to "empty" at this point */
122
150
    empty=pos->next_key;
123
151
    pos->ptr_to_rec=empty->ptr_to_rec;
124
152
    pos->next_key=empty->next_key;
125
153
  }
126
154
  else
127
 
  {
128
 
    /* this was the only HASH_INFO at this position */
129
155
    keyinfo->hash_buckets--;
130
 
  }
131
156
 
132
157
  if (empty == lastpos)                 /* deleted last hash key */
133
 
    return (0);
 
158
    DBUG_RETURN (0);
134
159
 
135
160
  /* Move the last key (lastpos) */
136
161
  lastpos_hashnr = hp_rec_hashnr(keyinfo, lastpos->ptr_to_rec);
140
165
  if (pos == empty)                     /* Move to empty position. */
141
166
  {
142
167
    empty[0]=lastpos[0];
143
 
    return(0);
 
168
    DBUG_RETURN(0);
144
169
  }
145
170
  pos_hashnr = hp_rec_hashnr(keyinfo, pos->ptr_to_rec);
146
171
  /* pos3 is where the pos should be */
151
176
    empty[0]=pos[0];                    /* Save it here */
152
177
    pos[0]=lastpos[0];                  /* This shold be here */
153
178
    hp_movelink(pos, pos3, empty);      /* Fix link to pos */
154
 
    return(0);
 
179
    DBUG_RETURN(0);
155
180
  }
156
181
  pos2= hp_mask(lastpos_hashnr, blength, share->records + 1);
157
182
  if (pos2 == hp_mask(pos_hashnr, blength, share->records + 1))
160
185
    {
161
186
      empty[0]=lastpos[0];
162
187
      hp_movelink(lastpos, pos, empty);
163
 
      return(0);
 
188
      DBUG_RETURN(0);
164
189
    }
165
190
    pos3= pos;                          /* Link pos->next after lastpos */
166
191
  }
173
198
  empty[0]=lastpos[0];
174
199
  hp_movelink(pos3, empty, pos->next_key);
175
200
  pos->next_key=empty;
176
 
  return(0);
 
201
  DBUG_RETURN(0);
177
202
}