~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_create.c

  • Committer: Monty Taylor
  • Date: 2008-07-05 11:20:18 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: monty@inaugust.com-20080705112018-fr12kkmgphtu7m29
Changes so that removal of duplicate curr_dir from my_sys.h work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* Create a MyISAM table */
17
17
 
18
 
#include "myisamdef.h"
19
 
#include <mysys/my_tree.h>
20
 
#include <mysys/queues.h>
21
 
#include <mysys/my_bit.h>
 
18
#include "ftdefs.h"
 
19
#include "sp_defs.h"
 
20
#include <my_bit.h>
22
21
 
23
 
#include <drizzled/util/test.h>
 
22
#if defined(MSDOS) || defined(__WIN__)
 
23
#ifdef __WIN__
 
24
#include <fcntl.h>
 
25
#else
 
26
#include <process.h>                    /* Prototype for getpid */
 
27
#endif
 
28
#endif
 
29
#include <m_ctype.h>
24
30
 
25
31
/*
26
32
  Old options is used when recreating database, from myisamchk
27
33
*/
28
34
 
29
 
int mi_create(const char *name,uint32_t keys,MI_KEYDEF *keydefs,
30
 
              uint32_t columns, MI_COLUMNDEF *recinfo,
31
 
              uint32_t uniques, MI_UNIQUEDEF *uniquedefs,
32
 
              MI_CREATE_INFO *ci,uint32_t flags)
 
35
int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
 
36
              uint columns, MI_COLUMNDEF *recinfo,
 
37
              uint uniques, MI_UNIQUEDEF *uniquedefs,
 
38
              MI_CREATE_INFO *ci,uint flags)
