~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_delete.c

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#include "heapdef.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
 
  DBUG_ENTER("heap_delete");
26
 
  DBUG_PRINT("enter",("info: 0x%lx  record: 0x%lx", (long) info, (long) record));
 
25
  uint32_t rec_length, chunk_count;
27
26
 
28
27
  test_active(info);
29
28
 
30
 
  if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,record))
31
 
    DBUG_RETURN(my_errno);                      /* Record changed */
 
29
  if (info->opt_flag & READ_CHECK_USED)
 
30
    return(my_errno);                   /* Record changed */
32
31
  share->changed=1;
33
32
 
 
33
  rec_length = hp_get_encoded_data_length(share, record, &chunk_count);
 
34
 
34
35
  if ( --(share->records) < share->blength >> 1) share->blength>>=1;
35
36
  pos=info->current_ptr;
36
37
 
43
44
  }
44
45
 
45
46
  info->update=HA_STATE_DELETED;
46
 
  *((uchar**) pos)=share->del_link;
47
 
  share->del_link=pos;
48
 
  pos[share->reclength]=0;              /* Record deleted */
49
 
  share->deleted++;
 
47
  hp_free_chunks(&share->recordspace, pos);
50
48
  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
54
49
 
55
 
  DBUG_RETURN(0);
 
50
  return(0);
56
51
err:
57
52
  if (++(share->records) == share->blength)
58
53
    share->blength+= share->blength;
59
 
  DBUG_RETURN(my_errno);
 
54
  return(my_errno);
60
55
}
61
56
 
62
57
 
65
60
*/
66
61
 
67
62
int hp_rb_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo,
68
 
                   const uchar *record, uchar *recpos, int flag)
 
63
                   const unsigned char *record, unsigned char *recpos, int flag)
69
64
{
70
65
  heap_rb_param custom_arg;
71
 
  uint old_allocated;
 
66
  uint32_t old_allocated;
72
67
  int res;
73
68
 
74
69
  if (flag) 
102
97
*/
103
98
 
104
99
int hp_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo,
105
 
                  const uchar *record, uchar *recpos, int flag)
 
100
                  const unsigned char *record, unsigned char *recpos, int flag)
106
101
{
107
 
  ulong blength,pos2,pos_hashnr,lastpos_hashnr;
 
102
  uint32_t blength,pos2,pos_hashnr,lastpos_hashnr;
108
103
  HASH_INFO *lastpos,*gpos,*pos,*pos3,*empty,*last_ptr;
109
104
  HP_SHARE *share=info->s;
110
 
  DBUG_ENTER("hp_delete_key");
111
105
 
112
106
  blength=share->blength;
113
107
  if (share->records+1 == blength)
114
108
    blength+= blength;
 
109
 
 
110
  /* find the very last HASH_INFO pointer in the index */
 
111
  /* note that records has already been decremented */
115
112
  lastpos=hp_find_hash(&keyinfo->block,share->records);
116
113
  last_ptr=0;
117
114
 
128
125
    gpos=pos;
129
126
    if (!(pos=pos->next_key))
130
127
    {
131
 
      DBUG_RETURN(my_errno=HA_ERR_CRASHED);     /* This shouldn't happend */
 
128
      return(my_errno=HA_ERR_CRASHED);  /* This shouldn't happend */
132
129
    }
133
130
  }
134
131
 
139
136
    /* Save for heap_rnext/heap_rprev */
140
137
    info->current_hash_ptr=last_ptr;
141
138
    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));
144
139
  }
145
140
  empty=pos;
146
 
  if (gpos)
147
 
    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
  }
148
145
  else if (pos->next_key)
149
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 */
150
150
    empty=pos->next_key;
151
151
    pos->ptr_to_rec=empty->ptr_to_rec;
152
152
    pos->next_key=empty->next_key;
153
153
  }
154
154
  else
 
155
  {
 
156
    /* this was the only HASH_INFO at this position */
155
157
    keyinfo->hash_buckets--;
 
158
  }
156
159
 
157
160
  if (empty == lastpos)                 /* deleted last hash key */
158
 
    DBUG_RETURN (0);
 
161
    return (0);
159
162
 
160
163
  /* Move the last key (lastpos) */
161
164
  lastpos_hashnr = hp_rec_hashnr(keyinfo, lastpos->ptr_to_rec);
165
168
  if (pos == empty)                     /* Move to empty position. */
166
169
  {
167
170
    empty[0]=lastpos[0];
168
 
    DBUG_RETURN(0);
 
171
    return(0);
169
172
  }
170
173
  pos_hashnr = hp_rec_hashnr(keyinfo, pos->ptr_to_rec);
171
174
  /* pos3 is where the pos should be */
176
179
    empty[0]=pos[0];                    /* Save it here */
177
180
    pos[0]=lastpos[0];                  /* This shold be here */
178
181
    hp_movelink(pos, pos3, empty);      /* Fix link to pos */
179
 
    DBUG_RETURN(0);
 
182
    return(0);
180
183
  }
181
184
  pos2= hp_mask(lastpos_hashnr, blength, share->records + 1);
182
185
  if (pos2 == hp_mask(pos_hashnr, blength, share->records + 1))
185
188
    {
186
189
      empty[0]=lastpos[0];
187
190
      hp_movelink(lastpos, pos, empty);
188
 
      DBUG_RETURN(0);
 
191
      return(0);
189
192
    }
190
193
    pos3= pos;                          /* Link pos->next after lastpos */
191
194
  }
198
201
  empty[0]=lastpos[0];
199
202
  hp_movelink(pos3, empty, pos->next_key);
200
203
  pos->next_key=empty;
201
 
  DBUG_RETURN(0);
 
204
  return(0);
202
205
}