394
enum row_type ha_heap::get_row_type() const
396
if (file->s->recordspace.is_variable_size)
397
return ROW_TYPE_DYNAMIC;
399
return ROW_TYPE_FIXED;
394
402
int ha_heap::extra(enum ha_extra_function operation)
396
404
return heap_extra(file,operation);
592
600
int ha_heap::create(const char *name, TABLE *table_arg,
593
601
HA_CREATE_INFO *create_info)
595
uint key, parts, mem_per_row= 0, keys= table_arg->s->keys;
603
uint key, parts, mem_per_row_keys= 0, keys= table_arg->s->keys;
596
604
uint auto_key= 0, auto_key_type= 0;
605
uint max_key_fieldnr = 0, key_part_size = 0, next_field_pos = 0;
606
uint column_idx, column_count= table_arg->s->fields;
607
HP_COLUMNDEF *columndef;
598
608
HP_KEYDEF *keydef;
610
char buff[FN_REFLEN];
601
612
TABLE_SHARE *share= table_arg->s;
602
613
bool found_real_auto_increment= 0;
615
if (!(columndef= (HP_COLUMNDEF*) my_malloc(column_count * sizeof(HP_COLUMNDEF), MYF(MY_WME))))
618
for (column_idx= 0; column_idx < column_count; column_idx++)
620
Field* field= *(table_arg->field + column_idx);
621
HP_COLUMNDEF* column= columndef + column_idx;
622
column->type= (uint16_t)field->type();
623
column->length= field->pack_length();
624
column->offset= field->offset(field->table->record[0]);
628
column->null_bit= field->null_bit;
629
column->null_pos= (uint) (field->null_ptr - (uchar*) table_arg->record[0]);
637
if (field->type() == DRIZZLE_TYPE_VARCHAR)
639
column->length_bytes= (uint8_t)(((Field_varstring*)field)->length_bytes);
643
column->length_bytes= 0;
604
647
for (key= parts= 0; key < keys; key++)
605
648
parts+= table_arg->key_info[key].key_parts;
607
650
if (!(keydef= (HP_KEYDEF*) my_malloc(keys * sizeof(HP_KEYDEF) +
608
651
parts * sizeof(HA_KEYSEG),
654
my_free((void *) columndef, MYF(0));
611
658
seg= my_reinterpret_cast(HA_KEYSEG*) (keydef + keys);
612
659
for (key= 0; key < keys; key++)
623
670
case HA_KEY_ALG_UNDEF:
624
671
case HA_KEY_ALG_HASH:
625
672
keydef[key].algorithm= HA_KEY_ALG_HASH;
626
mem_per_row+= sizeof(char*) * 2; // = sizeof(HASH_INFO)
673
mem_per_row_keys+= sizeof(char*) * 2; // = sizeof(HASH_INFO)
628
675
case HA_KEY_ALG_BTREE:
629
676
keydef[key].algorithm= HA_KEY_ALG_BTREE;
630
mem_per_row+=sizeof(TREE_ELEMENT)+pos->key_length+sizeof(char*);
677
mem_per_row_keys+=sizeof(TREE_ELEMENT)+pos->key_length+sizeof(char*);
633
680
assert(0); // cannot happen
652
699
seg->length= (uint) key_part->length;
653
700
seg->flag= key_part->key_part_flag;
702
next_field_pos= seg->start + seg->length;
703
if (field->type() == DRIZZLE_TYPE_VARCHAR)
705
next_field_pos+= (uint8_t)(((Field_varstring*)field)->length_bytes);
708
if (next_field_pos > key_part_size) {
709
key_part_size= next_field_pos;
655
712
if (field->flags & (ENUM_FLAG | SET_FLAG))
656
713
seg->charset= &my_charset_bin;
677
734
auto_key= key+ 1;
678
735
auto_key_type= field->key_type();
737
if ((uint)field->field_index + 1 > max_key_fieldnr)
739
/* Do not use seg->fieldnr as it's not reliable in case of temp tables */
740
max_key_fieldnr= field->field_index + 1;
682
mem_per_row+= MY_ALIGN(share->reclength + 1, sizeof(char*));
683
max_rows = (ha_rows) (table_arg->in_use->variables.max_heap_table_size /
684
(uint64_t) mem_per_row);
745
if (key_part_size < share->null_bytes + ((share->last_null_bit_pos+7) >> 3))
747
/* Make sure to include null fields regardless of the presense of keys */
748
key_part_size = share->null_bytes + ((share->last_null_bit_pos+7) >> 3);
685
753
if (table_arg->found_next_number_field)
687
755
keydef[share->next_number_index].flag|= HA_AUTO_KEY;
695
763
hp_create_info.max_table_size=current_thd->variables.max_heap_table_size;
696
764
hp_create_info.with_auto_increment= found_real_auto_increment;
697
765
hp_create_info.internal_table= internal_table;
698
max_rows = (ha_rows) (hp_create_info.max_table_size / mem_per_row);
699
error= heap_create(name,
700
keys, keydef, share->reclength,
701
(ulong) ((share->max_rows < max_rows &&
703
share->max_rows : max_rows),
704
(ulong) share->min_rows, &hp_create_info, &internal_share);
766
hp_create_info.max_chunk_size= share->block_size;
767
hp_create_info.is_dynamic= (share->row_type == ROW_TYPE_DYNAMIC);
768
error= heap_create(fn_format(buff,name,"","",
769
MY_REPLACE_EXT|MY_UNPACK_FILENAME),
771
column_count, columndef,
772
max_key_fieldnr, key_part_size,
773
share->reclength, mem_per_row_keys,
774
(ulong) share->max_rows, (ulong) share->min_rows,
775
&hp_create_info, &internal_share);
705
777
my_free((uchar*) keydef, MYF(0));
778
my_free((void *) columndef, MYF(0));
706
779
assert(file == 0);
713
786
table->file->info(HA_STATUS_AUTO);
714
787
if (!(create_info->used_fields & HA_CREATE_USED_AUTO))
715
788
create_info->auto_increment_value= stats.auto_increment_value;
789
if (!(create_info->used_fields & HA_CREATE_USED_BLOCK_SIZE))
791
if (file->s->recordspace.is_variable_size)
792
create_info->block_size= file->s->recordspace.chunk_length;
794
create_info->block_size= 0;
718
798
void ha_heap::get_auto_increment(uint64_t offset __attribute__((unused)),