~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/hp_hash.cc

pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
macros.
Add PANDORA_DRIZZLE_BUILD to run the extra checks that drizzle needs that 
plugins would also need to run so we can just use that macro in generated
external plugin builds.
Added support to register_plugins for external plugin building.
Renamed register_plugins.py to pandora-plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* The hash functions used for saveing keys */
17
17
 
18
 
#include "heapdef.h"
 
18
#include "heap_priv.h"
 
19
 
19
20
#include <mystrings/m_ctype.h>
20
 
 
21
 
 
 
21
#include <drizzled/util/test.h>
 
22
 
 
23
#include <string.h>
 
24
static uint32_t hp_hashnr(register HP_KEYDEF *keydef, register const unsigned char *key);
 
25
static int hp_key_cmp(HP_KEYDEF *keydef, const unsigned char *rec, const unsigned char *key);
22
26
 
23
27
/*
24
28
  Find out how many rows there is in the given range
59
63
  custom_arg.search_flag= SEARCH_FIND | SEARCH_SAME;
60
64
  if (min_key)
61
65
  {
62
 
    custom_arg.key_length= hp_rb_pack_key(keyinfo, (uchar*) info->recbuf,
63
 
                                          (uchar*) min_key->key,
 
66
    custom_arg.key_length= hp_rb_pack_key(keyinfo, (unsigned char*) info->recbuf,
 
67
                                          (unsigned char*) min_key->key,
64
68
                                          min_key->keypart_map);
65
69
    start_pos= tree_record_pos(rb_tree, info->recbuf, min_key->flag,
66
70
                               &custom_arg);
72
76
 
73
77
  if (max_key)
74
78
  {
75
 
    custom_arg.key_length= hp_rb_pack_key(keyinfo, (uchar*) info->recbuf,
76
 
                                          (uchar*) max_key->key,
 
79
    custom_arg.key_length= hp_rb_pack_key(keyinfo, (unsigned char*) info->recbuf,
 
80
                                          (unsigned char*) max_key->key,
77
81
                                          max_key->keypart_map);
78
82
    end_pos= tree_record_pos(rb_tree, info->recbuf, max_key->flag,
79
83
                             &custom_arg);
94
98
        /* Sets info->current_ptr to found record */
95
99
        /* next_flag:  Search=0, next=1, prev =2, same =3 */
96
100
 
97
 
uchar *hp_search(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key,
98
 
                uint nextflag)
 
101
unsigned char *hp_search(HP_INFO *info, HP_KEYDEF *keyinfo, const unsigned char *key,
 
102
                uint32_t nextflag)
99
103
{
100
104
  register HASH_INFO *pos,*prev_ptr;
101
105
  int flag;
102
 
  uint old_nextflag;
 
106
  uint32_t old_nextflag;
103
107
  HP_SHARE *share=info->s;
104
108
  old_nextflag=nextflag;
105
109
  flag=1;
159
163
 
160
164
  if (old_nextflag && nextflag)
161
165
    my_errno=HA_ERR_RECORD_CHANGED;             /* Didn't find old record */
162
 
  info->current_hash_ptr=0;  
 
166
  info->current_hash_ptr=0;
163
167
  return((info->current_ptr= 0));
164
168
}
165
169
 
169
173
  since last read !
170
174
*/
171
175
 
172
 
uchar *hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key,
 
176
unsigned char *hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo, const unsigned char *key,
173
177
                      HASH_INFO *pos)
174
178
{
175
179
  while ((pos= pos->next_key))
193
197
      hashnr     Hash value
194
198
      buffmax    Value such that
195
199
                 2^(n-1) < maxlength <= 2^n = buffmax
196
 
      maxlength  
197
 
  
 
200
      maxlength
 
201
 
198
202
  RETURN
199
203
    Array index, in [0..maxlength)
200
204
*/
225
229
  return;
226
230
}
227
231
 
228
 
#ifndef NEW_HASH_FUNCTION
229
 
 
230
232
        /* Calc hashvalue for a key */
231
233
 
232
 
uint32_t hp_hashnr(register HP_KEYDEF *keydef, register const uchar *key)
 
