~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_create.c

  • Committer: Stewart Smith
  • Date: 2008-09-25 10:04:06 UTC
  • mto: This revision was merged to the branch mainline in revision 408.
  • Revision ID: stewart@flamingspork.com-20080925100406-hld92f4dr4nuar3a
Move compression functions (compress, uncompress and compressed_length) out into modules and fix test

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
  Old options is used when recreating database, from myisamchk
26
26
*/
27
27
 
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)
 
28
int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
 
29
              uint columns, MI_COLUMNDEF *recinfo,
 
30
              uint uniques, MI_UNIQUEDEF *uniquedefs,
 
31
              MI_CREATE_INFO *ci,uint flags)
32
32
{
33
 
  register uint32_t i, j;
 
33
  register uint i, j;
34
34
  File dfile= 0, file= 0;
35
35
  int errpos,save_errno, create_mode= O_RDWR | O_TRUNC;
36
36
  myf create_flag;
37
 
  uint32_t fields,length,max_key_length,packed,pointer,real_length_diff,
 
37
  uint fields,length,max_key_length,packed,pointer,real_length_diff,
38
38
       key_length,info_length,key_segs,options,min_key_length_skip,
39
39
       base_pos,long_varchar_count,varchar_length,
40
40
       max_key_block_length,unique_key_parts,fulltext_keys,offset;
41
 
  uint32_t aligned_key_start, block_length;
 
41
  uint aligned_key_start, block_length;
42
42
  ulong reclength, real_reclength,min_pack_length;
43
43
  char filename[FN_REFLEN],linkname[FN_REFLEN], *linkname_ptr;
44
44
  ulong pack_reclength;
354
354
    block_length= (keydef->block_length ? 
355
355
                   my_round_up_to_next_power(keydef->block_length) :
356
356
                   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);
 
357
    block_length= max(block_length, MI_MIN_KEY_BLOCK_LENGTH);
 
358
    block_length= min(block_length, MI_MAX_KEY_BLOCK_LENGTH);
359
359
 
360
360
    keydef->block_length= (uint16_t) MI_BLOCK_SIZE(length-real_length_diff,
361
361
                                                 pointer,MI_MAX_KEYPTR_SIZE,
443
443
    got from MYI file header (see also myisampack.c:save_state)
444
444
  */
445
445
  share.base.key_reflength=
446
 
    mi_get_pointer_length(cmax(ci->key_file_length,tmp),3);
 
446
    mi_get_pointer_length(max(ci->key_file_length,tmp),3);
447
447
  share.base.keys= share.state.header.keys= keys;
448
448
  share.state.header.uniques= uniques;
449
449
  share.state.header.fulltext_keys= fulltext_keys;
476
476
  share.base.min_block_length=
477
477
    (share.base.pack_reclength+3 < MI_EXTEND_BLOCK_LENGTH &&
478
478
     ! share.base.blobs) ?
479
 
    cmax(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
 
479
    max(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
480
480
    MI_EXTEND_BLOCK_LENGTH;
481
481
  if (! (flags & HA_DONT_TOUCH_DATA))
482
482
    share.state.create_time= (long) time((time_t*) 0);
603
603
  /* Write key and keyseg definitions */
604
604
  for (i=0 ; i < share.base.keys - uniques; i++)
605
605
  {
606
 
    uint32_t sp_segs= 0;
 
606
    uint sp_segs= 0;
607
607
 
608
608
    if (mi_keydef_write(file, &keydefs[i]))
609
609
      goto err;
684
684
  pthread_mutex_unlock(&THR_LOCK_myisam);
685
685
  if (my_close(file,MYF(0)))
686
686
    goto err;
687
 
  free((char*) rec_per_key_part);
 
687
  my_free((char*) rec_per_key_part,MYF(0));
688
688
  return(0);
689
689
 
690
690
err:
692
692
  save_errno=my_errno;
693
693
  switch (errpos) {
694
694
  case 3:
695
 
    my_close(dfile,MYF(0));
 
695
    VOID(my_close(dfile,MYF(0)));
696
696
    /* fall through */
697
697
  case 2:
698
698
    /* QQ: T�nu should add a call to my_raid_delete() here */
702
702
                           MYF(0));
703
703
    /* fall through */
704
704
  case 1:
705
 
    my_close(file,MYF(0));
 
705
    VOID(my_close(file,MYF(0)));
706
706
    if (! (flags & HA_DONT_TOUCH_DATA))
707
707
      my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_IEXT,
708
708
                                       MY_UNPACK_FILENAME | MY_APPEND_EXT),
709
709
                             MYF(0));
710
710
  }
711
 
  free((char*) rec_per_key_part);
 
711
  my_free((char*) rec_per_key_part, MYF(0));
712
712
  return(my_errno=save_errno);          /* return the fatal errno */
713
713
}
714
714
 
715
715
 
716
 
uint32_t mi_get_pointer_length(uint64_t file_length, uint32_t def)
 
716
uint mi_get_pointer_length(uint64_t file_length, uint def)
717
717
{
718
718
  assert(def >= 2 && def <= 7);
719
719
  if (file_length)                              /* If not default */