~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_create.c

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
Remove uint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#include "myisamdef.h"
19
19
#include <mysys/my_tree.h>
 
20
#include <mysys/queues.h>
20
21
#include <mysys/my_bit.h>
21
22
 
22
 
#include <drizzled/util/test.h>
23
 
 
24
 
#include <algorithm>
25
 
 
26
 
using namespace std;
27
23
 
28
24
/*
29
25
  Old options is used when recreating database, from myisamchk
76
72
    if (!(ci->old_options & HA_OPTION_TEMP_COMPRESS_RECORD))
77
73
      options=ci->old_options &
78
74
        (HA_OPTION_COMPRESS_RECORD | HA_OPTION_PACK_RECORD |
79
 
         HA_OPTION_READ_ONLY_DATA |
80
 
         HA_OPTION_TMP_TABLE );
 
75
         HA_OPTION_READ_ONLY_DATA | HA_OPTION_CHECKSUM |
 
76
         HA_OPTION_TMP_TABLE | HA_OPTION_DELAY_KEY_WRITE);
81
77
    else
82
78
      options=ci->old_options &
83
 
        (HA_OPTION_TMP_TABLE );
 
79
        (HA_OPTION_CHECKSUM | HA_OPTION_TMP_TABLE | HA_OPTION_DELAY_KEY_WRITE);
84
80
  }
85
81
 
86
82
  if (ci->reloc_rows > ci->max_rows)
87
83
    ci->reloc_rows=ci->max_rows;                /* Check if wrong parameter */
88
84
 
89
85
  if (!(rec_per_key_part=
90
 
        (ulong*) malloc((keys + uniques)*MI_MAX_KEY_SEG*sizeof(long))))
 
86
        (ulong*) my_malloc((keys + uniques)*MI_MAX_KEY_SEG*sizeof(long),
 
87
                           MYF(MY_WME | MY_ZEROFILL))))
91
88
    return(my_errno);
92
 
  memset(rec_per_key_part, 0, (keys + uniques)*MI_MAX_KEY_SEG*sizeof(long));
93
89
 
94
90
        /* Start by checking fields and field-types used */
95
91
 
165
161
 
166
162
  if (packed || (flags & HA_PACK_RECORD))
167
163
    options|=HA_OPTION_PACK_RECORD;     /* Must use packed records */
 
164
  /* We can't use checksum with static length rows */
 
165
  if (!(options & HA_OPTION_PACK_RECORD))
 
166
    options&= ~HA_OPTION_CHECKSUM;
168
167
  if (!(options & (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)))
169
168
    min_pack_length+= varchar_length;
170
169
  if (flags & HA_CREATE_TMP_TABLE)
171
170
  {
172
171
    options|= HA_OPTION_TMP_TABLE;
173
 
    create_mode|= O_EXCL;
174
 
  }
 
172
    create_mode|= O_EXCL | O_NOFOLLOW;
 
173
  }
 
174
  if (flags & HA_CREATE_CHECKSUM || (options & HA_OPTION_CHECKSUM))
 
175
  {
 
176
    options|= HA_OPTION_CHECKSUM;
 
177
    min_pack_length++;
 
178
  }
 
179
  if (flags & HA_CREATE_DELAY_KEY_WRITE)
 
180
    options|= HA_OPTION_DELAY_KEY_WRITE;
 
181
  if (flags & HA_CREATE_RELIES_ON_SQL_LAYER)
 
182
    options|= HA_OPTION_RELIES_ON_SQL_LAYER;
175
183
 
176
184
  packed=(packed+7)/8;
177
185
  if (pack_reclength != INT32_MAX)
178
186
    pack_reclength+= reclength+packed +
179
 
      test(test_all_bits(options,
180
 
                         uint32_t(HA_PACK_RECORD)));
 
187
      test(test_all_bits(options, HA_OPTION_CHECKSUM | HA_PACK_RECORD));
181
188
  min_pack_length+=packed;
182
189
 
183
190
  if (!ci->data_file_length && ci->max_rows)
194
201
                                          3 : 0)));
195
202
 
196
203
  if (options & (HA_OPTION_COMPRESS_RECORD | HA_OPTION_PACK_RECORD))
197
 
    pointer=mi_get_pointer_length(ci->data_file_length, data_pointer_size);
 
204
    pointer=mi_get_pointer_length(ci->data_file_length,myisam_data_pointer_size);
198
205
  else
199
 
    pointer=mi_get_pointer_length(ci->max_rows, data_pointer_size);
 
206
    pointer=mi_get_pointer_length(ci->max_rows,myisam_data_pointer_size);
200
207
  if (!(max_rows=(uint64_t) ci->max_rows))
201
208
    max_rows= ((((uint64_t) 1 << (pointer*8)) -1) / min_pack_length);
202
209
 
344
351
      share.state.rec_per_key_part[key_segs-1]=1L;
345
352
    length+=key_length;
346
353
    /* Get block length for key, if defined by user */