234
static uint32_t hp_hashnr(register HP_KEYDEF *keydef, register const unsigned char *key)
233
235
{
234
 
  /*register*/ 
 
236
  /*register*/
235
237
  uint32_t nr=1, nr2=4;
236
238
  HA_KEYSEG *seg,*endseg;
237
239
 
238
240
  for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
239
241
  {
240
 
    uchar *pos=(uchar*) key;
 
242
    unsigned char *pos=(unsigned char*) key;
241
243
    key+=seg->length;
242
244
    if (seg->null_bit)
243
245
    {
255
257
    if (seg->type == HA_KEYTYPE_TEXT)
256
258
    {
257
259
       const CHARSET_INFO * const cs= seg->charset;
258
 
       uint length= seg->length;
 
260
       uint32_t length= seg->length;
259
261
       if (cs->mbmaxlen > 1)
260
262
       {
261
 
         uint char_length;
 
263
         uint32_t char_length;
262
264
         char_length= my_charpos(cs, pos, pos + length, length/cs->mbmaxlen);
263
265
         set_if_smaller(length, char_length);
264
266
       }
267
269
    else if (seg->type == HA_KEYTYPE_VARTEXT1)  /* Any VARCHAR segments */
268
270
    {
269
271
       const CHARSET_INFO * const cs= seg->charset;
270
 
       uint pack_length= 2;                     /* Key packing is constant */
271
 
       uint length= uint2korr(pos);
 
272
       uint32_t pack_length= 2;                     /* Key packing is constant */
 
273
       uint32_t length= uint2korr(pos);
272
274
       if (cs->mbmaxlen > 1)
273
275
       {
274
 
         uint char_length;
 
276
         uint32_t char_length;
275
277
         char_length= my_charpos(cs, pos +pack_length,
276
278
                                 pos +pack_length + length,
277
279
                                 seg->length/cs->mbmaxlen);
282
284
    }
283
285
    else
284
286
    {
285
 
      for (; pos < (uchar*) key ; pos++)
 
287
      for (; pos < (unsigned char*) key ; pos++)
286
288
      {
287
289
        nr^=(uint32_t) ((((uint) nr & 63)+nr2)*((uint) *pos)) + (nr << 8);
288
290
        nr2+=3;
294
296
 
295
297
        /* Calc hashvalue for a key in a record */
296
298
 
297
 
uint32_t hp_rec_hashnr(register HP_KEYDEF *keydef, register const uchar *rec)
 
299
uint32_t hp_rec_hashnr(register HP_KEYDEF *keydef, register const unsigned char *rec)
298
300
{
299
301
  uint32_t nr=1, nr2=4;
300
302
  HA_KEYSEG *seg,*endseg;
301
303
 
302
304
  for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
303
305
  {
304
 
    uchar *pos=(uchar*) rec+seg->start,*end=pos+seg->length;
 
306
    unsigned char *pos=(unsigned char*) rec+seg->start,*end=pos+seg->length;
305
307
    if (seg->null_bit)
306
308
    {
307
309
      if (rec[seg->null_pos] & seg->null_bit)
313
315
    if (seg->type == HA_KEYTYPE_TEXT)
314
316
    {
315
317
      const CHARSET_INFO * const cs= seg->charset;
316
 
      uint char_length= seg->length;
 
318
      uint32_t char_length= seg->length;
317
319
      if (cs->mbmaxlen > 1)
318
320
      {
319
321
        char_length= my_charpos(cs, pos, pos + char_length,
320
322
                                char_length / cs->mbmaxlen);
321
 
        set_if_smaller(char_length, seg->length); /* QQ: ok to remove? */
 
323
        set_if_smaller(char_length, (uint32_t)seg->length); /* QQ: ok to remove? */
322
324
      }
323
325
      cs->coll->hash_sort(cs, pos, char_length, &nr, &nr2);
324
326
    }
325
327
    else if (seg->type == HA_KEYTYPE_VARTEXT1)  /* Any VARCHAR segments */
326
328
    {
327
329
      const CHARSET_INFO * const cs= seg->charset;
328
 
      uint pack_length= seg->bit_start;
329
 
      uint length= (pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos));
 
330
      uint32_t pack_length= seg->bit_start;
 
331
      uint32_t length= (pack_length == 1 ? (uint) *(unsigned char*) pos : uint2korr(pos));
330
332
      if (cs->mbmaxlen > 1)
331
333
      {
332
 
        uint char_length;
 
334
        uint32_t char_length;
333
335
        char_length= my_charpos(cs, pos + pack_length,
334
336
                                pos + pack_length + length,
335
337
                                seg->length/cs->mbmaxlen);
349
351
  return(nr);
350
352
}
351
353
 
352
 
#else
353
 
 
354
 
/*
355
 
 * Fowler/Noll/Vo hash
356
 
 *
357
 
 * The basis of the hash algorithm was taken from an idea sent by email to the
358
 
 * IEEE Posix P1003.2 mailing list from Phong Vo (kpv@research.att.com) and
359
 
 * Glenn Fowler (gsf@research.att.com).  Landon Curt Noll (chongo@toad.com)
360
 
 * later improved on their algorithm.
361
 
 *
362
 
 * The magic is in the interesting relationship between the special prime
363
 
 * 16777619 (2^24 + 403) and 2^32 and 2^8.
364
 
 *
365
 
 * This hash produces the fewest collisions of any function that we've seen so
366
 
 * far, and works well on both numbers and strings.
367
 
 */
368
 
 
369
 
uint32_t hp_hashnr(register HP_KEYDEF *keydef, register const uchar *key)
370
 
{
371
 
  /*
372
 
    Note, if a key consists of a combination of numeric and
373
 
    a text columns, it most likely won't work well.
374
 
    Making text columns work with NEW_HASH_FUNCTION
375
 
    needs also changes in strings/ctype-xxx.c.
376
 
  */
377
 
  uint32_t nr= 1, nr2= 4;
378
 
  HA_KEYSEG *seg,*endseg;
379
 
 
380
 
  for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
381
 
  {
382
 
    uchar *pos=(uchar*) key;
383
 
    key+=seg->length;
384
 
    if (seg->null_bit)
385
 
    {
386
 
      key++;
387
 
      if (*pos)
388
 
      {
389
 
        nr^= (nr << 1) | 1;
390
 
        /* Add key pack length (2) to key for VARCHAR segments */
391
 
        if (seg->type == HA_KEYTYPE_VARTEXT1)
392
 
          key+= 2;
393
 
        continue;
394
 
      }
395
 
      pos++;
396
 
    }
397
 
    if (seg->type == HA_KEYTYPE_TEXT)
398
 
    {
399
 
      seg->charset->coll->hash_sort(seg->charset, pos, ((uchar*)key)-pos,
400
 
                                    &nr, &nr2);
401
 
    }
402
 
    else if (seg->type == HA_KEYTYPE_VARTEXT1)  /* Any VARCHAR segments */
403
 
    {
404
 
      uint pack_length= 2;                      /* Key packing is constant */
405
 
      uint length= uint2korr(pos);
406
 
      seg->charset->coll->hash_sort(seg->charset, pos+pack_length, length,
407
 
                                    &nr, &nr2);
408
 
      key+= pack_length;
409
 
    }
410
 
    else
411
 
    {
412
 
      for ( ; pos < (uchar*) key ; pos++)
413
 
      {
414
 
        nr *=16777619; 
415
 
        nr ^=(uint) *pos;
416
 
      }
417
 
    }
418
 
  }
419
 
  return(nr);
420
 
}
421
 
 
422
 
        /* Calc hashvalue for a key in a record */
423
 
 
424
 
uint32_t hp_rec_hashnr(register HP_KEYDEF *keydef, register const uchar *rec)
425
 
{
426
 
  uint32_t nr= 1, nr2= 4;
427
 
  HA_KEYSEG *seg,*endseg;
428
 
 
429
 
  for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
430
 
  {
431
 
    uchar *pos=(uchar*) rec+seg->start;
432
 
    if (seg->null_bit)
433
 
    {
434
 
      if (rec[seg->null_pos] & seg->null_bit)
435
 
      {
436
 
        nr^= (nr << 1) | 1;
437
 
        continue;
438
 
      }
439
 
    }
440
 
    if (seg->type == HA_KEYTYPE_TEXT)
441
 
    {
442
 
      uint char_length= seg->length; /* TODO: fix to use my_charpos() */
443
 
      seg->charset->coll->hash_sort(seg->charset, pos, char_length,
444
 
                                    &nr, &nr2);
445
 
    }
446
 
    else if (seg->type == HA_KEYTYPE_VARTEXT1)  /* Any VARCHAR segments */
447
 
    {
448
 
      uint pack_length= seg->bit_start;
449
 
      uint length= (pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos));
450
 
      seg->charset->coll->hash_sort(seg->charset, pos+pack_length,
451
 
                                    length, &nr, &nr2);
452
 
    }
453
 
    else
454
 
    {
455
 
      uchar *end= pos+seg->length;
456
 
      for ( ; pos < end ; pos++)
457
 
      {
458
 
        nr *=16777619; 
459
 
        nr ^=(uint) *pos;
460
 
      }
461
 
    }
462
 
  }
463
 
  return(nr);
464
 
}
465
 
 
466
 
#endif
467
 
 
468
 
 
469
354
/*
470
355
  Compare keys for two records. Returns 0 if they are identical
471
356
 
475
360
    rec1                Record to compare
476
361
    rec2                Other record to compare
477
362
    diff_if_only_endspace_difference
478
 
                        Different number of end space is significant    
 
363
                        Different number of end space is significant
479
364
 
480
365
  NOTES
481
366
    diff_if_only_endspace_difference is used to allow us to insert
486
371
    <> 0        Key differes
487
372
*/
488
373
 
489
 
int hp_rec_key_cmp(HP_KEYDEF *keydef, const uchar *rec1, const uchar *rec2,
 
374
int hp_rec_key_cmp(HP_KEYDEF *keydef, const unsigned char *rec1, const unsigned char *rec2,
490
375
                   bool diff_if_only_endspace_difference)
491
376
{
492
377
  HA_KEYSEG *seg,*endseg;
504
389
    if (seg->type == HA_KEYTYPE_TEXT)
505
390
    {
506
391
      const CHARSET_INFO * const cs= seg->charset;
507
 
      uint char_length1;
508
 
      uint char_length2;
509
 
      uchar *pos1= (uchar*)rec1 + seg->start;
510
 
      uchar *pos2= (uchar*)rec2 + seg->start;
 
392
      uint32_t char_length1;
 
393
      uint32_t char_length2;
 
394
      unsigned char *pos1= (unsigned char*)rec1 + seg->start;
 
395
      unsigned char *pos2= (unsigned char*)rec2 + seg->start;
511
396
      if (cs->mbmaxlen > 1)
512
397
      {
513
 
        uint char_length= seg->length / cs->mbmaxlen;
 
398
        uint32_t char_length= seg->length / cs->mbmaxlen;
514
399
        char_length1= my_charpos(cs, pos1, pos1 + seg->length, char_length);
515
 
        set_if_smaller(char_length1, seg->length);
 
400
        set_if_smaller(char_length1, (uint32_t)seg->length);
516
401
        char_length2= my_charpos(cs, pos2, pos2 + seg->length, char_length);
517
 
        set_if_smaller(char_length2, seg->length);
 
402
        set_if_smaller(char_length2, (uint32_t)seg->length);
518
403
      }
519
404
      else
520
405
      {
527
412
    }
528
413
    else if (seg->type == HA_KEYTYPE_VARTEXT1)  /* Any VARCHAR segments */
529
414
    {
530
 
      uchar *pos1= (uchar*) rec1 + seg->start;
531
 
      uchar *pos2= (uchar*) rec2 + seg->start;
532
 
      uint char_length1, char_length2;
533
 
      uint pack_length= seg->bit_start;
 
415
      unsigned char *pos1= (unsigned char*) rec1 + seg->start;
 
416
      unsigned char *pos2= (unsigned char*) rec2 + seg->start;
 
417
      uint32_t char_length1, char_length2;
 
418
      uint32_t pack_length= seg->bit_start;
534
419
      const CHARSET_INFO * const cs= seg->charset;
535
420
      if (pack_length == 1)
536
421
      {
537
 
        char_length1= (uint) *(uchar*) pos1++;
538
 
        char_length2= (uint) *(uchar*) pos2++;
 
422
        char_length1= (uint) *(unsigned char*) pos1++;
 
423
        char_length2= (uint) *(unsigned char*) pos2++;
539
424
      }
540
425
      else
541
426
      {
546
431
      }
547
432
      if (cs->mbmaxlen > 1)
548
433
      {
549
 
        uint safe_length1= char_length1;
550
 
        uint safe_length2= char_length2;
551
 
        uint char_length= seg->length / cs->mbmaxlen;
 
434
        uint32_t safe_length1= char_length1;
 
435
        uint32_t safe_length2= char_length2;
 
436
        uint32_t char_length= seg->length / cs->mbmaxlen;
552
437
        char_length1= my_charpos(cs, pos1, pos1 + char_length1, char_length);
553
438
        set_if_smaller(char_length1, safe_length1);
554
439
        char_length2= my_charpos(cs, pos2, pos2 + char_length2, char_length);
573
458
 
574
459
        /* Compare a key in a record to a whole key */
575
460
 
576
 
int hp_key_cmp(HP_KEYDEF *keydef, const uchar *rec, const uchar *key)
 
461
static int hp_key_cmp(HP_KEYDEF *keydef, const unsigned char *rec, const unsigned char *key)
577
462
{
578
463
  HA_KEYSEG *seg,*endseg;
579
464
 
597
482
    if (seg->type == HA_KEYTYPE_TEXT)
598
483
    {
599
484
      const CHARSET_INFO * const cs= seg->charset;
600
 
      uint char_length_key;
601
 
      uint char_length_rec;
602
 
      uchar *pos= (uchar*) rec + seg->start;
 
485
      uint32_t char_length_key;
 
486
      uint32_t char_length_rec;
 
487
      unsigned char *pos= (unsigned char*) rec + seg->start;
603
488
      if (cs->mbmaxlen > 1)
604
489
      {
605
 
        uint char_length= seg->length / cs->mbmaxlen;
 
490
        uint32_t char_length= seg->length / cs->mbmaxlen;
606
491
        char_length_key= my_charpos(cs, key, key + seg->length, char_length);
607
 
        set_if_smaller(char_length_key, seg->length);
 
492
        set_if_smaller(char_length_key, (uint32_t)seg->length);
608
493
        char_length_rec= my_charpos(cs, pos, pos + seg->length, char_length);
609
 
        set_if_smaller(char_length_rec, seg->length);
 
494
        set_if_smaller(char_length_rec, (uint32_t)seg->length);
610
495
      }
611
496
      else
612
497
      {
613
498
        char_length_key= seg->length;
614
499
        char_length_rec= seg->length;
615
500
      }
616
 
      
 
501
 
617
502
      if (seg->charset->coll->strnncollsp(seg->charset,
618
 
                                          (uchar*) pos, char_length_rec,
619
 
                                          (uchar*) key, char_length_key, 0))
 
503
                                          (unsigned char*) pos, char_length_rec,
 
504
                                          (unsigned char*) key, char_length_key, 0))
620
505
        return 1;
621
506
    }
622
507
    else if (seg->type == HA_KEYTYPE_VARTEXT1)  /* Any VARCHAR segments */
623
508
    {
624
 
      uchar *pos= (uchar*) rec + seg->start;
 
509
      unsigned char *pos= (unsigned char*) rec + seg->start;
625
510
      const CHARSET_INFO * const cs= seg->charset;
626
 
      uint pack_length= seg->bit_start;
627
 
      uint char_length_rec= (pack_length == 1 ? (uint) *(uchar*) pos :
 
511
      uint32_t pack_length= seg->bit_start;
 
512
      uint32_t char_length_rec= (pack_length == 1 ? (uint) *(unsigned char*) pos :
628
513
                             uint2korr(pos));
629
514
      /* Key segments are always packed with 2 bytes */
630
 
      uint char_length_key= uint2korr(key);
 
515
      uint32_t char_length_key= uint2korr(key);
631
516
      pos+= pack_length;
632
517
      key+= 2;                                  /* skip key pack length */
633
518
      if (cs->mbmaxlen > 1)
634
519
      {
635
 
        uint char_length1, char_length2;
636
 
        char_length1= char_length2= seg->length / cs->mbmaxlen; 
 
520
        uint32_t char_length1, char_length2;
 
521
        char_length1= char_length2= seg->length / cs->mbmaxlen;
637
522
        char_length1= my_charpos(cs, key, key + char_length_key, char_length1);
638
523
        set_if_smaller(char_length_key, char_length1);
639
524
        char_length2= my_charpos(cs, pos, pos + char_length_rec, char_length2);
641
526
      }
642
527
 
643
528
      if (cs->coll->strnncollsp(seg->charset,
644
 
                                (uchar*) pos, char_length_rec,
645
 
                                (uchar*) key, char_length_key, 0))
 
529
                                (unsigned char*) pos, char_length_rec,
 
530
                                (unsigned char*) key, char_length_key, 0))
646
531
        return 1;
647
532
    }
648
533
    else
657
542
 
658
543
        /* Copy a key from a record to a keybuffer */
659
544
 
660
 
void hp_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec)
 
545
void hp_make_key(HP_KEYDEF *keydef, unsigned char *key, const unsigned char *rec)
661
546
{
662
547
  HA_KEYSEG *seg,*endseg;
663
548
 
664
549
  for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
665
550
  {
666
551
    const CHARSET_INFO * const cs= seg->charset;
667
 
    uint char_length= seg->length;
668
 
    uchar *pos= (uchar*) rec + seg->start;
 
552
    uint32_t char_length= seg->length;
 
553
    unsigned char *pos= (unsigned char*) rec + seg->start;
669
554
    if (seg->null_bit)
670
555
      *key++= test(rec[seg->null_pos] & seg->null_bit);
671
556
    if (cs->mbmaxlen > 1)
672
557
    {
673
558
      char_length= my_charpos(cs, pos, pos + seg->length,
674
559
                              char_length / cs->mbmaxlen);
675
 
      set_if_smaller(char_length, seg->length); /* QQ: ok to remove? */
 
560
      set_if_smaller(char_length, (uint32_t)seg->length); /* QQ: ok to remove? */
676
561
    }
677
562
    if (seg->type == HA_KEYTYPE_VARTEXT1)
678
563
      char_length+= seg->bit_start;             /* Copy also length */
689
574
  } while(0)
690
575
 
691
576
 
692
 
uint hp_rb_make_key(HP_KEYDEF *keydef, uchar *key, 
693
 
                    const uchar *rec, uchar *recpos)
 
577
uint32_t hp_rb_make_key(HP_KEYDEF *keydef, unsigned char *key,
 
578
                    const unsigned char *rec, unsigned char *recpos)
694
579
{
695
 
  uchar *start_key= key;
 
580
  unsigned char *start_key= key;
696
581
  HA_KEYSEG *seg, *endseg;
697
582
 
698
583
  for (seg= keydef->seg, endseg= seg + keydef->keysegs; seg < endseg; seg++)
699
584
  {
700
 
    uint char_length;
 
585
    uint32_t char_length;
701
586
    if (seg->null_bit)
702
587
    {
703
588
      if (!(*key++= 1 - test(rec[seg->null_pos] & seg->null_bit)))
705
590
    }
706
591
    if (seg->flag & HA_SWAP_KEY)
707
592
    {
708
 
      uint length= seg->length;
709
 
      uchar *pos= (uchar*) rec + seg->start;
710
 
      
 
593
      uint32_t length= seg->length;
 
594
      unsigned char *pos= (unsigned char*) rec + seg->start;
 
595
 
711
596
#ifdef HAVE_ISNAN
712
 
      if (seg->type == HA_KEYTYPE_FLOAT)
713
 
      {
714
 
        float nr;
715
 
        float4get(nr, pos);
716
 
        if (isnan(nr))
717
 
        {
718
 
          /* Replace NAN with zero */
719
 
          memset(key, 0, length);
720
 
          key+= length;
721
 
          continue;
722
 
        }
723
 
      }
724
 
      else if (seg->type == HA_KEYTYPE_DOUBLE)
 
597
      if (seg->type == HA_KEYTYPE_DOUBLE)
725
598
      {
726
599
        double nr;
727
600
        float8get(nr, pos);
743
616
 
744
617
    if (seg->flag & HA_VAR_LENGTH_PART)
745
618
    {
746
 
      uchar *pos=      (uchar*) rec + seg->start;
747
 
      uint length=     seg->length;
748
 
      uint pack_length= seg->bit_start;
749
 
      uint tmp_length= (pack_length == 1 ? (uint) *(uchar*) pos :
 
619
      unsigned char *pos=      (unsigned char*) rec + seg->start;
 
620
      uint32_t length=     seg->length;
 
621
      uint32_t pack_length= seg->bit_start;
 
622
      uint32_t tmp_length= (pack_length == 1 ? (uint) *(unsigned char*) pos :
750
623
                        uint2korr(pos));
751
624
      const CHARSET_INFO * const cs= seg->charset;
752
625
      char_length= length/cs->mbmaxlen;
763
636
    char_length= seg->length;
764
637
    if (seg->charset->mbmaxlen > 1)
765
638
    {
766
 
      char_length= my_charpos(seg->charset, 
 
639
      char_length= my_charpos(seg->charset,
767
640
                              rec + seg->start, rec + seg->start + char_length,
768
641
                              char_length / seg->charset->mbmaxlen);
769
 
      set_if_smaller(char_length, seg->length); /* QQ: ok to remove? */
 
642
      set_if_smaller(char_length, (uint32_t)seg->length); /* QQ: ok to remove? */
770
643
      if (char_length < seg->length)
771
644
        seg->charset->cset->fill(seg->charset, (char*) key + char_length,
772
645
                                 seg->length - char_length, ' ');
774
647
    memcpy(key, rec + seg->start, (size_t) char_length);
775
648
    key+= seg->length;
776
649
  }
777
 
  memcpy(key, &recpos, sizeof(uchar*));
778
 
  return (uint) (key - start_key);
 
650
  memcpy(key, &recpos, sizeof(unsigned char*));
 
651
  return (uint32_t) (key - start_key);
779
652
}
780
653
 
781
654
 
782
 
uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old,
 
655
uint32_t hp_rb_pack_key(HP_KEYDEF *keydef, unsigned char *key, const unsigned char *old,
783
656
                    key_part_map keypart_map)
784
657
{
785
658
  HA_KEYSEG *seg, *endseg;
786
 
  uchar *start_key= key;
 
659
  unsigned char *start_key= key;
787
660
 
788
661
  for (seg= keydef->seg, endseg= seg + keydef->keysegs;
789
662
       seg < endseg && keypart_map; old+= seg->length, seg++)
790
663
  {
791
 
    uint char_length;
 
664
    uint32_t char_length;
792
665
    keypart_map>>= 1;
793
666
    if (seg->null_bit)
794
667
    {
797
670
      }
798
671
    if (seg->flag & HA_SWAP_KEY)
799
672
    {
800
 
      uint length= seg->length;
801
 
      uchar *pos= (uchar*) old + length;
802
 
      
 
673
      uint32_t length= seg->length;
 
674
      unsigned char *pos= (unsigned char*) old + length;
 
675
 
803
676
      while (length--)
804
677
      {
805
678
        *key++= *--pos;
809
682
    if (seg->flag & (HA_VAR_LENGTH_PART | HA_BLOB_PART))
810
683
    {
811
684
      /* Length of key-part used with heap_rkey() always 2 */
812
 
      uint tmp_length=uint2korr(old);
813
 
      uint length= seg->length;
 
685
      uint32_t tmp_length=uint2korr(old);
 
686
      uint32_t length= seg->length;
814
687
      const CHARSET_INFO * const cs= seg->charset;
815
688
      char_length= length/cs->mbmaxlen;
816
689
 
827
700
    {
828
701
      char_length= my_charpos(seg->charset, old, old+char_length,
829
702
                              char_length / seg->charset->mbmaxlen);
830
 
      set_if_smaller(char_length, seg->length); /* QQ: ok to remove? */
 
703
      set_if_smaller(char_length, (uint32_t)seg->length); /* QQ: ok to remove? */
831
704
      if (char_length < seg->length)
832
 
        seg->charset->cset->fill(seg->charset, (char*) key + char_length, 
 
705
        seg->charset->cset->fill(seg->charset, (char*) key + char_length,
833
706
                                 seg->length - char_length, ' ');
834
707
    }
835
708
    memcpy(key, old, (size_t) char_length);
839
712
}
840
713
 
841
714
 
842
 
uint hp_rb_key_length(HP_KEYDEF *keydef, 
843
 
                      const uchar *key __attribute__((unused)))
 
715
uint32_t hp_rb_key_length(HP_KEYDEF *keydef, const unsigned char *not_used)
844
716
{
 
717
  (void)not_used;
845
718
  return keydef->length;
846
719
}
847
720
 
848
721
 
849
 
uint hp_rb_null_key_length(HP_KEYDEF *keydef, const uchar *key)
 
722
uint32_t hp_rb_null_key_length(HP_KEYDEF *keydef, const unsigned char *key)
850
723
{
851
 
  const uchar *start_key= key;
 
724
  const unsigned char *start_key= key;
852
725
  HA_KEYSEG *seg, *endseg;
853
 
  
 
726
 
854
727
  for (seg= keydef->seg, endseg= seg + keydef->keysegs; seg < endseg; seg++)
855
728
  {
856
729
    if (seg->null_bit && !*key++)
859
732
  }
860
733
  return (uint) (key - start_key);
861
734
}
862
 
                  
863
 
 
864
 
uint hp_rb_var_key_length(HP_KEYDEF *keydef, const uchar *key)
 
735
 
 
736
 
 
737
uint32_t hp_rb_var_key_length(HP_KEYDEF *keydef, const unsigned char *key)
865
738
{
866
 
  const uchar *start_key= key;
 
739
  const unsigned char *start_key= key;
867
740
  HA_KEYSEG *seg, *endseg;
868
 
  
 
741
 
869
742
  for (seg= keydef->seg, endseg= seg + keydef->keysegs; seg < endseg; seg++)
870
743
  {
871
 
    uint length= seg->length;
 
744
    uint32_t length= seg->length;
872
745
    if (seg->null_bit && !*key++)
873
746
      continue;
874
747
    if (seg->flag & (HA_VAR_LENGTH_PART | HA_BLOB_PART))
888
761
    0 otherwise
889
762
*/
890
763
 
891
 
bool hp_if_null_in_key(HP_KEYDEF *keydef, const uchar *record)
 
764
bool hp_if_null_in_key(HP_KEYDEF *keydef, const unsigned char *record)
892
765
{
893
766
  HA_KEYSEG *seg,*endseg;
894
767
  for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
914
787
    less than zero.
915
788
*/
916
789
 
917
 
void heap_update_auto_increment(HP_INFO *info, const uchar *record)
 
790
void heap_update_auto_increment(HP_INFO *info, const unsigned char *record)
918
791
{
919
792
  uint64_t value= 0;                    /* Store unsigned values here */
920
793
  int64_t s_value= 0;                   /* Store signed values here */
921
794
 
922
795
  HA_KEYSEG *keyseg= info->s->keydef[info->s->auto_key - 1].seg;
923
 
  const uchar *key=  (uchar*) record + keyseg->start;
 
796
  const unsigned char *key=  (unsigned char*) record + keyseg->start;
924
797
 
925
798
  switch (info->s->auto_key_type) {
926
 
  case HA_KEYTYPE_INT8:
927
 
    s_value= (int64_t) *(char*)key;
928
 
    break;
929
799
  case HA_KEYTYPE_BINARY:
930
 
    value=(uint64_t)  *(uchar*) key;
931
 
    break;
932
 
  case HA_KEYTYPE_SHORT_INT:
933
 
    s_value= (int64_t) sint2korr(key);
934
 
    break;
935
 
  case HA_KEYTYPE_USHORT_INT:
936
 
    value=(uint64_t) uint2korr(key);
 
800
    value=(uint64_t)  *(unsigned char*) key;
937
801
    break;
938
802
  case HA_KEYTYPE_LONG_INT:
939
803
    s_value= (int64_t) sint4korr(key);
941
805
  case HA_KEYTYPE_ULONG_INT:
942
806
    value=(uint64_t) uint4korr(key);
943
807
    break;
944
 
  case HA_KEYTYPE_INT24:
945
 
    s_value= (int64_t) sint3korr(key);
946
 
    break;
947
808
  case HA_KEYTYPE_UINT24:
948
809
    value=(uint64_t) uint3korr(key);
949
810
    break;
950
 
  case HA_KEYTYPE_FLOAT:                        /* This shouldn't be used */
951
 
  {
952
 
    float f_1;
953
 
    float4get(f_1,key);
954
 
    /* Ignore negative values */
955
 
    value = (f_1 < (float) 0.0) ? 0 : (uint64_t) f_1;
956
 
    break;
957
 
  }
958
811
  case HA_KEYTYPE_DOUBLE:                       /* This shouldn't be used */
959
812
  {
960
813
    double f_1;