33
39
{
34
 
  register uint32_t i, j;
35
 
  File dfile= 0, file= 0;
 
40
  register uint i, j;
 
41
  File dfile= 0, file;
36
42
  int errpos,save_errno, create_mode= O_RDWR | O_TRUNC;
37
43
  myf create_flag;
38
 
  uint32_t fields,length,max_key_length,packed,pointer,real_length_diff,
 
44
  uint fields,length,max_key_length,packed,pointer,real_length_diff,
39
45
       key_length,info_length,key_segs,options,min_key_length_skip,
40
46
       base_pos,long_varchar_count,varchar_length,
41
47
       max_key_block_length,unique_key_parts,fulltext_keys,offset;
42
 
  uint32_t aligned_key_start, block_length;
 
48
  uint aligned_key_start, block_length;
43
49
  ulong reclength, real_reclength,min_pack_length;
44
50
  char filename[FN_REFLEN],linkname[FN_REFLEN], *linkname_ptr;
45
51
  ulong pack_reclength;
46
 
  uint64_t tot_length,max_rows, tmp;
 
52
  ulonglong tot_length,max_rows, tmp;
47
53
  enum en_fieldtype type;
48
54
  MYISAM_SHARE share;
49
55
  MI_KEYDEF *keydef,tmp_keydef;
53
59
  ulong *rec_per_key_part;
54
60
  my_off_t key_root[HA_MAX_POSSIBLE_KEY],key_del[MI_MAX_KEY_BLOCK_SIZE];
55
61
  MI_CREATE_INFO tmp_create_info;
 
62
  DBUG_ENTER("mi_create");
 
63
  DBUG_PRINT("enter", ("keys: %u  columns: %u  uniques: %u  flags: %u",
 
64
                      keys, columns, uniques, flags));
56
65
 
57
66
  if (!ci)
58
67
  {
59
 
    memset(&tmp_create_info, 0, sizeof(tmp_create_info));
 
68
    bzero((char*) &tmp_create_info,sizeof(tmp_create_info));
60
69
    ci=&tmp_create_info;
61
70
  }
62
71
 
63
72
  if (keys + uniques > MI_MAX_KEY || columns == 0)
64
73
  {
65
 
    return(my_errno=HA_WRONG_CREATE_OPTION);
 
74
    DBUG_RETURN(my_errno=HA_WRONG_CREATE_OPTION);
66
75
  }
67
76
  errpos= 0;
68
77
  options= 0;
69
 
  memset(&share, 0, sizeof(share));
 
78
  bzero((uchar*) &share,sizeof(share));
70
79
 
71
80
  if (flags & HA_DONT_TOUCH_DATA)
72
81
  {
86
95
  if (!(rec_per_key_part=
87
96
        (ulong*) my_malloc((keys + uniques)*MI_MAX_KEY_SEG*sizeof(long),
88
97
                           MYF(MY_WME | MY_ZEROFILL))))
89
 
    return(my_errno);
 
98
    DBUG_RETURN(my_errno);
90
99
 
91
100
        /* Start by checking fields and field-types used */
92
101
 
104
113
      if (type == FIELD_BLOB)
105
114
      {
106
115
        share.base.blobs++;
107
 
        if (pack_reclength != INT32_MAX)
 
116
        if (pack_reclength != INT_MAX32)
108
117
        {
109
118
          if (rec->length == 4+portable_sizeof_char_ptr)
110
 
            pack_reclength= INT32_MAX;
 
119
            pack_reclength= INT_MAX32;
111
120
          else
112
121
            pack_reclength+=(1 << ((rec->length-portable_sizeof_char_ptr)*8)); /* Max blob length */
113
122
        }
115
124
      else if (type == FIELD_SKIP_PRESPACE ||
116
125
               type == FIELD_SKIP_ENDSPACE)
117
126
      {
118
 
        if (pack_reclength != INT32_MAX)
 
127
        if (pack_reclength != INT_MAX32)
119
128
          pack_reclength+= rec->length > 255 ? 2 : 1;
120
129
        min_pack_length++;
121
130
      }
170
179
  if (flags & HA_CREATE_TMP_TABLE)
171
180
  {
172
181
    options|= HA_OPTION_TMP_TABLE;
173
 
    create_mode|= O_EXCL;
 
182
    create_mode|= O_EXCL | O_NOFOLLOW;
174
183
  }
175
184
  if (flags & HA_CREATE_CHECKSUM || (options & HA_OPTION_CHECKSUM))
176
185
  {
183
192
    options|= HA_OPTION_RELIES_ON_SQL_LAYER;
184
193
 
185
194
  packed=(packed+7)/8;
186
 
  if (pack_reclength != INT32_MAX)
 
195
  if (pack_reclength != INT_MAX32)
187
196
    pack_reclength+= reclength+packed +
188
197
      test(test_all_bits(options, HA_OPTION_CHECKSUM | HA_PACK_RECORD));
189
198
  min_pack_length+=packed;
190
199
 
191
200
  if (!ci->data_file_length && ci->max_rows)
192
201
  {
193
 
    if (pack_reclength == INT32_MAX ||
194
 
             (~(uint64_t) 0)/ci->max_rows < (uint64_t) pack_reclength)
195
 
      ci->data_file_length= ~(uint64_t) 0;
 
202
    if (pack_reclength == INT_MAX32 ||
 
203
             (~(ulonglong) 0)/ci->max_rows < (ulonglong) pack_reclength)
 
204
      ci->data_file_length= ~(ulonglong) 0;
196
205
    else
197
 
      ci->data_file_length=(uint64_t) ci->max_rows*pack_reclength;
 
206
      ci->data_file_length=(ulonglong) ci->max_rows*pack_reclength;
198
207
  }
199
208
  else if (!ci->max_rows)
200
209
    ci->max_rows=(ha_rows) (ci->data_file_length/(min_pack_length +
205
214
    pointer=mi_get_pointer_length(ci->data_file_length,myisam_data_pointer_size);
206
215
  else
207
216
    pointer=mi_get_pointer_length(ci->max_rows,myisam_data_pointer_size);
208
 
  if (!(max_rows=(uint64_t) ci->max_rows))
209
 
    max_rows= ((((uint64_t) 1 << (pointer*8)) -1) / min_pack_length);
 
217
  if (!(max_rows=(ulonglong) ci->max_rows))
 
218
    max_rows= ((((ulonglong) 1 << (pointer*8)) -1) / min_pack_length);
210
219
 
211
220
 
212
221
  real_reclength=reclength;
236
245
    share.state.key_root[i]= HA_OFFSET_ERROR;
237
246
    min_key_length_skip=length=real_length_diff=0;
238
247
    key_length=pointer;
 
248
    if (keydef->flag & HA_SPATIAL)
 
249
    {
 
250
#ifdef HAVE_SPATIAL
 
251
      /* BAR TODO to support 3D and more dimensions in the future */
 
252
      uint sp_segs=SPDIMS*2;
 
253
      keydef->flag=HA_SPATIAL;
 
254
 
 
255
      if (flags & HA_DONT_TOUCH_DATA)
 
256
      {
 
257
        /*
 
258
           called by myisamchk - i.e. table structure was taken from
 
259
           MYI file and SPATIAL key *does have* additional sp_segs keysegs.
 
260
           keydef->seg here points right at the GEOMETRY segment,
 
261
           so we only need to decrease keydef->keysegs.
 
262
           (see recreate_table() in mi_check.c)
 
263
        */
 
264
        keydef->keysegs-=sp_segs-1;
 
265
      }
 
266
 
 
267
      for (j=0, keyseg=keydef->seg ; (int) j < keydef->keysegs ;
 
268
           j++, keyseg++)
 
269
      {
 
270
        if (keyseg->type != HA_KEYTYPE_BINARY &&
 
271
            keyseg->type != HA_KEYTYPE_VARBINARY1 &&
 
272
            keyseg->type != HA_KEYTYPE_VARBINARY2)
 
273
        {
 
274
          my_errno=HA_WRONG_CREATE_OPTION;
 
275
          goto err;
 
276
        }
 
277
      }
 
278
      keydef->keysegs+=sp_segs;
 
279
      key_length+=SPLEN*sp_segs;
 
280
      length++;                              /* At least one length byte */
 
281
      min_key_length_skip+=SPLEN*2*SPDIMS;
 
282
#else
 
283
      my_errno= HA_ERR_UNSUPPORTED;
 
284
      goto err;
 
285
#endif /*HAVE_SPATIAL*/
 
286
    }
 
287
    else if (keydef->flag & HA_FULLTEXT)
 
288
    {
 
289
      keydef->flag=HA_FULLTEXT | HA_PACK_KEY | HA_VAR_LENGTH_KEY;
 
290
      options|=HA_OPTION_PACK_KEYS;             /* Using packed keys */
 
291
 
 
292
      for (j=0, keyseg=keydef->seg ; (int) j < keydef->keysegs ;
 
293
           j++, keyseg++)
 
294
      {
 
295
        if (keyseg->type != HA_KEYTYPE_TEXT &&
 
296
            keyseg->type != HA_KEYTYPE_VARTEXT1 &&
 
297
            keyseg->type != HA_KEYTYPE_VARTEXT2)
 
298
        {
 
299
          my_errno=HA_WRONG_CREATE_OPTION;
 
300
          goto err;
 
301
        }
 
302
        if (!(keyseg->flag & HA_BLOB_PART) &&
 
303
            (keyseg->type == HA_KEYTYPE_VARTEXT1 ||
 
304
             keyseg->type == HA_KEYTYPE_VARTEXT2))
 
305
        {
 
306
          /* Make a flag that this is a VARCHAR */
 
307
          keyseg->flag|= HA_VAR_LENGTH_PART;
 
308
          /* Store in bit_start number of bytes used to pack the length */
 
309
          keyseg->bit_start= ((keyseg->type == HA_KEYTYPE_VARTEXT1)?
 
310
                              1 : 2);
 
311
        }
 
312
      }
 
313
 
 
314
      fulltext_keys++;
 
315
      key_length+= HA_FT_MAXBYTELEN+HA_FT_WLEN;
 
316
      length++;                              /* At least one length byte */
 
317
      min_key_length_skip+=HA_FT_MAXBYTELEN;
 
318
      real_length_diff=HA_FT_MAXBYTELEN-FT_MAX_WORD_LEN_FOR_SORT;
 
319
    }
 
320
    else
239
321
    {
240
322
      /* Test if prefix compression */
241
323
      if (keydef->flag & HA_PACK_KEY)
301
383
        }
302
384
        if (keyseg->flag & HA_SPACE_PACK)
303
385
        {
304
 
          assert(!(keyseg->flag & HA_VAR_LENGTH_PART));
 
386
          DBUG_ASSERT(!(keyseg->flag & HA_VAR_LENGTH_PART));
305
387
          keydef->flag |= HA_SPACE_PACK_USED | HA_VAR_LENGTH_KEY;
306
388
          options|=HA_OPTION_PACK_KEYS;         /* Using packed keys */
307
389
          length++;                             /* At least one length byte */
314
396
        }
315
397
        if (keyseg->flag & (HA_VAR_LENGTH_PART | HA_BLOB_PART))
316
398
        {
317
 
          assert(!test_all_bits(keyseg->flag,
 
399
          DBUG_ASSERT(!test_all_bits(keyseg->flag,
318
400
                                    (HA_VAR_LENGTH_PART | HA_BLOB_PART)));
319
401
          keydef->flag|=HA_VAR_LENGTH_KEY;
320
402
          length++;                             /* At least one length byte */
355
437
    block_length= (keydef->block_length ? 
356
438
                   my_round_up_to_next_power(keydef->block_length) :
357
439
                   myisam_block_size);
358
 
    block_length= cmax(block_length, MI_MIN_KEY_BLOCK_LENGTH);
359
 
    block_length= cmin(block_length, MI_MAX_KEY_BLOCK_LENGTH);
 
440
    block_length= max(block_length, MI_MIN_KEY_BLOCK_LENGTH);
 
441
    block_length= min(block_length, MI_MAX_KEY_BLOCK_LENGTH);
360
442
 
361
 
    keydef->block_length= (uint16_t) MI_BLOCK_SIZE(length-real_length_diff,
 
443
    keydef->block_length= (uint16) MI_BLOCK_SIZE(length-real_length_diff,
362
444
                                                 pointer,MI_MAX_KEYPTR_SIZE,
363
445
                                                 block_length);
364
446
    if (keydef->block_length > MI_MAX_KEY_BLOCK_LENGTH ||
368
450
      goto err;
369
451
    }
370
452
    set_if_bigger(max_key_block_length,keydef->block_length);
371
 
    keydef->keylength= (uint16_t) key_length;
372
 
    keydef->minlength= (uint16_t) (length-min_key_length_skip);
373
 
    keydef->maxlength= (uint16_t) length;
 
453
    keydef->keylength= (uint16) key_length;
 
454
    keydef->minlength= (uint16) (length-min_key_length_skip);
 
455
    keydef->maxlength= (uint16) length;
374
456
 
375
457
    if (length > max_key_length)
376
458
      max_key_length= length;
404
486
                               uniques * MI_UNIQUEDEF_SIZE +
405
487
                               (key_segs + unique_key_parts)*HA_KEYSEG_SIZE+
406
488
                               columns*MI_COLUMNDEF_SIZE);
 
489
  DBUG_PRINT("info", ("info_length: %u", info_length));
407
490
  /* There are only 16 bits for the total header length. */
408
491
  if (info_length > 65535)
409
492
  {
414
497
    goto err;
415
498
  }
416
499
 
417
 
  memcpy(share.state.header.file_version,myisam_file_magic,4);
 
500
  bmove(share.state.header.file_version,(uchar*) myisam_file_magic,4);
418
501
  ci->old_options=options| (ci->old_options & HA_OPTION_TEMP_COMPRESS_RECORD ?
419
502
                        HA_OPTION_COMPRESS_RECORD |
420
503
                        HA_OPTION_TEMP_COMPRESS_RECORD: 0);
432
515
  share.state.unique=   (ulong) 0;
433
516
  share.state.update_count=(ulong) 0;
434
517
  share.state.version=  (ulong) time((time_t*) 0);
435
 
  share.state.sortkey=  UINT16_MAX;
 
518
  share.state.sortkey=  (ushort) ~0;
436
519
  share.state.auto_increment=ci->auto_increment;
437
520
  share.options=options;
438
521
  share.base.rec_reflength=pointer;
444
527
    got from MYI file header (see also myisampack.c:save_state)
445
528
  */
446
529
  share.base.key_reflength=
447
 
    mi_get_pointer_length(cmax(ci->key_file_length,tmp),3);
 
530
    mi_get_pointer_length(max(ci->key_file_length,tmp),3);
448
531
  share.base.keys= share.state.header.keys= keys;
449
532
  share.state.header.uniques= uniques;
450
533
  share.state.header.fulltext_keys= fulltext_keys;
469
552
  share.base.pack_bits=packed;
470
553
  share.base.fields=fields;
471
554
  share.base.pack_fields=packed;
 
555
#ifdef USE_RAID
 
556
  share.base.raid_type=ci->raid_type;
 
557
  share.base.raid_chunks=ci->raid_chunks;
 
558
  share.base.raid_chunksize=ci->raid_chunksize;
 
559
#endif
472
560
 
473
561
  /* max_data_file_length and max_key_file_length are recalculated on open */
474
562
  if (options & HA_OPTION_TMP_TABLE)
477
565
  share.base.min_block_length=
478
566
    (share.base.pack_reclength+3 < MI_EXTEND_BLOCK_LENGTH &&
479
567
     ! share.base.blobs) ?
480
 
    cmax(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
 
568
    max(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
481
569
    MI_EXTEND_BLOCK_LENGTH;
482
570
  if (! (flags & HA_DONT_TOUCH_DATA))
483
571
    share.state.create_time= (long) time((time_t*) 0);
555
643
 
556
644
  if (!(flags & HA_DONT_TOUCH_DATA))
557
645
  {
 
646
#ifdef USE_RAID
 
647
    if (share.base.raid_type)
 
648
    {
 
649
      (void) fn_format(filename, name, "", MI_NAME_DEXT,
 
650
                       MY_UNPACK_FILENAME | MY_APPEND_EXT);
 
651
      if ((dfile=my_raid_create(filename, 0, create_mode,
 
652
                                share.base.raid_type,
 
653
                                share.base.raid_chunks,
 
654
                                share.base.raid_chunksize,
 
655
                                MYF(MY_WME | MY_RAID))) < 0)
 
656
        goto err;
 
657
    }
 
658
    else
 
659
#endif
558
660
    {
559
661
      if (ci->data_file_name)
560
662
      {
597
699
    errpos=3;
598
700
  }
599
701
 
 
702
  DBUG_PRINT("info", ("write state info and base info"));
600
703
  if (mi_state_info_write(file, &share.state, 2) ||
601
704
      mi_base_info_write(file, &share.base))
602
705
    goto err;
 
706
#ifndef DBUG_OFF
 
707
  if ((uint) my_tell(file,MYF(0)) != base_pos+ MI_BASE_INFO_SIZE)
 
708
  {
 
709
    uint pos=(uint) my_tell(file,MYF(0));
 
710
    DBUG_PRINT("warning",("base_length: %d  != used_length: %d",
 
711
                          base_pos+ MI_BASE_INFO_SIZE, pos));
 
712
  }
 
713
#endif
603
714
 
604
715
  /* Write key and keyseg definitions */
 
716
  DBUG_PRINT("info", ("write key and keyseg definitions"));
605
717
  for (i=0 ; i < share.base.keys - uniques; i++)
606
718
  {
607
 
    uint32_t sp_segs= 0;
 
719
    uint sp_segs=(keydefs[i].flag & HA_SPATIAL) ? 2*SPDIMS : 0;
608
720
 
609
721
    if (mi_keydef_write(file, &keydefs[i]))
610
722
      goto err;
611
723
    for (j=0 ; j < keydefs[i].keysegs-sp_segs ; j++)
612
724
      if (mi_keyseg_write(file, &keydefs[i].seg[j]))
613
725
       goto err;
 
726
#ifdef HAVE_SPATIAL
 
727
    for (j=0 ; j < sp_segs ; j++)
 
728
    {
 
729
      HA_KEYSEG sseg;
 
730
      sseg.type=SPTYPE;
 
731
      sseg.language= 7;                         /* Binary */
 
732
      sseg.null_bit=0;
 
733
      sseg.bit_start=0;
 
734
      sseg.bit_end=0;
 
735
      sseg.bit_length= 0;
 
736
      sseg.bit_pos= 0;
 
737
      sseg.length=SPLEN;
 
738
      sseg.null_pos=0;
 
739
      sseg.start=j*SPLEN;
 
740
      sseg.flag= HA_SWAP_KEY;
 
741
      if (mi_keyseg_write(file, &sseg))
 
742
        goto err;
 
743
    }
 
744
#endif
614
745
  }
615
746
  /* Create extra keys for unique definitions */
616
747
  offset=reclength-uniques*MI_UNIQUE_HASH_LENGTH;
617
 
  memset(&tmp_keydef, 0, sizeof(tmp_keydef));
618
 
  memset(&tmp_keyseg, 0, sizeof(tmp_keyseg));
 
748
  bzero((char*) &tmp_keydef,sizeof(tmp_keydef));
 
749
  bzero((char*) &tmp_keyseg,sizeof(tmp_keyseg));
619
750
  for (i=0; i < uniques ; i++)
620
751
  {
621
752
    tmp_keydef.keysegs=1;
622
753
    tmp_keydef.flag=            HA_UNIQUE_CHECK;
623
 
    tmp_keydef.block_length=    (uint16_t)myisam_block_size;
 
754
    tmp_keydef.block_length=    (uint16)myisam_block_size;
624
755
    tmp_keydef.keylength=       MI_UNIQUE_HASH_LENGTH + pointer;
625
756
    tmp_keydef.minlength=tmp_keydef.maxlength=tmp_keydef.keylength;
626
757
    tmp_keyseg.type=            MI_UNIQUE_HASH_TYPE;
633
764
  }
634
765
 
635
766
  /* Save unique definition */
 
767
  DBUG_PRINT("info", ("write unique definitions"));
636
768
  for (i=0 ; i < share.state.header.uniques ; i++)
637
769
  {
638
770
    HA_KEYSEG *keyseg_end;
663
795
        goto err;
664
796
    }
665
797
  }
 
798
  DBUG_PRINT("info", ("write field definitions"));
666
799
  for (i=0 ; i < share.base.fields ; i++)
667
800
    if (mi_recinfo_write(file, &recinfo[i]))
668
801
      goto err;
669
802
 
 
803
#ifndef DBUG_OFF
 
804
  if ((uint) my_tell(file,MYF(0)) != info_length)
 
805
  {
 
806
    uint pos= (uint) my_tell(file,MYF(0));
 
807
    DBUG_PRINT("warning",("info_length: %d  != used_length: %d",
 
808
                          info_length, pos));
 
809
  }
 
810
#endif
 
811
 
670
812
        /* Enlarge files */
 
813
  DBUG_PRINT("info", ("enlarge to keystart: %lu", (ulong) share.base.keystart));
671
814
  if (ftruncate(file, (off_t) share.base.keystart))
672
815
    goto err;
673
816
 
685
828
  pthread_mutex_unlock(&THR_LOCK_myisam);
686
829
  if (my_close(file,MYF(0)))
687
830
    goto err;
688
 
  free((char*) rec_per_key_part);
689
 
  return(0);
 
831
  my_free((char*) rec_per_key_part,MYF(0));
 
832
  DBUG_RETURN(0);
690
833
 
691
834
err:
692
835
  pthread_mutex_unlock(&THR_LOCK_myisam);
693
836
  save_errno=my_errno;
694
837
  switch (errpos) {
695
838
  case 3:
696
 
    my_close(dfile,MYF(0));
 
839
    VOID(my_close(dfile,MYF(0)));
697
840
    /* fall through */
698
841
  case 2:
 
842
    /* QQ: T�nu should add a call to my_raid_delete() here */
699
843
  if (! (flags & HA_DONT_TOUCH_DATA))
700
844
    my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_DEXT,
701
845
                                     MY_UNPACK_FILENAME | MY_APPEND_EXT),
702
846
                           MYF(0));
703
847
    /* fall through */
704
848
  case 1:
705
 
    my_close(file,MYF(0));
 
849
    VOID(my_close(file,MYF(0)));
706
850
    if (! (flags & HA_DONT_TOUCH_DATA))
707
851
      my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_IEXT,
708
852
                                       MY_UNPACK_FILENAME | MY_APPEND_EXT),
709
853
                             MYF(0));
710
854
  }
711
 
  free((char*) rec_per_key_part);
712
 
  return(my_errno=save_errno);          /* return the fatal errno */
 
855
  my_free((char*) rec_per_key_part, MYF(0));
 
856
  DBUG_RETURN(my_errno=save_errno);             /* return the fatal errno */
713
857
}
714
858
 
715
859
 
716
 
uint32_t mi_get_pointer_length(uint64_t file_length, uint32_t def)
 
860
uint mi_get_pointer_length(ulonglong file_length, uint def)
717
861
{
718
 
  assert(def >= 2 && def <= 7);
 
862
  DBUG_ASSERT(def >= 2 && def <= 7);
719
863
  if (file_length)                              /* If not default */
720
864
  {
721
865
#ifdef NOT_YET_READY_FOR_8_BYTE_POINTERS
722
 
    if (file_length >= 1ULL << 56)
 
866
    if (file_length >= ULL(1) << 56)
723
867
      def=8;
724
868
    else
725
869
#endif
726
 
    if (file_length >= 1ULL << 48)
 
870
    if (file_length >= ULL(1) << 48)
727
871
      def=7;
728
 
    else if (file_length >= 1ULL << 40)
 
872
    else if (file_length >= ULL(1) << 40)
729
873
      def=6;
730
 
    else if (file_length >= 1ULL << 32)
 
874
    else if (file_length >= ULL(1) << 32)
731
875
      def=5;
732
 
    else if (file_length >= 1ULL << 24)
 
876
    else if (file_length >= ULL(1) << 24)
733
877
      def=4;
734
 
    else if (file_length >= 1ULL << 16)
 
878
    else if (file_length >= ULL(1) << 16)
735
879
      def=3;
736
880
    else
737
881
      def=2;