~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_create.c

  • Committer: Jay Pipes
  • Date: 2008-07-17 19:43:08 UTC
  • mto: This revision was merged to the branch mainline in revision 182.
  • Revision ID: jay@mysql.com-20080717194308-l9i4ti57gikm2qbv
Phase 1 removal of DBUG in mysys

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
/* Create a MyISAM table */
17
17
 
18
18
#include "myisamdef.h"
19
 
#include <mysys/my_tree.h>
20
 
#include <mysys/queues.h>
21
 
#include <mysys/my_bit.h>
 
19
#include <m_ctype.h>
 
20
#include <my_tree.h>
 
21
#include <queues.h>
 
22
#include <mysql/plugin.h>
 
23
#include <my_bit.h>
22
24
 
 
25
#include <m_ctype.h>
23
26
 
24
27
/*
25
28
  Old options is used when recreating database, from myisamchk
26
29
*/
27
30
 
28
 
int mi_create(const char *name,uint32_t keys,MI_KEYDEF *keydefs,
29
 
              uint32_t columns, MI_COLUMNDEF *recinfo,
30
 
              uint32_t uniques, MI_UNIQUEDEF *uniquedefs,
31
 
              MI_CREATE_INFO *ci,uint32_t flags)
 
31
int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
 
32
              uint columns, MI_COLUMNDEF *recinfo,
 
33
              uint uniques, MI_UNIQUEDEF *uniquedefs,
 
34
              MI_CREATE_INFO *ci,uint flags)
32
35
{
33
 
  register uint32_t i, j;
34
 
  File dfile= 0, file= 0;
 
36
  register uint i, j;
 
37
  File dfile= 0, file;
35
38
  int errpos,save_errno, create_mode= O_RDWR | O_TRUNC;
36
39
  myf create_flag;
37
 
  uint32_t fields,length,max_key_length,packed,pointer,real_length_diff,
 
40
  uint fields,length,max_key_length,packed,pointer,real_length_diff,
38
41
       key_length,info_length,key_segs,options,min_key_length_skip,
39
42
       base_pos,long_varchar_count,varchar_length,
40
43
       max_key_block_length,unique_key_parts,fulltext_keys,offset;
41
 
  uint32_t aligned_key_start, block_length;
 
44
  uint aligned_key_start, block_length;
42
45
  ulong reclength, real_reclength,min_pack_length;
43
46
  char filename[FN_REFLEN],linkname[FN_REFLEN], *linkname_ptr;
44
47
  ulong pack_reclength;
55
58
 
56
59
  if (!ci)
57
60
  {
58
 
    memset(&tmp_create_info, 0, sizeof(tmp_create_info));
 
61
    bzero((char*) &tmp_create_info,sizeof(tmp_create_info));
59
62
    ci=&tmp_create_info;
60
63
  }
61
64
 
65
68
  }
66
69
  errpos= 0;
67
70
  options= 0;
68
 
  memset(&share, 0, sizeof(share));
 
71
  bzero((uchar*) &share,sizeof(share));
69
72
 
70
73
  if (flags & HA_DONT_TOUCH_DATA)
