16
16
/* Create a MyISAM table */
18
18
#include "myisamdef.h"
19
#include <mysys/my_tree.h>
20
#include <mysys/queues.h>
21
#include <mysys/my_bit.h>
22
#include <mysql/plugin.h>
25
28
Old options is used when recreating database, from myisamchk
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)
33
register uint32_t i, j;
34
File dfile= 0, file= 0;
35
38
int errpos,save_errno, create_mode= O_RDWR | O_TRUNC;
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;
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);
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,
363
366
if (keydef->block_length > MI_MAX_KEY_BLOCK_LENGTH ||
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;
374
377
if (length > max_key_length)
375
378
max_key_length= length;
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)
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);
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++)
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;
703
706
/* fall through */
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),
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 */
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)
718
721
assert(def >= 2 && def <= 7);
719
722
if (file_length) /* If not default */