~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_hash.c

  • Committer: Patrick Galbraith
  • Date: 2008-07-24 16:57:40 UTC
  • mto: (202.2.4 rename-mysql-to-drizzle)
  • mto: This revision was merged to the branch mainline in revision 212.
  • Revision ID: patg@ishvara-20080724165740-x58yw6zs6d9o17lf
Most everything working with client rename
mysqlslap test still fails... can't connect to the server

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
/* The hash functions used for saveing keys */
17
17
 
18
18
#include "heapdef.h"
19
 
#include <mystrings/m_ctype.h>
20
 
#include <drizzled/util/test.h>
 
19
#include <m_ctype.h>
 
20
 
21
21
 
22
22
 
23
23
/*
59
59
  custom_arg.search_flag= SEARCH_FIND | SEARCH_SAME;
60
60
  if (min_key)
61
61
  {
62
 
    custom_arg.key_length= hp_rb_pack_key(keyinfo, (unsigned char*) info->recbuf,
63
 
                                          (unsigned char*) min_key->key,
 
62
    custom_arg.key_length= hp_rb_pack_key(keyinfo, (uchar*) info->recbuf,
 
63
                                          (uchar*) min_key->key,
64
64
                                          min_key->keypart_map);
65
65
    start_pos= tree_record_pos(rb_tree, info->recbuf, min_key->flag,
66
66
                               &custom_arg);
72
72
 
73
73
  if (max_key)
74
74
  {
75
 
    custom_arg.key_length= hp_rb_pack_key(keyinfo, (unsigned char*) info->recbuf,
76
 
                                          (unsigned char*) max_key->key,
 
75
    custom_arg.key_length= hp_rb_pack_key(keyinfo, (uchar*) info->recbuf,
 
76
                                          (uchar*) max_key->key,
77
77
                                          max_key->keypart_map);
78
78
    end_pos= tree_record_pos(rb_tree, info->recbuf, max_key->flag,
79
79
                             &custom_arg);
94
94
        /* Sets info->current_ptr to found record */
95
95
        /* next_flag:  Search=0, next=1, prev =2, same =3 */
96
96
 
97
 
unsigned char *hp_search(HP_INFO *info, HP_KEYDEF *keyinfo, const unsigned char *key,
98
 
                uint32_t nextflag)
 
97
uchar *hp_search(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key,
 
98
                uint nextflag)
99
99
{
100
100
  register HASH_INFO *pos,*prev_ptr;
101
101
  int flag;
102
 
  uint32_t old_nextflag;
 
102
  uint old_nextflag;
103
103
  HP_SHARE *share=info->s;
104
104
  old_nextflag=nextflag;
105
105
  flag=1;
169
169
  since last read !
170
170
*/
171
171
 
172
 
unsigned char *hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo, const unsigned char *key,
 
172
uchar *hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key,
173
173
                      HASH_INFO *pos)