71
74
  {
354
357
    block_length= (keydef->block_length ? 
355
358
                   my_round_up_to_next_power(keydef->block_length) :
356
359
                   myisam_block_size);
357
 
    block_length= cmax(block_length, MI_MIN_KEY_BLOCK_LENGTH);
358
 
    block_length= cmin(block_length, MI_MAX_KEY_BLOCK_LENGTH);
 
360
    block_length= max(block_length, MI_MIN_KEY_BLOCK_LENGTH);
 
361
    block_length= min(block_length, MI_MAX_KEY_BLOCK_LENGTH);
359
362
 
360
 
    keydef->block_length= (uint16_t) MI_BLOCK_SIZE(length-real_length_diff,
 
363
    keydef->block_length= (uint16) MI_BLOCK_SIZE(length-real_length_diff,
361
364
                                                 pointer,MI_MAX_KEYPTR_SIZE,
362
365
                                                 block_length);
363
366
    if (keydef->block_length > MI_MAX_KEY_BLOCK_LENGTH ||
367
370
      goto err;
368
371
    }
369
372
    set_if_bigger(max_key_block_length,keydef->block_length);
370
 
    keydef->keylength= (uint16_t) key_length;
371
 
    keydef->minlength= (uint16_t) (length-min_key_length_skip);
372
 
    keydef->maxlength= (uint16_t) length;
 
373
    keydef->keylength= (uint16) key_length;
 
374
    keydef->minlength= (uint16) (length-min_key_length_skip);
 
375
    keydef->maxlength= (uint16) length;
373
376
 
374
377
    if (length > max_key_length)
375
378
      max_key_length= length;
413
416
    goto err;
414
417
  }
415
418
 
416
 
  memcpy(share.state.header.file_version,myisam_file_magic,4);
 
419
  bmove(share.state.header.file_version,(uchar*) myisam_file_magic,4);
417
420
  ci->old_options=options| (ci->old_options & HA_OPTION_TEMP_COMPRESS_RECORD ?
418
421
                        HA_OPTION_COMPRESS_RECORD |
419
422
                        HA_OPTION_TEMP_COMPRESS_RECORD: 0);
431
434
  share.state.unique=   (ulong) 0;
432
435
  share.state.update_count=(ulong) 0;
433
436
  share.state.version=  (ulong) time((time_t*) 0);
434
 
  share.state.sortkey=  UINT16_MAX;
 
437
  share.state.sortkey=  (ushort) ~0;
435
438
  share.state.auto_increment=ci->auto_increment;
436
439
  share.options=options;
437
440
  share.base.rec_reflength=pointer;
443
446
    got from MYI file header (see also myisampack.c:save_state)
444
447
  */
445
448
  share.base.key_reflength=
446
 
    mi_get_pointer_length(cmax(ci->key_file_length,tmp),3);
 
449
    mi_get_pointer_length(max(ci->key_file_length,tmp),3);
447
450
  share.base.keys= share.state.header.keys= keys;
448
451
  share.state.header.uniques= uniques;
449
452
  share.state.header.fulltext_keys= fulltext_keys;
476
479
  share.base.min_block_length=
477
480
    (share.base.pack_reclength+3 < MI_EXTEND_BLOCK_LENGTH &&
478
481
     ! share.base.blobs) ?
479
 
    cmax(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
 
482
    max(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
480
483
    MI_EXTEND_BLOCK_LENGTH;
481
484
  if (! (flags & HA_DONT_TOUCH_DATA))
482
485
    share.state.create_time= (long) time((time_t*) 0);
603
606
  /* Write key and keyseg definitions */
604
607
  for (i=0 ; i < share.base.keys - uniques; i++)
605
608
  {
606
 
    uint32_t sp_segs= 0;
 
609
    uint sp_segs= 0;
607
610
 
608
611
    if (mi_keydef_write(file, &keydefs[i]))
609
612
      goto err;
613
616
  }
614
617
  /* Create extra keys for unique definitions */
615
618
  offset=reclength-uniques*MI_UNIQUE_HASH_LENGTH;
616
 
  memset(&tmp_keydef, 0, sizeof(tmp_keydef));
617
 
  memset(&tmp_keyseg, 0, sizeof(tmp_keyseg));
 
619
  bzero((char*) &tmp_keydef,sizeof(tmp_keydef));
 
620
  bzero((char*) &tmp_keyseg,sizeof(tmp_keyseg));
618
621
  for (i=0; i < uniques ; i++)
619
622
  {
620
623
    tmp_keydef.keysegs=1;
621
624
    tmp_keydef.flag=            HA_UNIQUE_CHECK;
622
 
    tmp_keydef.block_length=    (uint16_t)myisam_block_size;
 
625
    tmp_keydef.block_length=    (uint16)myisam_block_size;
623
626
    tmp_keydef.keylength=       MI_UNIQUE_HASH_LENGTH + pointer;
624
627
    tmp_keydef.minlength=tmp_keydef.maxlength=tmp_keydef.keylength;
625
628
    tmp_keyseg.type=            MI_UNIQUE_HASH_TYPE;
684
687
  pthread_mutex_unlock(&THR_LOCK_myisam);
685
688
  if (my_close(file,MYF(0)))
686
689
    goto err;
687
 
  free((char*) rec_per_key_part);
 
690
  my_free((char*) rec_per_key_part,MYF(0));
688
691
  return(0);
689
692
 
690
693
err:
692
695
  save_errno=my_errno;
693
696
  switch (errpos) {
694
697
  case 3:
695
 
    my_close(dfile,MYF(0));
 
698
    VOID(my_close(dfile,MYF(0)));
696
699
    /* fall through */
697
700
  case 2:
698
701
    /* QQ: T�nu should add a call to my_raid_delete() here */
702
705
                           MYF(0));
703
706
    /* fall through */
704
707
  case 1:
705
 
    my_close(file,MYF(0));
 
708
    VOID(my_close(file,MYF(0)));
706
709
    if (! (flags & HA_DONT_TOUCH_DATA))
707
710
      my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_IEXT,
708
711
                                       MY_UNPACK_FILENAME | MY_APPEND_EXT),
709
712
                             MYF(0));
710
713
  }
711
 
  free((char*) rec_per_key_part);
 
714
  my_free((char*) rec_per_key_part, MYF(0));
712
715
  return(my_errno=save_errno);          /* return the fatal errno */
713
716
}
714
717
 
715
718
 
716
 
uint32_t mi_get_pointer_length(uint64_t file_length, uint32_t def)
 
719
uint mi_get_pointer_length(uint64_t file_length, uint def)
717
720
{
718
721
  assert(def >= 2 && def <= 7);
719
722
  if (file_length)                              /* If not default */