~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_delete.c

  • Committer: Monty Taylor
  • Date: 2008-07-09 19:33:54 UTC
  • mto: (77.6.1 glibclient-merge)
  • mto: This revision was merged to the branch mainline in revision 124.
  • Revision ID: monty@inaugust.com-20080709193354-vi0pemwf40galnll
First step of sql-common removal (the cheap way) 

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