174
174
{
175
175
  while ((pos= pos->next_key))
199
199
    Array index, in [0..maxlength)
200
200
*/
201
201
 
202
 
uint32_t hp_mask(uint32_t hashnr, uint32_t buffmax, uint32_t maxlength)
 
202
ulong hp_mask(ulong hashnr, ulong buffmax, ulong maxlength)
203
203
{
204
204
  if ((hashnr & (buffmax-1)) < maxlength) return (hashnr & (buffmax-1));
205
205
  return (hashnr & ((buffmax >> 1) -1));
229
229
 
230
230
        /* Calc hashvalue for a key */
231
231
 
232
 
uint32_t hp_hashnr(register HP_KEYDEF *keydef, register const unsigned char *key)
 
232
ulong hp_hashnr(register HP_KEYDEF *keydef, register const uchar *key)
233
233
{
234
234
  /*register*/ 
235
 
  uint32_t nr=1, nr2=4;
 
235
  ulong nr=1, nr2=4;
236
236
  HA_KEYSEG *seg,*endseg;
237
237
 
238
238
  for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
239
239
  {
240
 
    unsigned char *pos=(unsigned char*) key;
 
240
    uchar *pos=(uchar*) key;
241
241
    key+=seg->length;
242
242
    if (seg->null_bit)
243
243
    {
254
254
    }
255
255
    if (seg->type == HA_KEYTYPE_TEXT)
256
256
    {
257
 
       const CHARSET_INFO * const cs= seg->charset;
258
 
       uint32_t length= seg->length;
 
257
       CHARSET_INFO *cs= seg->charset;
 
258
       uint length= seg->length;
259
259
       if (cs->mbmaxlen > 1)
260
260
       {
261
 
         uint32_t char_length;
 
261
         uint char_length;
262
262
         char_length= my_charpos(cs, pos, pos + length, length/cs->mbmaxlen);
263
263
         set_if_smaller(length, char_length);
264
264
       }
266
266
    }
267
267
    else if (seg->type == HA_KEYTYPE_VARTEXT1)  /* Any VARCHAR segments */
268
268
    {
269
 
       const CHARSET_INFO * const cs= seg->charset;
270
 
       uint32_t pack_length= 2;                     /* Key packing is constant */
271
 
       uint32_t length= uint2korr(pos);
 
269
       CHARSET_INFO *cs= seg->charset;
 
270
       uint pack_length= 2;                     /* Key packing is constant */
 
271
       uint length= uint2korr(pos);
272
272
       if (cs->mbmaxlen > 1)
273
273
       {
274
 
         uint32_t char_length;
 
274
         uint char_length;
275
275
         char_length= my_charpos(cs, pos +pack_length,
276
276
                                 pos +pack_length + length,
277
277
                                 seg->length/cs->mbmaxlen);
282
282
    }
283
283
    else
284
284
    {
285
 
      for (; pos < (unsigned char*) key ; pos++)
 
285
      for (; pos < (uchar*) key ; pos++)
286
286
      {
287
 
        nr^=(uint32_t) ((((uint) nr & 63)+nr2)*((uint) *pos)) + (nr << 8);
 
287
        nr^=(ulong) ((((uint) nr & 63)+nr2)*((uint) *pos)) + (nr << 8);
288
288
        nr2+=3;
289
289
      }
290
290
    }
291
291
  }
292
 
  return((uint32_t) nr);
 
292
  return((ulong) nr);
293
293
}
294
294
 
295
295
        /* Calc hashvalue for a key in a record */
296
296
 
297
 
uint32_t hp_rec_hashnr(register HP_KEYDEF *keydef, register const unsigned char *rec)
 
297
ulong hp_rec_hashnr(register HP_KEYDEF *keydef, register const uchar *rec)
298
298
{
299
 
  uint32_t nr=1, nr2=4;
 
299
  ulong nr=1, nr2=4;
300
300
  HA_KEYSEG *seg,*endseg;
301
301
 
302
302
  for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
303
303
  {
304
 
    unsigned char *pos=(unsigned char*) rec+seg->start,*end=pos+seg->length;
 
304
    uchar *pos=(uchar*) rec+seg->start,*end=pos+seg->length;
305
305
    if (seg->null_bit)
306
306
    {
307
307
      if (rec[seg->null_pos] & seg->null_bit)
312
312
    }
313
313
    if (seg->type == HA_KEYTYPE_TEXT)
314
314
    {
315
 
      const CHARSET_INFO * const cs= seg->charset;
316
 
      uint32_t char_length= seg->length;
 
315
      CHARSET_INFO *cs= seg->charset;
 
316
      uint char_length= seg->length;
317
317
      if (cs->mbmaxlen > 1)
318
318
      {
319
319
        char_length= my_charpos(cs, pos, pos + char_length,
324
324
    }
325
325
    else if (seg->type == HA_KEYTYPE_VARTEXT1)  /* Any VARCHAR segments */
326
326
    {
327
 
      const CHARSET_INFO * const cs= seg->charset;
328
 
      uint32_t pack_length= seg->bit_start;
329
 
      uint32_t length= (pack_length == 1 ? (uint) *(unsigned char*) pos : uint2korr(pos));
 
327
      CHARSET_INFO *cs= seg->charset;
 
328
      uint pack_length= seg->bit_start;
 
329
      uint length= (pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos));
330
330
      if (cs->mbmaxlen > 1)
331
331
      {
332
 
        uint32_t char_length;
 
332
        uint char_length;
333
333
        char_length= my_charpos(cs, pos + pack_length,
334
334
                                pos + pack_length + length,
335
335
                                seg->length/cs->mbmaxlen);
341
341
    {
342
342
      for (; pos < end ; pos++)
343
343
      {
344
 
        nr^=(uint32_t) ((((uint) nr & 63)+nr2)*((uint) *pos))+ (nr << 8);
 
344
        nr^=(ulong) ((((uint) nr & 63)+nr2)*((uint) *pos))+ (nr << 8);
345
345
        nr2+=3;
346
346
      }
347
347
    }
366
366
 * far, and works well on both numbers and strings.
367
367
 */
368
368
 
369
 
uint32_t hp_hashnr(register HP_KEYDEF *keydef, register const unsigned char *key)
 
369
ulong hp_hashnr(register HP_KEYDEF *keydef, register const uchar *key)
370
370
{
371
371
  /*
372
372
    Note, if a key consists of a combination of numeric and
374
374
    Making text columns work with NEW_HASH_FUNCTION
375
375
    needs also changes in strings/ctype-xxx.c.
376
376
  */
377
 
  uint32_t nr= 1, nr2= 4;
 
377
  ulong nr= 1, nr2= 4;
378
378
  HA_KEYSEG *seg,*endseg;
379
379
 
380
380
  for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
381
381
  {
382
 
    unsigned char *pos=(unsigned char*) key;
 
382
    uchar *pos=(uchar*) key;
383
383
    key+=seg->length;
384
384
    if (seg->null_bit)
385
385
    {
396
396
    }
397
397
    if (seg->type == HA_KEYTYPE_TEXT)
398
398
    {
399
 
      seg->charset->coll->hash_sort(seg->charset, pos, ((unsigned char*)key)-pos,
 
399
      seg->charset->coll->hash_sort(seg->charset, pos, ((uchar*)key)-pos,
400
400
                                    &nr, &nr2);
401
401
    }
402
402
    else if (seg->type == HA_KEYTYPE_VARTEXT1)  /* Any VARCHAR segments */
403
403
    {
404
 
      uint32_t pack_length= 2;                      /* Key packing is constant */
405
 
      uint32_t length= uint2korr(pos);
 
404
      uint pack_length= 2;                      /* Key packing is constant */
 
405
      uint length= uint2korr(pos);
406
406
      seg->charset->coll->hash_sort(seg->charset, pos+pack_length, length,
407
407
                                    &nr, &nr2);
408
408
      key+= pack_length;
409
409
    }
410
410
    else
411
411
    {
412
 
      for ( ; pos < (unsigned char*) key ; pos++)
 
412
      for ( ; pos < (uchar*) key ; pos++)
413
413
      {
414
414
        nr *=16777619; 
415
415
        nr ^=(uint) *pos;
421
421
 
422
422
        /* Calc hashvalue for a key in a record */
423
423
 
424
 
uint32_t hp_rec_hashnr(register HP_KEYDEF *keydef, register const unsigned char *rec)
 
424
ulong hp_rec_hashnr(register HP_KEYDEF *keydef, register const uchar *rec)
425
425
{
426
 
  uint32_t nr= 1, nr2= 4;
 
426
  ulong nr= 1, nr2= 4;
427
427
  HA_KEYSEG *seg,*endseg;
428
428
 
429
429
  for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
430
430
  {
431
 
    unsigned char *pos=(unsigned char*) rec+seg->start;
 
431
    uchar *pos=(uchar*) rec+seg->start;
432
432
    if (seg->null_bit)
433
433
    {
434
434
      if (rec[seg->null_pos] & seg->null_bit)
439
439
    }
440
440
    if (seg->type == HA_KEYTYPE_TEXT)
441
441
    {
442
 
      uint32_t char_length= seg->length; /* TODO: fix to use my_charpos() */
 
442
      uint char_length= seg->length; /* TODO: fix to use my_charpos() */
443
443
      seg->charset->coll->hash_sort(seg->charset, pos, char_length,
444
444
                                    &nr, &nr2);
445
445
    }
446
446
    else if (seg->type == HA_KEYTYPE_VARTEXT1)  /* Any VARCHAR segments */
447
447
    {
448
 
      uint32_t pack_length= seg->bit_start;
449
 
      uint32_t length= (pack_length == 1 ? (uint) *(unsigned char*) pos : uint2korr(pos));
 
448
      uint pack_length= seg->bit_start;
 
449
      uint length= (pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos));
450
450
      seg->charset->coll->hash_sort(seg->charset, pos+pack_length,
451
451
                                    length, &nr, &nr2);
452
452
    }
453
453
    else
454
454
    {
455
 
      unsigned char *end= pos+seg->length;
 
455
      uchar *end= pos+seg->length;
456
456
      for ( ; pos < end ; pos++)
457
457
      {
458
458
        nr *=16777619; 
486
486
    <> 0        Key differes
487
487
*/
488
488
 
489
 
int hp_rec_key_cmp(HP_KEYDEF *keydef, const unsigned char *rec1, const unsigned char *rec2,
490
 
                   bool diff_if_only_endspace_difference)
 
489
int hp_rec_key_cmp(HP_KEYDEF *keydef, const uchar *rec1, const uchar *rec2,
 
490
                   my_bool diff_if_only_endspace_difference)
491
491
{
492
492
  HA_KEYSEG *seg,*endseg;
493
493
 
503
503
    }
504
504
    if (seg->type == HA_KEYTYPE_TEXT)
505
505
    {
506
 
      const CHARSET_INFO * const cs= seg->charset;
507
 
      uint32_t char_length1;
508
 
      uint32_t char_length2;
509
 
      unsigned char *pos1= (unsigned char*)rec1 + seg->start;
510
 
      unsigned char *pos2= (unsigned char*)rec2 + seg->start;
 
506
      CHARSET_INFO *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;
511
511
      if (cs->mbmaxlen > 1)
512
512
      {
513
 
        uint32_t char_length= seg->length / cs->mbmaxlen;
 
513
        uint char_length= seg->length / cs->mbmaxlen;
514
514
        char_length1= my_charpos(cs, pos1, pos1 + seg->length, char_length);
515
515
        set_if_smaller(char_length1, seg->length);
516
516
        char_length2= my_charpos(cs, pos2, pos2 + seg->length, char_length);
527
527
    }
528
528
    else if (seg->type == HA_KEYTYPE_VARTEXT1)  /* Any VARCHAR segments */
529
529
    {
530
 
      unsigned char *pos1= (unsigned char*) rec1 + seg->start;
531
 
      unsigned char *pos2= (unsigned char*) rec2 + seg->start;
532
 
      uint32_t char_length1, char_length2;
533
 
      uint32_t pack_length= seg->bit_start;
534
 
      const CHARSET_INFO * const cs= seg->charset;
 
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;
 
534
      CHARSET_INFO *cs= seg->charset;
535
535
      if (pack_length == 1)
536
536
      {
537
 
        char_length1= (uint) *(unsigned char*) pos1++;
538
 
        char_length2= (uint) *(unsigned char*) pos2++;
 
537
        char_length1= (uint) *(uchar*) pos1++;
 
538
        char_length2= (uint) *(uchar*) pos2++;
539
539
      }
540
540
      else
541
541
      {
546
546
      }
547
547
      if (cs->mbmaxlen > 1)
548
548
      {
549
 
        uint32_t safe_length1= char_length1;
550
 
        uint32_t safe_length2= char_length2;
551
 
        uint32_t char_length= seg->length / cs->mbmaxlen;
 
549
        uint safe_length1= char_length1;
 
550
        uint safe_length2= char_length2;
 
551
        uint char_length= seg->length / cs->mbmaxlen;
552
552
        char_length1= my_charpos(cs, pos1, pos1 + char_length1, char_length);
553
553
        set_if_smaller(char_length1, safe_length1);
554
554
        char_length2= my_charpos(cs, pos2, pos2 + char_length2, char_length);
564
564
    }
565
565
    else
566
566
    {
567
 
      if (memcmp(rec1+seg->start,rec2+seg->start,seg->length))
 
567
      if (bcmp(rec1+seg->start,rec2+seg->start,seg->length))
568
568
        return 1;
569
569
    }
570
570
  }
573
573
 
574
574
        /* Compare a key in a record to a whole key */
575
575
 
576
 
int hp_key_cmp(HP_KEYDEF *keydef, const unsigned char *rec, const unsigned char *key)
 
576
int hp_key_cmp(HP_KEYDEF *keydef, const uchar *rec, const uchar *key)
577
577
{
578
578
  HA_KEYSEG *seg,*endseg;
579
579
 
596
596
    }
597
597
    if (seg->type == HA_KEYTYPE_TEXT)
598
598
    {
599
 
      const CHARSET_INFO * const cs= seg->charset;
600
 
      uint32_t char_length_key;
601
 
      uint32_t char_length_rec;
602
 
      unsigned char *pos= (unsigned char*) rec + seg->start;
 
599
      CHARSET_INFO *cs= seg->charset;
 
600
      uint char_length_key;
 
601
      uint char_length_rec;
 
602
      uchar *pos= (uchar*) rec + seg->start;
603
603
      if (cs->mbmaxlen > 1)
604
604
      {
605
 
        uint32_t char_length= seg->length / cs->mbmaxlen;
 
605
        uint char_length= seg->length / cs->mbmaxlen;
606
606
        char_length_key= my_charpos(cs, key, key + seg->length, char_length);
607
607
        set_if_smaller(char_length_key, seg->length);
608
608
        char_length_rec= my_charpos(cs, pos, pos + seg->length, char_length);
615
615
      }
616
616
      
617
617
      if (seg->charset->coll->strnncollsp(seg->charset,
618
 
                                          (unsigned char*) pos, char_length_rec,
619
 
                                          (unsigned char*) key, char_length_key, 0))
 
618
                                          (uchar*) pos, char_length_rec,
 
619
                                          (uchar*) key, char_length_key, 0))
620
620
        return 1;
621
621
    }
622
622
    else if (seg->type == HA_KEYTYPE_VARTEXT1)  /* Any VARCHAR segments */
623
623
    {
624
 
      unsigned char *pos= (unsigned char*) rec + seg->start;
625
 
      const CHARSET_INFO * const cs= seg->charset;
626
 
      uint32_t pack_length= seg->bit_start;
627
 
      uint32_t char_length_rec= (pack_length == 1 ? (uint) *(unsigned char*) pos :
 
624
      uchar *pos= (uchar*) rec + seg->start;
 
625
      CHARSET_INFO *cs= seg->charset;
 
626
      uint pack_length= seg->bit_start;
 
627
      uint char_length_rec= (pack_length == 1 ? (uint) *(uchar*) pos :
628
628
                             uint2korr(pos));
629
629
      /* Key segments are always packed with 2 bytes */
630
 
      uint32_t char_length_key= uint2korr(key);
 
630
      uint char_length_key= uint2korr(key);
631
631
      pos+= pack_length;
632
632
      key+= 2;                                  /* skip key pack length */
633
633
      if (cs->mbmaxlen > 1)
634
634
      {
635
 
        uint32_t char_length1, char_length2;
 
635
        uint char_length1, char_length2;
636
636
        char_length1= char_length2= seg->length / cs->mbmaxlen; 
637
637
        char_length1= my_charpos(cs, key, key + char_length_key, char_length1);
638
638
        set_if_smaller(char_length_key, char_length1);
641
641
      }
642
642
 
643
643
      if (cs->coll->strnncollsp(seg->charset,
644
 
                                (unsigned char*) pos, char_length_rec,
645
 
                                (unsigned char*) key, char_length_key, 0))
 
644
                                (uchar*) pos, char_length_rec,
 
645
                                (uchar*) key, char_length_key, 0))
646
646
        return 1;
647
647
    }
648
648
    else
649
649
    {
650
 
      if (memcmp(rec+seg->start,key,seg->length))
 
650
      if (bcmp(rec+seg->start,key,seg->length))
651
651
        return 1;
652
652
    }
653
653
  }
657
657
 
658
658
        /* Copy a key from a record to a keybuffer */
659
659
 
660
 
void hp_make_key(HP_KEYDEF *keydef, unsigned char *key, const unsigned char *rec)
 
660
void hp_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec)
661
661
{
662
662
  HA_KEYSEG *seg,*endseg;
663
663
 
664
664
  for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
665
665
  {
666
 
    const CHARSET_INFO * const cs= seg->charset;
667
 
    uint32_t char_length= seg->length;
668
 
    unsigned char *pos= (unsigned char*) rec + seg->start;
 
666
    CHARSET_INFO *cs= seg->charset;
 
667
    uint char_length= seg->length;
 
668
    uchar *pos= (uchar*) rec + seg->start;
669
669
    if (seg->null_bit)
670
670
      *key++= test(rec[seg->null_pos] & seg->null_bit);
671
671
    if (cs->mbmaxlen > 1)
689
689
  } while(0)
690
690
 
691
691
 
692
 
uint32_t hp_rb_make_key(HP_KEYDEF *keydef, unsigned char *key, 
693
 
                    const unsigned char *rec, unsigned char *recpos)
 
692
uint hp_rb_make_key(HP_KEYDEF *keydef, uchar *key, 
 
693
                    const uchar *rec, uchar *recpos)
694
694
{
695
 
  unsigned char *start_key= key;
 
695
  uchar *start_key= key;
696
696
  HA_KEYSEG *seg, *endseg;
697
697
 
698
698
  for (seg= keydef->seg, endseg= seg + keydef->keysegs; seg < endseg; seg++)
699
699
  {
700
 
    uint32_t char_length;
 
700
    uint char_length;
701
701
    if (seg->null_bit)
702
702
    {
703
703
      if (!(*key++= 1 - test(rec[seg->null_pos] & seg->null_bit)))
705
705
    }
706
706
    if (seg->flag & HA_SWAP_KEY)
707
707
    {
708
 
      uint32_t length= seg->length;
709
 
      unsigned char *pos= (unsigned char*) rec + seg->start;
 
708
      uint length= seg->length;
 
709
      uchar *pos= (uchar*) rec + seg->start;
710
710
      
711
711
#ifdef HAVE_ISNAN
712
712
      if (seg->type == HA_KEYTYPE_FLOAT)
716
716
        if (isnan(nr))
717
717
        {
718
718
          /* Replace NAN with zero */
719
 
          memset(key, 0, length);
 
719
          bzero(key, length);
720
720
          key+= length;
721
721
          continue;
722
722
        }
727
727
        float8get(nr, pos);
728
728
        if (isnan(nr))
729
729
        {
730
 
          memset(key, 0, length);
 
730
          bzero(key, length);
731
731
          key+= length;
732
732
          continue;
733
733
        }
743
743
 
744
744
    if (seg->flag & HA_VAR_LENGTH_PART)
745
745
    {
746
 
      unsigned char *pos=      (unsigned char*) rec + seg->start;
747
 
      uint32_t length=     seg->length;
748
 
      uint32_t pack_length= seg->bit_start;
749
 
      uint32_t tmp_length= (pack_length == 1 ? (uint) *(unsigned char*) pos :
 
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 :
750
750
                        uint2korr(pos));
751
 
      const CHARSET_INFO * const cs= seg->charset;
 
751
      CHARSET_INFO *cs= seg->charset;
752
752
      char_length= length/cs->mbmaxlen;
753
753
 
754
754
      pos+= pack_length;                        /* Skip VARCHAR length */
755
755
      set_if_smaller(length,tmp_length);
756
756
      FIX_LENGTH(cs, pos, length, char_length);
757
757
      store_key_length_inc(key,char_length);
758
 
      memcpy(key,pos,(size_t) char_length);
 
758
      memcpy((uchar*) key,(uchar*) pos,(size_t) char_length);
759
759
      key+= char_length;
760
760
      continue;
761
761
    }
774
774
    memcpy(key, rec + seg->start, (size_t) char_length);
775
775
    key+= seg->length;
776
776
  }
777
 
  memcpy(key, &recpos, sizeof(unsigned char*));
 
777
  memcpy(key, &recpos, sizeof(uchar*));
778
778
  return (uint) (key - start_key);
779
779
}
780
780
 
781
781
 
782
 
uint32_t hp_rb_pack_key(HP_KEYDEF *keydef, unsigned char *key, const unsigned char *old,
 
782
uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old,
783
783
                    key_part_map keypart_map)
784
784
{
785
785
  HA_KEYSEG *seg, *endseg;
786
 
  unsigned char *start_key= key;
 
786
  uchar *start_key= key;
787
787
 
788
788
  for (seg= keydef->seg, endseg= seg + keydef->keysegs;
789
789
       seg < endseg && keypart_map; old+= seg->length, seg++)
790
790
  {
791
 
    uint32_t char_length;
 
791
    uint char_length;
792
792
    keypart_map>>= 1;
793
793
    if (seg->null_bit)
794
794
    {
797
797
      }
798
798
    if (seg->flag & HA_SWAP_KEY)
799
799
    {
800
 
      uint32_t length= seg->length;
801
 
      unsigned char *pos= (unsigned char*) old + length;
 
800
      uint length= seg->length;
 
801
      uchar *pos= (uchar*) old + length;
802
802
      
803
803
      while (length--)
804
804
      {
809
809
    if (seg->flag & (HA_VAR_LENGTH_PART | HA_BLOB_PART))
810
810
    {
811
811
      /* Length of key-part used with heap_rkey() always 2 */
812
 
      uint32_t tmp_length=uint2korr(old);
813
 
      uint32_t length= seg->length;
814
 
      const CHARSET_INFO * const cs= seg->charset;
 
812
      uint tmp_length=uint2korr(old);
 
813
      uint length= seg->length;
 
814
      CHARSET_INFO *cs= seg->charset;
815
815
      char_length= length/cs->mbmaxlen;
816
816
 
817
817
      old+= 2;
818
818
      set_if_smaller(length,tmp_length);        /* Safety */
819
819
      FIX_LENGTH(cs, old, length, char_length);
820
820
      store_key_length_inc(key,char_length);
821
 
      memcpy(key, old,(size_t) char_length);
 
821
      memcpy((uchar*) key, old,(size_t) char_length);
822
822
      key+= char_length;
823
823
      continue;
824
824
    }
839
839
}
840
840
 
841
841
 
842
 
uint32_t hp_rb_key_length(HP_KEYDEF *keydef, 
843
 
                      const unsigned char *key __attribute__((unused)))
 
842
uint hp_rb_key_length(HP_KEYDEF *keydef, 
 
843
                      const uchar *key __attribute__((unused)))
844
844
{
845
845
  return keydef->length;
846
846
}
847
847
 
848
848
 
849
 
uint32_t hp_rb_null_key_length(HP_KEYDEF *keydef, const unsigned char *key)
 
849
uint hp_rb_null_key_length(HP_KEYDEF *keydef, const uchar *key)
850
850
{
851
 
  const unsigned char *start_key= key;
 
851
  const uchar *start_key= key;
852
852
  HA_KEYSEG *seg, *endseg;
853
853
  
854
854
  for (seg= keydef->seg, endseg= seg + keydef->keysegs; seg < endseg; seg++)
861
861
}
862
862
                  
863
863
 
864
 
uint32_t hp_rb_var_key_length(HP_KEYDEF *keydef, const unsigned char *key)
 
864
uint hp_rb_var_key_length(HP_KEYDEF *keydef, const uchar *key)
865
865
{
866
 
  const unsigned char *start_key= key;
 
866
  const uchar *start_key= key;
867
867
  HA_KEYSEG *seg, *endseg;
868
868
  
869
869
  for (seg= keydef->seg, endseg= seg + keydef->keysegs; seg < endseg; seg++)
870
870
  {
871
 
    uint32_t length= seg->length;
 
871
    uint length= seg->length;
872
872
    if (seg->null_bit && !*key++)
873
873
      continue;
874
874
    if (seg->flag & (HA_VAR_LENGTH_PART | HA_BLOB_PART))
888
888
    0 otherwise
889
889
*/
890
890
 
891
 
bool hp_if_null_in_key(HP_KEYDEF *keydef, const unsigned char *record)
 
891
my_bool hp_if_null_in_key(HP_KEYDEF *keydef, const uchar *record)
892
892
{
893
893
  HA_KEYSEG *seg,*endseg;
894
894
  for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
914
914
    less than zero.
915
915
*/
916
916
 
917
 
void heap_update_auto_increment(HP_INFO *info, const unsigned char *record)
 
917
void heap_update_auto_increment(HP_INFO *info, const uchar *record)
918
918
{
919
919
  uint64_t value= 0;                    /* Store unsigned values here */
920
920
  int64_t s_value= 0;                   /* Store signed values here */
921
921
 
922
922
  HA_KEYSEG *keyseg= info->s->keydef[info->s->auto_key - 1].seg;
923
 
  const unsigned char *key=  (unsigned char*) record + keyseg->start;
 
923
  const uchar *key=  (uchar*) record + keyseg->start;
924
924
 
925
925
  switch (info->s->auto_key_type) {
926
926
  case HA_KEYTYPE_INT8:
927
927
    s_value= (int64_t) *(char*)key;
928
928
    break;
929
929
  case HA_KEYTYPE_BINARY:
930
 
    value=(uint64_t)  *(unsigned char*) key;
 
930
    value=(uint64_t)  *(uchar*) key;
931
931
    break;
932
932
  case HA_KEYTYPE_SHORT_INT:
933
933
    s_value= (int64_t) sint2korr(key);