~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/key.cc

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
       key_length is set to length of key before (not including) field
46
46
*/
47
47
 
48
 
int find_ref_key(KEY *key, uint32_t key_count, unsigned char *record, Field *field,
49
 
                 uint32_t *key_length, uint32_t *keypart)
 
48
int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field,
 
49
                 uint *key_length, uint *keypart)
50
50
{
51
51
  register int i;
52
52
  register KEY *key_info;
53
 
  uint32_t fieldpos;
 
53
  uint fieldpos;
54
54
 
55
55
  fieldpos= field->offset(record);
56
56
 
71
71
       i < (int) key_count ;
72
72
       i++, key_info++)
73
73
  {
74
 
    uint32_t j;
 
74
    uint j;
75
75
    KEY_PART_INFO *key_part;
76
76
    *key_length=0;
77
77
    for (j=0, key_part=key_info->key_part ;
105
105
  @param key_length  specifies length of all keyparts that will be copied
106
106
*/
107
107
 
108
 
void key_copy(unsigned char *to_key, unsigned char *from_record, KEY *key_info,
 
108
void key_copy(uchar *to_key, uchar *from_record, KEY *key_info,
109
109
              unsigned int key_length)
110
110
{
111
 
  uint32_t length;
 
111
  uint length;
112
112
  KEY_PART_INFO *key_part;
113
113
 
114
114
  if (key_length == 0)
125
125
        key_part->key_part_flag & HA_VAR_LENGTH_PART)
126
126
    {
127
127
      key_length-= HA_KEY_BLOB_LENGTH;
128
 
      length= cmin((uint16_t)key_length, key_part->length);
 
128
      length= min((uint16_t)key_length, key_part->length);
129
129
      key_part->field->get_key_image(to_key, length, Field::itRAW);
130
130
      to_key+= HA_KEY_BLOB_LENGTH;
131
131
    }
132
132
    else
133
133
    {
134
 
      length= cmin((uint16_t)key_length, key_part->length);
 
134
      length= min((uint16_t)key_length, key_part->length);
135
135
      Field *field= key_part->field;
136
136
      const CHARSET_INFO * const cs= field->charset();
137
 
      uint32_t bytes= field->get_key_image(to_key, length, Field::itRAW);
 
137
      uint bytes= field->get_key_image(to_key, length, Field::itRAW);
138
138
      if (bytes < length)
139
139
        cs->cset->fill(cs, (char*) to_key + bytes, length - bytes, ' ');
140
140
    }
148
148
  Zero the null components of key tuple.
149
149
*/
150
150
 
151
 
void key_zero_nulls(unsigned char *tuple, KEY *key_info)
 
151
void key_zero_nulls(uchar *tuple, KEY *key_info)
152
152
{
153
153
  KEY_PART_INFO *key_part= key_info->key_part;
154
154
  KEY_PART_INFO *key_part_end= key_part + key_info->key_parts;
173
173
  @param key_length  specifies length of all keyparts that will be restored
174
174
*/
175
175
 
176
 
void key_restore(unsigned char *to_record, unsigned char *from_key, KEY *key_info,
 
176
void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
177
177
                 uint16_t key_length)
178
178
{
179
 
  uint32_t length;
 
179
  uint length;
180
180
  KEY_PART_INFO *key_part;
181
181
 
182
182
  if (key_length == 0)
185
185
  }
186
186
  for (key_part= key_info->key_part ; (int) key_length > 0 ; key_part++)
187
187
  {
188
 
    unsigned char used_uneven_bits= 0;
 
188
    uchar used_uneven_bits= 0;
189
189
    if (key_part->null_bit)
190
190
    {
191
191
      if (*from_key++)
203
203
        Maybe this branch is to be removed, but now we
204
204
        have to ignore GCov compaining.
205
205
      */
206
 
      uint32_t blob_length= uint2korr(from_key);
 
206
      uint blob_length= uint2korr(from_key);
207
207
      Field_blob *field= (Field_blob*) key_part->field;
208
208
      from_key+= HA_KEY_BLOB_LENGTH;
209
209
      key_length-= HA_KEY_BLOB_LENGTH;
217
217
      my_ptrdiff_t ptrdiff= to_record - field->table->record[0];
218
218
      field->move_field_offset(ptrdiff);
219
219
      key_length-= HA_KEY_BLOB_LENGTH;
220
 
      length= cmin(key_length, key_part->length);
 
220
      length= min(key_length, key_part->length);
221
221
      field->set_key_image(from_key, length);
222
222
      from_key+= HA_KEY_BLOB_LENGTH;
223
223
      field->move_field_offset(-ptrdiff);
224
224
    }
225
225
    else
226
226
    {
227
 
      length= cmin(key_length, key_part->length);
 
227
      length= min(key_length, key_part->length);
228
228
      /* skip the byte with 'uneven' bits, if used */
229
229
      memcpy(to_record + key_part->offset, from_key + used_uneven_bits
230
230
             , (size_t) length - used_uneven_bits);
255
255
    1   Key has changed
256
256
*/
257
257
 
258
 
bool key_cmp_if_same(Table *table,const unsigned char *key,uint32_t idx,uint32_t key_length)
 
258
bool key_cmp_if_same(Table *table,const uchar *key,uint idx,uint key_length)
259
259
{
260
 
  uint32_t store_length;
 
260
  uint store_length;
261
261
  KEY_PART_INFO *key_part;
262
 
  const unsigned char *key_end= key + key_length;;
 
262
  const uchar *key_end= key + key_length;;
263
263
 
264
264
  for (key_part=table->key_info[idx].key_part;
265
265
       key < key_end ; 
266
266
       key_part++, key+= store_length)
267
267
  {
268
 
    uint32_t length;
 
268
    uint length;
269
269
    store_length= key_part->store_length;
270
270
 
271
271
    if (key_part->null_bit)
285
285
        return 1;
286
286
      continue;
287
287
    }
288
 
    length= cmin((uint) (key_end-key), store_length);
 
288
    length= min((uint) (key_end-key), store_length);
289
289
    if (!(key_part->key_type & (FIELDFLAG_NUMBER+FIELDFLAG_BINARY+
290
290
                                FIELDFLAG_PACK)))
291
291
    {
292
292
      const CHARSET_INFO * const cs= key_part->field->charset();
293
 
      uint32_t char_length= key_part->length / cs->mbmaxlen;
294
 
      const unsigned char *pos= table->record[0] + key_part->offset;
 
293
      uint char_length= key_part->length / cs->mbmaxlen;
 
294
      const uchar *pos= table->record[0] + key_part->offset;
295
295
      if (length > char_length)
296
296
      {
297
297
        char_length= my_charpos(cs, pos, pos + length, char_length);
298
298
        set_if_smaller(char_length, length);
299
299
      }
300
300
      if (cs->coll->strnncollsp(cs,
301
 
                                (const unsigned char*) key, length,
302
 
                                (const unsigned char*) pos, char_length, 0))
 
301
                                (const uchar*) key, length,
 
302
                                (const uchar*) pos, char_length, 0))
303
303
        return 1;
304
304
      continue;
305
305
    }
323
323
     idx        Key number
324
324
*/
325
325
 
326
 
void key_unpack(String *to,Table *table,uint32_t idx)
 
326
void key_unpack(String *to,Table *table,uint idx)
327
327
{
328
328
  KEY_PART_INFO *key_part,*key_part_end;
329
329
  Field *field;
360
360
          which can break a multi-byte characters in the middle.
361
361
          Align, returning not more than "char_length" characters.
362
362
        */
363
 
        uint32_t charpos, char_length= key_part->length / cs->mbmaxlen;
 
363
        uint charpos, char_length= key_part->length / cs->mbmaxlen;
364
364
        if ((charpos= my_charpos(cs, tmp.ptr(),
365
365
                                 tmp.ptr() + tmp.length(),
366
366
                                 char_length)) < key_part->length)
368
368
      }
369
369
      
370
370
      if (key_part->length < field->pack_length())
371
 
        tmp.length(cmin(tmp.length(),(uint32_t)key_part->length));
 
371
        tmp.length(min(tmp.length(),(uint32_t)key_part->length));
372
372
      to->append(tmp);
373
373
    }
374
374
    else
397
397
    FALSE  Otherwise
398
398
*/
399
399
 
400
 
bool is_key_used(Table *table, uint32_t idx, const MY_BITMAP *fields)
 
400
bool is_key_used(Table *table, uint idx, const MY_BITMAP *fields)
401
401
{
402
402
  bitmap_clear_all(&table->tmp_set);
403
403
  table->mark_columns_used_by_index_no_reset(idx, &table->tmp_set);
429
429
    -   1               Key is larger than range
430
430
*/
431
431
 
432
 
int key_cmp(KEY_PART_INFO *key_part, const unsigned char *key, uint32_t key_length)
 
432
int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length)
433
433
{
434
 
  uint32_t store_length;
 
434
  uint store_length;
435
435
 
436
 
  for (const unsigned char *end=key + key_length;
 
436
  for (const uchar *end=key + key_length;
437
437
       key < end;
438
438
       key+= store_length, key_part++)
439
439
  {
490
490
    and return the result of the comparison.
491
491
*/
492
492
 
493
 
int key_rec_cmp(void *key, unsigned char *first_rec, unsigned char *second_rec)
 
493
int key_rec_cmp(void *key, uchar *first_rec, uchar *second_rec)
494
494
{
495
495
  KEY *key_info= (KEY*)key;
496
 
  uint32_t key_parts= key_info->key_parts, i= 0;
 
496
  uint key_parts= key_info->key_parts, i= 0;
497
497
  KEY_PART_INFO *key_part= key_info->key_part;
498
 
  unsigned char *rec0= key_part->field->ptr - key_part->offset;
 
498
  uchar *rec0= key_part->field->ptr - key_part->offset;
499
499
  my_ptrdiff_t first_diff= first_rec - rec0, sec_diff= second_rec - rec0;
500
500
  int result= 0;
501
501