347
 
    block_length= (keydef->block_length ?
 
354
    block_length= (keydef->block_length ? 
348
355
                   my_round_up_to_next_power(keydef->block_length) :
349
356
                   myisam_block_size);
350
 
    block_length= max(block_length, (uint32_t)MI_MIN_KEY_BLOCK_LENGTH);
351
 
    block_length= min(block_length, (uint32_t)MI_MAX_KEY_BLOCK_LENGTH);
 
357
    block_length= cmax(block_length, MI_MIN_KEY_BLOCK_LENGTH);
 
358
    block_length= cmin(block_length, MI_MAX_KEY_BLOCK_LENGTH);
352
359
 
353
360
    keydef->block_length= (uint16_t) MI_BLOCK_SIZE(length-real_length_diff,
354
361
                                                 pointer,MI_MAX_KEYPTR_SIZE,
359
366
      my_errno=HA_WRONG_CREATE_OPTION;
360
367
      goto err;
361
368
    }
362
 
    set_if_bigger(max_key_block_length,(uint32_t)keydef->block_length);
 
369
    set_if_bigger(max_key_block_length,keydef->block_length);
363
370
    keydef->keylength= (uint16_t) key_length;
364
371
    keydef->minlength= (uint16_t) (length-min_key_length_skip);
365
372
    keydef->maxlength= (uint16_t) length;
406
413
    goto err;
407
414
  }
408
415
 
409
 
  memmove(share.state.header.file_version,myisam_file_magic,4);
 
416
  memcpy(share.state.header.file_version,myisam_file_magic,4);
410
417
  ci->old_options=options| (ci->old_options & HA_OPTION_TEMP_COMPRESS_RECORD ?
411
418
                        HA_OPTION_COMPRESS_RECORD |
412
419
                        HA_OPTION_TEMP_COMPRESS_RECORD: 0);
436
443
    got from MYI file header (see also myisampack.c:save_state)
437
444
  */
438
445
  share.base.key_reflength=
439
 
    mi_get_pointer_length(max(ci->key_file_length,tmp),3);
 
446
    mi_get_pointer_length(cmax(ci->key_file_length,tmp),3);
440
447
  share.base.keys= share.state.header.keys= keys;
441
448
  share.state.header.uniques= uniques;
442
449
  share.state.header.fulltext_keys= fulltext_keys;
455
462
  share.base.records=ci->max_rows;
456
463
  share.base.reloc=  ci->reloc_rows;
457
464
  share.base.reclength=real_reclength;
458
 
  share.base.pack_reclength=reclength;
 
465
  share.base.pack_reclength=reclength+ test(options & HA_OPTION_CHECKSUM);
459
466
  share.base.max_pack_length=pack_reclength;
460
467
  share.base.min_pack_length=min_pack_length;
461
468
  share.base.pack_bits=packed;
469
476
  share.base.min_block_length=
470
477
    (share.base.pack_reclength+3 < MI_EXTEND_BLOCK_LENGTH &&
471
478
     ! share.base.blobs) ?
472
 
    max(share.base.pack_reclength,(ulong)MI_MIN_BLOCK_LENGTH) :
 
479
    cmax(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
473
480
    MI_EXTEND_BLOCK_LENGTH;
474
481
  if (! (flags & HA_DONT_TOUCH_DATA))
475
482
    share.state.create_time= (long) time((time_t*) 0);
482
489
  */
483
490
  if (ci->index_file_name)
484
491
  {
485
 
    char *iext= strrchr((char *)ci->index_file_name, '.');
 
492
    char *iext= strrchr(ci->index_file_name, '.');
486
493
    int have_iext= iext && !strcmp(iext, MI_NAME_IEXT);
487
494
    if (options & HA_OPTION_TMP_TABLE)
488
495
    {
489
496
      char *path;
490
497
      /* chop off the table name, tempory tables use generated name */
491
 
      if ((path= strrchr((char *)ci->index_file_name, FN_LIBCHAR)))
 
498
      if ((path= strrchr(ci->index_file_name, FN_LIBCHAR)))
492
499
        *path= '\0';
493
500
      fn_format(filename, name, ci->index_file_name, MI_NAME_IEXT,
494
501
                MY_REPLACE_DIR | MY_UNPACK_FILENAME |
511
518
  }
512
519
  else
513
520
  {
514
 
    char *iext= strrchr((char *)name, '.');
 
521
    char *iext= strrchr(name, '.');
515
522
    int have_iext= iext && !strcmp(iext, MI_NAME_IEXT);
516
523
    fn_format(filename, name, "", MI_NAME_IEXT,
517
524
              MY_UNPACK_FILENAME | MY_RETURN_REAL_PATH |
550
557
    {
551
558
      if (ci->data_file_name)
552
559
      {
553
 
        char *dext= strrchr((char *)ci->data_file_name, '.');
 
560
        char *dext= strrchr(ci->data_file_name, '.');
554
561
        int have_dext= dext && !strcmp(dext, MI_NAME_DEXT);
555
562
 
556
563
        if (options & HA_OPTION_TMP_TABLE)
557
564
        {
558
565
          char *path;
559
566
          /* chop off the table name, tempory tables use generated name */
560
 
          if ((path= strrchr((char *)ci->data_file_name, FN_LIBCHAR)))
 
567
          if ((path= strrchr(ci->data_file_name, FN_LIBCHAR)))
561
568
            *path= '\0';
562
569
          fn_format(filename, name, ci->data_file_name, MI_NAME_DEXT,
563
570
                    MY_REPLACE_DIR | MY_UNPACK_FILENAME | MY_APPEND_EXT);
688
695
    my_close(dfile,MYF(0));
689
696
    /* fall through */
690
697
  case 2:
 
698
    /* QQ: T�nu should add a call to my_raid_delete() here */
691
699
  if (! (flags & HA_DONT_TOUCH_DATA))
692
700
    my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_DEXT,
693
701
                                     MY_UNPACK_FILENAME | MY_APPEND_EXT),