97
126
TableShare *alloc_table_share(TableList *table_list, char *key,
98
127
uint32_t key_length)
100
memory::Root mem_root;
101
130
TableShare *share;
102
131
char *key_buff, *path_buff;
105
build_table_filename(path, table_list->db, table_list->table_name, false);
107
memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
132
char path[FN_REFLEN];
133
uint32_t path_length;
135
path_length= build_table_filename(path, sizeof(path) - 1,
137
table_list->table_name, false);
138
init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
108
139
if (multi_alloc_root(&mem_root,
109
140
&share, sizeof(*share),
110
141
&key_buff, key_length,
111
&path_buff, path.length() + 1,
142
&path_buff, path_length + 1,
114
145
memset(share, 0, sizeof(*share));
116
147
share->set_table_cache_key(key_buff, key, key_length);
118
share->path.str= path_buff,
119
share->path.length= path.length();
120
strcpy(share->path.str, path.c_str());
149
share->path.str= path_buff;
150
share->path.length= path_length;
151
strcpy(share->path.str, path);
121
152
share->normalized_path.str= share->path.str;
122
share->normalized_path.length= path.length();
153
share->normalized_path.length= path_length;
124
155
share->version= refresh_version;
138
169
switch(proto_field_type)
140
case message::Table::Field::INTEGER:
171
case drizzled::message::Table::Field::TINYINT:
172
field_type= DRIZZLE_TYPE_TINY;
174
case drizzled::message::Table::Field::INTEGER:
141
175
field_type= DRIZZLE_TYPE_LONG;
143
case message::Table::Field::DOUBLE:
177
case drizzled::message::Table::Field::DOUBLE:
144
178
field_type= DRIZZLE_TYPE_DOUBLE;
146
case message::Table::Field::TIMESTAMP:
180
case drizzled::message::Table::Field::TIMESTAMP:
147
181
field_type= DRIZZLE_TYPE_TIMESTAMP;
149
case message::Table::Field::BIGINT:
183
case drizzled::message::Table::Field::BIGINT:
150
184
field_type= DRIZZLE_TYPE_LONGLONG;
152
case message::Table::Field::DATETIME:
186
case drizzled::message::Table::Field::DATETIME:
153
187
field_type= DRIZZLE_TYPE_DATETIME;
155
case message::Table::Field::DATE:
189
case drizzled::message::Table::Field::DATE:
156
190
field_type= DRIZZLE_TYPE_DATE;
158
case message::Table::Field::VARCHAR:
192
case drizzled::message::Table::Field::VARCHAR:
159
193
field_type= DRIZZLE_TYPE_VARCHAR;
161
case message::Table::Field::DECIMAL:
162
field_type= DRIZZLE_TYPE_DECIMAL;
195
case drizzled::message::Table::Field::DECIMAL:
196
field_type= DRIZZLE_TYPE_NEWDECIMAL;
164
case message::Table::Field::ENUM:
198
case drizzled::message::Table::Field::ENUM:
165
199
field_type= DRIZZLE_TYPE_ENUM;
167
case message::Table::Field::BLOB:
201
case drizzled::message::Table::Field::BLOB:
168
202
field_type= DRIZZLE_TYPE_BLOB;
171
field_type= DRIZZLE_TYPE_LONG; /* Set value to kill GCC warning */
205
field_type= DRIZZLE_TYPE_TINY; /* Set value to kill GCC warning */
353
414
if (indx.has_options())
355
message::Table::Index::IndexOptions indx_options= indx.options();
416
drizzled::message::Table::Index::IndexOptions indx_options= indx.options();
356
417
if (indx_options.pack_key())
357
keyinfo->flags|= HA_PACK_KEY;
418
keyinfo->flags|= HA_PACK_KEY;
359
420
if (indx_options.var_length_key())
360
keyinfo->flags|= HA_VAR_LENGTH_PART;
421
keyinfo->flags|= HA_VAR_LENGTH_PART;
362
423
if (indx_options.null_part_key())
363
keyinfo->flags|= HA_NULL_PART_KEY;
424
keyinfo->flags|= HA_NULL_PART_KEY;
365
426
if (indx_options.binary_pack_key())
366
keyinfo->flags|= HA_BINARY_PACK_KEY;
427
keyinfo->flags|= HA_BINARY_PACK_KEY;
368
429
if (indx_options.has_partial_segments())
369
keyinfo->flags|= HA_KEY_HAS_PART_KEY_SEG;
430
keyinfo->flags|= HA_KEY_HAS_PART_KEY_SEG;
371
432
if (indx_options.auto_generated_key())
372
keyinfo->flags|= HA_GENERATED_KEY;
433
keyinfo->flags|= HA_GENERATED_KEY;
374
435
if (indx_options.has_key_block_size())
376
keyinfo->flags|= HA_USES_BLOCK_SIZE;
377
keyinfo->block_size= indx_options.key_block_size();
437
keyinfo->flags|= HA_USES_BLOCK_SIZE;
438
keyinfo->block_size= indx_options.key_block_size();
381
keyinfo->block_size= 0;
442
keyinfo->block_size= 0;
387
case message::Table::Index::UNKNOWN_INDEX:
449
case drizzled::message::Table::Index::UNKNOWN_INDEX:
388
450
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
390
case message::Table::Index::BTREE:
452
case drizzled::message::Table::Index::BTREE:
391
453
keyinfo->algorithm= HA_KEY_ALG_BTREE;
393
case message::Table::Index::HASH:
455
case drizzled::message::Table::Index::RTREE:
456
keyinfo->algorithm= HA_KEY_ALG_RTREE;
458
case drizzled::message::Table::Index::HASH:
394
459
keyinfo->algorithm= HA_KEY_ALG_HASH;
461
case drizzled::message::Table::Index::FULLTEXT:
462
keyinfo->algorithm= HA_KEY_ALG_FULLTEXT;
398
465
/* TODO: suitable warning ? */
498
587
case DRIZZLE_TYPE_BLOB:
499
588
case DRIZZLE_TYPE_VARCHAR:
501
message::Table::Field::StringFieldOptions field_options= pfield.string_options();
503
const CHARSET_INFO *cs= get_charset(field_options.has_collation_id() ?
504
field_options.collation_id() : 0);
507
cs= default_charset_info;
509
field_pack_length[fieldnr]= calc_pack_length(drizzle_field_type,
510
field_options.length() * cs->mbmaxlen);
590
drizzled::message::Table::Field::StringFieldOptions field_options=
591
pfield.string_options();
593
const CHARSET_INFO *cs= get_charset(field_options.has_collation_id()?
594
field_options.collation_id() : 0);
597
cs= default_charset_info;
599
field_pack_length[fieldnr]=
600
calc_pack_length(drizzle_field_type,
601
field_options.length() * cs->mbmaxlen);
513
605
case DRIZZLE_TYPE_ENUM:
515
message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
517
field_pack_length[fieldnr]=
518
get_enum_pack_length(field_options.field_value_size());
521
interval_parts+= field_options.field_value_size();
607
drizzled::message::Table::Field::SetFieldOptions field_options=
608
pfield.set_options();
610
field_pack_length[fieldnr]=
611
get_enum_pack_length(field_options.field_value_size());
614
interval_parts+= field_options.field_value_size();
524
case DRIZZLE_TYPE_DECIMAL:
617
case DRIZZLE_TYPE_NEWDECIMAL:
526
message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
619
drizzled::message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
528
field_pack_length[fieldnr]= my_decimal_get_binary_size(fo.precision(), fo.scale());
621
field_pack_length[fieldnr]=
622
my_decimal_get_binary_size(fo.precision(), fo.scale());
602
697
for (unsigned int fieldnr= 0; fieldnr < share->fields; fieldnr++)
604
message::Table::Field pfield= table.field(fieldnr);
699
drizzled::message::Table::Field pfield= table.field(fieldnr);
606
701
/* field names */
607
702
share->fieldnames.type_names[fieldnr]= strmake_root(&share->mem_root,
608
pfield.name().c_str(),
609
pfield.name().length());
703
pfield.name().c_str(),
704
pfield.name().length());
611
706
share->fieldnames.type_lengths[fieldnr]= pfield.name().length();
613
708
/* enum typelibs */
614
if (pfield.type() != message::Table::Field::ENUM)
709
if (pfield.type() != drizzled::message::Table::Field::ENUM)
617
message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
619
const CHARSET_INFO *charset= get_charset(field_options.has_collation_id() ?
620
field_options.collation_id() : 0);
712
drizzled::message::Table::Field::SetFieldOptions field_options=
713
pfield.set_options();
715
const CHARSET_INFO *charset= get_charset(field_options.has_collation_id()?
716
field_options.collation_id() : 0);
623
719
charset= default_charset_info;
625
721
TYPELIB *t= &(share->intervals[interval_nr]);
627
723
t->type_names= (const char**)alloc_root(&share->mem_root,
628
(field_options.field_value_size() + 1) * sizeof(char*));
724
(field_options.field_value_size()+1)*sizeof(char*));
630
726
t->type_lengths= (unsigned int*) alloc_root(&share->mem_root,
631
(field_options.field_value_size() + 1) * sizeof(unsigned int));
727
(field_options.field_value_size()+1)*sizeof(unsigned int));
633
729
t->type_names[field_options.field_value_size()]= NULL;
634
730
t->type_lengths[field_options.field_value_size()]= 0;
698
788
Field::utype unireg_type= Field::NONE;
700
if (pfield.has_numeric_options() &&
701
pfield.numeric_options().is_autoincrement())
790
if (pfield.has_numeric_options()
791
&& pfield.numeric_options().is_autoincrement())
703
793
unireg_type= Field::NEXT_NUMBER;
706
if (pfield.has_options() &&
707
pfield.options().has_default_value() &&
708
pfield.options().default_value().compare("NOW()") == 0)
796
if (pfield.has_options()
797
&& pfield.options().has_default_value()
798
&& pfield.options().default_value().compare("NOW()") == 0)
710
if (pfield.options().has_update_value() &&
711
pfield.options().update_value().compare("NOW()") == 0)
800
if (pfield.options().has_update_value()
801
&& pfield.options().update_value().compare("NOW()") == 0)
713
unireg_type= Field::TIMESTAMP_DNUN_FIELD;
803
unireg_type= Field::TIMESTAMP_DNUN_FIELD;
715
else if (! pfield.options().has_update_value())
805
else if (!pfield.options().has_update_value())
717
unireg_type= Field::TIMESTAMP_DN_FIELD;
807
unireg_type= Field::TIMESTAMP_DN_FIELD;
720
assert(1); // Invalid update value.
810
assert(1); // Invalid update value.
722
else if (pfield.has_options() &&
723
pfield.options().has_update_value() &&
724
pfield.options().update_value().compare("NOW()") == 0)
812
else if (pfield.has_options()
813
&& pfield.options().has_update_value()
814
&& pfield.options().update_value().compare("NOW()") == 0)
726
816
unireg_type= Field::TIMESTAMP_UN_FIELD;
748
838
const CHARSET_INFO *charset= &my_charset_bin;
750
if (field_type == DRIZZLE_TYPE_BLOB ||
751
field_type == DRIZZLE_TYPE_VARCHAR)
753
message::Table::Field::StringFieldOptions field_options= pfield.string_options();
755
charset= get_charset(field_options.has_collation_id() ?
756
field_options.collation_id() : 0);
759
charset= default_charset_info;
762
if (field_type == DRIZZLE_TYPE_ENUM)
764
message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
766
charset= get_charset(field_options.has_collation_id()?
767
field_options.collation_id() : 0);
770
charset= default_charset_info;
774
if (field_type == DRIZZLE_TYPE_DECIMAL
775
|| field_type == DRIZZLE_TYPE_DOUBLE)
777
message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
779
if (! pfield.has_numeric_options() || ! fo.has_scale())
782
We don't write the default to table proto so
783
if no decimals specified for DOUBLE, we use the default.
785
decimals= NOT_FIXED_DEC;
789
if (fo.scale() > DECIMAL_MAX_SCALE)
794
decimals= static_cast<uint8_t>(fo.scale());
840
if (field_type==DRIZZLE_TYPE_BLOB
841
|| field_type==DRIZZLE_TYPE_VARCHAR)
843
drizzled::message::Table::Field::StringFieldOptions field_options=
844
pfield.string_options();
846
charset= get_charset(field_options.has_collation_id()?
847
field_options.collation_id() : 0);
850
charset= default_charset_info;
854
if (field_type==DRIZZLE_TYPE_ENUM)
856
drizzled::message::Table::Field::SetFieldOptions field_options=
857
pfield.set_options();
859
charset= get_charset(field_options.has_collation_id()?
860
field_options.collation_id() : 0);
863
charset= default_charset_info;
798
867
Item *default_value= NULL;
800
if (pfield.options().has_default_value() ||
801
pfield.options().has_default_null() ||
802
pfield.options().has_default_bin_value())
869
if (pfield.options().has_default_value()
870
|| pfield.options().has_default_null()
871
|| pfield.options().has_default_bin_value())
804
873
default_value= default_value_item(field_type,
806
pfield.options().default_null(),
807
&pfield.options().default_value(),
808
&pfield.options().default_bin_value());
875
pfield.options().default_null(),
876
&pfield.options().default_value(),
877
&pfield.options().default_bin_value());
880
uint32_t pack_flag= pfield.pack_flag(); /* TODO: MUST DIE */
812
882
Table temp_table; /* Use this so that BLOB DEFAULT '' works */
813
883
memset(&temp_table, 0, sizeof(temp_table));
814
884
temp_table.s= share;
815
temp_table.in_use= &session;
816
temp_table.s->db_low_byte_first= true; //Cursor->low_byte_first();
885
temp_table.in_use= session;
886
temp_table.s->db_low_byte_first= 1; //handler->low_byte_first();
817
887
temp_table.s->blob_ptr_size= portable_sizeof_char_ptr;
819
uint32_t field_length= 0; //Assignment is for compiler complaint.
823
case DRIZZLE_TYPE_BLOB:
824
case DRIZZLE_TYPE_VARCHAR:
826
message::Table::Field::StringFieldOptions field_options= pfield.string_options();
828
charset= get_charset(field_options.has_collation_id() ?
829
field_options.collation_id() : 0);
832
charset= default_charset_info;
834
field_length= field_options.length() * charset->mbmaxlen;
837
case DRIZZLE_TYPE_DOUBLE:
839
message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
840
if (!fo.has_precision() && !fo.has_scale())
842
field_length= DBL_DIG+7;
846
field_length= fo.precision();
848
if (field_length < decimals &&
849
decimals != NOT_FIXED_DEC)
851
my_error(ER_M_BIGGER_THAN_D, MYF(0), pfield.name().c_str());
857
case DRIZZLE_TYPE_DECIMAL:
859
message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
861
field_length= my_decimal_precision_to_length(fo.precision(), fo.scale(),
865
case DRIZZLE_TYPE_TIMESTAMP:
866
case DRIZZLE_TYPE_DATETIME:
867
field_length= DateTime::MAX_STRING_LENGTH;
869
case DRIZZLE_TYPE_DATE:
870
field_length= Date::MAX_STRING_LENGTH;
872
case DRIZZLE_TYPE_ENUM:
876
message::Table::Field::EnumerationValues fo= pfield.enumeration_values();
878
for (int valnr= 0; valnr < fo.field_value_size(); valnr++)
880
if (fo.field_value(valnr).length() > field_length)
882
field_length= charset->cset->numchars(charset,
883
fo.field_value(valnr).c_str(),
884
fo.field_value(valnr).c_str()
885
+ fo.field_value(valnr).length())
891
case DRIZZLE_TYPE_LONG:
893
uint32_t sign_len= pfield.constraints().is_unsigned() ? 0 : 1;
894
field_length= MAX_INT_WIDTH+sign_len;
897
case DRIZZLE_TYPE_LONGLONG:
898
field_length= MAX_BIGINT_WIDTH;
900
case DRIZZLE_TYPE_NULL:
901
abort(); // Programming error
904
Field* f= make_field(share,
906
record + field_offsets[fieldnr] + data_offset,
908
pfield.constraints().is_nullable(),
914
(Field::utype) MTYP_TYPENR(unireg_type),
915
((field_type == DRIZZLE_TYPE_ENUM) ?
916
share->intervals + (interval_nr++)
918
share->fieldnames.type_names[fieldnr]);
889
Field* f= make_field(share, &share->mem_root,
890
record+field_offsets[fieldnr]+data_offset,
891
pfield.options().length(),
897
(Field::utype) MTYP_TYPENR(unireg_type),
898
((field_type==DRIZZLE_TYPE_ENUM)?
899
share->intervals+(interval_nr++)
901
share->fieldnames.type_names[fieldnr]);
920
903
share->field[fieldnr]= f;
922
905
f->init(&temp_table); /* blob default values need table obj */
924
if (! (f->flags & NOT_NULL_FLAG))
907
if (!(f->flags & NOT_NULL_FLAG))
926
909
*f->null_ptr|= f->null_bit;
927
if (! (null_bit_pos= (null_bit_pos + 1) & 7)) /* @TODO Ugh. */
910
if (!(null_bit_pos= (null_bit_pos + 1) & 7))
932
915
if (default_value)
934
enum_check_fields old_count_cuted_fields= session.count_cuted_fields;
935
session.count_cuted_fields= CHECK_FIELD_WARN;
917
enum_check_fields old_count_cuted_fields= session->count_cuted_fields;
918
session->count_cuted_fields= CHECK_FIELD_WARN;
936
919
int res= default_value->save_in_field(f, 1);
937
session.count_cuted_fields= old_count_cuted_fields;
938
if (res != 0 && res != 3) /* @TODO Huh? */
920
session->count_cuted_fields= old_count_cuted_fields;
921
if (res != 0 && res != 3)
940
923
my_error(ER_INVALID_DEFAULT, MYF(0), f->field_name);
945
928
else if (f->real_type() == DRIZZLE_TYPE_ENUM &&
946
(f->flags & NOT_NULL_FLAG))
929
(f->flags & NOT_NULL_FLAG))
948
931
f->set_notnull();
949
932
f->store((int64_t) 1, true);
1003
982
if (null_count & 7)
1004
983
*(record + null_count / 8)|= ~(((unsigned char) 1 << (null_count & 7)) - 1);
1006
share->null_bytes= (null_pos - (unsigned char*) record + (null_bit_pos + 7) / 8);
985
share->null_bytes= (null_pos - (unsigned char*) record +
986
(null_bit_pos + 7) / 8);
1008
988
share->last_null_bit_pos= null_bit_pos;
1010
990
free(field_offsets);
1011
field_offsets= NULL;
1012
991
free(field_pack_length);
1013
field_pack_length= NULL;
993
if (!(handler_file= get_new_handler(share, session->mem_root,
1015
997
/* Fix key stuff */
1016
998
if (share->key_parts)
1018
uint32_t primary_key= (uint32_t) (find_type((char*) "PRIMARY",
1019
&share->keynames, 3) - 1); /* @TODO Huh? */
1000
uint32_t primary_key=(uint32_t) (find_type((char*) "PRIMARY",
1001
&share->keynames, 3) - 1);
1003
int64_t ha_option= handler_file->ha_table_flags();
1021
1005
keyinfo= share->key_info;
1022
1006
key_part= keyinfo->key_part;
1024
for (uint32_t key= 0; key < share->keys; key++,keyinfo++)
1008
for (uint32_t key= 0 ; key < share->keys ; key++,keyinfo++)
1026
1010
uint32_t usable_parts= 0;
1028
1012
if (primary_key >= MAX_KEY && (keyinfo->flags & HA_NOSAME))
1031
If the UNIQUE key doesn't have NULL columns and is not a part key
1032
declare this as a primary key.
1035
for (uint32_t i= 0; i < keyinfo->key_parts; i++)
1037
uint32_t fieldnr= key_part[i].fieldnr;
1039
share->field[fieldnr-1]->null_ptr ||
1040
share->field[fieldnr-1]->key_length() != key_part[i].length)
1042
primary_key= MAX_KEY; // Can't be used
1015
If the UNIQUE key doesn't have NULL columns and is not a part key
1016
declare this as a primary key.
1019
for (uint32_t i= 0 ; i < keyinfo->key_parts ;i++)
1021
uint32_t fieldnr= key_part[i].fieldnr;
1023
share->field[fieldnr-1]->null_ptr ||
1024
share->field[fieldnr-1]->key_length() !=
1027
primary_key=MAX_KEY; // Can't be used
1048
1033
for (uint32_t i= 0 ; i < keyinfo->key_parts ; key_part++,i++)
1051
if (! key_part->fieldnr)
1036
if (!key_part->fieldnr)
1053
abort(); // goto err;
1038
// error= 4; // Wrong file
1039
abort(); // goto err;
1055
1041
field= key_part->field= share->field[key_part->fieldnr-1];
1056
1042
key_part->type= field->key_type();
1122
1107
set_if_bigger(share->max_key_length,keyinfo->key_length+
1123
1108
keyinfo->key_parts);
1124
1109
share->total_key_length+= keyinfo->key_length;
1126
if (keyinfo->flags & HA_NOSAME)
1111
MERGE tables do not have unique indexes. But every key could be
1112
an unique index on the underlying MyISAM table. (Bug #10400)
1114
if ((keyinfo->flags & HA_NOSAME) ||
1115
(ha_option & HA_ANY_INDEX_MAY_BE_UNIQUE))
1128
1116
set_if_bigger(share->max_unique_length,keyinfo->key_length);
1131
1118
if (primary_key < MAX_KEY &&
1132
(share->keys_in_use.test(primary_key)))
1119
(share->keys_in_use.test(primary_key)))
1134
1121
share->primary_key= primary_key;
1136
If we are using an integer as the primary key then allow the user to
1137
refer to it as '_rowid'
1123
If we are using an integer as the primary key then allow the user to
1124
refer to it as '_rowid'
1139
1126
if (share->key_info[primary_key].key_parts == 1)
1141
Field *field= share->key_info[primary_key].key_part[0].field;
1142
if (field && field->result_type() == INT_RESULT)
1128
Field *field= share->key_info[primary_key].key_part[0].field;
1129
if (field && field->result_type() == INT_RESULT)
1144
1131
/* note that fieldnr here (and rowid_field_offset) starts from 1 */
1145
share->rowid_field_offset= (share->key_info[primary_key].key_part[0].
1132
share->rowid_field_offset= (share->key_info[primary_key].key_part[0].
1151
1139
share->primary_key = MAX_KEY; // we do not have a primary key
1448
1450
bitmap_size= share->column_bitmap_size;
1449
1451
if (!(bitmaps= (unsigned char*) alloc_root(&outparam->mem_root, bitmap_size*3)))
1451
outparam->def_read_set.init((my_bitmap_map*) bitmaps, share->fields);
1452
outparam->def_write_set.init((my_bitmap_map*) (bitmaps+bitmap_size), share->fields);
1453
outparam->tmp_set.init((my_bitmap_map*) (bitmaps+bitmap_size*2), share->fields);
1453
bitmap_init(&outparam->def_read_set,
1454
(my_bitmap_map*) bitmaps, share->fields);
1455
bitmap_init(&outparam->def_write_set,
1456
(my_bitmap_map*) (bitmaps+bitmap_size), share->fields);
1457
bitmap_init(&outparam->tmp_set,
1458
(my_bitmap_map*) (bitmaps+bitmap_size*2), share->fields);
1454
1459
outparam->default_column_bitmaps();
1456
1461
/* The table struct is now initialized; Open the table */
1463
if (db_stat && open_mode != OTM_ALTER)
1461
if ((ha_err= (outparam->cursor->
1466
if ((ha_err= (outparam->file->
1462
1467
ha_open(outparam, share->normalized_path.str,
1463
1468
(db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
1464
1469
(db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE :
1560
void Table::resetTable(Session *session,
1562
uint32_t db_stat_arg)
1575
db_stat= db_stat_arg;
1578
record[0]= (unsigned char *) NULL;
1579
record[1]= (unsigned char *) NULL;
1581
insert_values= NULL;
1583
next_number_field= NULL;
1584
found_next_number_field= NULL;
1585
timestamp_field= NULL;
1587
pos_in_table_list= NULL;
1597
derived_select_number= 0;
1598
current_lock= F_UNLCK;
1612
open_placeholder= false;
1613
locked_by_name= false;
1616
auto_increment_field_not_null= false;
1617
alias_name_used= false;
1620
quick_condition_rows= 0;
1622
timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
1627
covering_keys.reset();
1632
keys_in_use_for_query.reset();
1633
keys_in_use_for_group_by.reset();
1634
keys_in_use_for_order_by.reset();
1636
memset(quick_rows, 0, sizeof(ha_rows) * MAX_KEY);
1637
memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
1639
memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
1640
memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
1642
memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
1643
memset(&sort, 0, sizeof(filesort_info_st));
1648
1566
/* Deallocate temporary blob storage */
1650
1568
void free_blobs(register Table *table)
1855
1774
uint32_t field_count= s->fields;
1857
this->def_read_set.init((my_bitmap_map*) bitmaps, field_count);
1858
this->tmp_set.init((my_bitmap_map*) (bitmaps+ bitmap_buffer_size(field_count)), field_count);
1776
bitmap_init(&this->def_read_set, (my_bitmap_map*) bitmaps, field_count);
1777
bitmap_init(&this->tmp_set, (my_bitmap_map*) (bitmaps+ bitmap_buffer_size(field_count)), field_count);
1860
1779
/* write_set and all_set are copies of read_set */
1861
1780
def_write_set= def_read_set;
1862
1781
s->all_set= def_read_set;
1863
this->s->all_set.setAll();
1782
bitmap_set_all(&this->s->all_set);
1864
1783
default_column_bitmaps();
1869
void Table::updateCreateInfo(message::Table *table_proto)
1788
void Table::updateCreateInfo(HA_CREATE_INFO *create_info)
1871
message::Table::TableOptions *table_options= table_proto->mutable_options();
1872
table_options->set_block_size(s->block_size);
1873
table_options->set_comment(s->getComment());
1790
create_info->max_rows= s->max_rows;
1791
create_info->min_rows= s->min_rows;
1792
create_info->table_options= s->db_create_options;
1793
create_info->avg_row_length= s->avg_row_length;
1794
create_info->block_size= s->block_size;
1795
create_info->row_type= s->row_type;
1796
create_info->default_table_charset= s->table_charset;
1797
create_info->table_charset= 0;
1798
create_info->comment= s->comment;
1876
1803
int rename_file_ext(const char * from,const char * to,const char * ext)
2636
2608
/* If result table is small; use a heap */
2637
2609
/* future: storage engine selection can be made dynamic? */
2638
2610
if (blob_count || using_unique_constraint ||
2639
(select_options & (OPTION_BIG_TABLES | SELECT_SMALL_RESULT)) == OPTION_BIG_TABLES)
2611
(select_options & (OPTION_BIG_TABLES | SELECT_SMALL_RESULT)) ==
2612
OPTION_BIG_TABLES || (select_options & TMP_TABLE_FORCE_MYISAM))
2641
2614
share->storage_engine= myisam_engine;
2642
table->cursor= share->db_type()->getCursor(*share, &table->mem_root);
2615
table->file= get_new_handler(share, &table->mem_root,
2644
(param->group_parts > table->cursor->getEngine()->max_key_parts() ||
2645
param->group_length > table->cursor->getEngine()->max_key_length()))
2646
using_unique_constraint= true;
2618
(param->group_parts > table->file->max_key_parts() ||
2619
param->group_length > table->file->max_key_length()))
2620
using_unique_constraint=1;
2650
2624
share->storage_engine= heap_engine;
2651
table->cursor= share->db_type()->getCursor(*share, &table->mem_root);
2625
table->file= get_new_handler(share, &table->mem_root,
2653
if (! table->cursor)
2657
if (! using_unique_constraint)
2632
if (!using_unique_constraint)
2658
2633
reclength+= group_null_items; // null flag is stored separately
2660
2635
share->blob_fields= blob_count;
3350
3316
if (new_table.open_tmp_table())
3352
if (table->cursor->indexes_are_disabled())
3353
new_table.cursor->ha_disable_indexes(HA_KEY_SWITCH_ALL);
3354
table->cursor->ha_index_or_rnd_end();
3355
table->cursor->ha_rnd_init(1);
3318
if (table->file->indexes_are_disabled())
3319
new_table.file->ha_disable_indexes(HA_KEY_SWITCH_ALL);
3320
table->file->ha_index_or_rnd_end();
3321
table->file->ha_rnd_init(1);
3356
3322
if (table->no_rows)
3358
new_table.cursor->extra(HA_EXTRA_NO_ROWS);
3324
new_table.file->extra(HA_EXTRA_NO_ROWS);
3359
3325
new_table.no_rows=1;
3362
3328
/* HA_EXTRA_WRITE_CACHE can stay until close, no need to disable it */
3363
new_table.cursor->extra(HA_EXTRA_WRITE_CACHE);
3329
new_table.file->extra(HA_EXTRA_WRITE_CACHE);
3366
3332
copy all old rows from heap table to MyISAM table
3367
3333
This is the only code that uses record[1] to read/write but this
3368
3334
is safe as this is a temporary MyISAM table without timestamp/autoincrement.
3370
while (!table->cursor->rnd_next(new_table.record[1]))
3336
while (!table->file->rnd_next(new_table.record[1]))
3372
write_err= new_table.cursor->ha_write_row(new_table.record[1]);
3338
write_err= new_table.file->ha_write_row(new_table.record[1]);
3376
3342
/* copy row that filled HEAP table */
3377
if ((write_err=new_table.cursor->ha_write_row(table->record[0])))
3343
if ((write_err=new_table.file->ha_write_row(table->record[0])))
3379
if (new_table.cursor->is_fatal_error(write_err, HA_CHECK_DUP) ||
3345
if (new_table.file->is_fatal_error(write_err, HA_CHECK_DUP) ||
3380
3346
!ignore_last_dupp_key_error)
3384
3350
/* remove heap table and change to use myisam table */
3385
(void) table->cursor->ha_rnd_end();
3386
(void) table->cursor->close(); // This deletes the table !
3387
delete table->cursor;
3388
table->cursor= NULL;
3351
(void) table->file->ha_rnd_end();
3352
(void) table->file->close(); // This deletes the table !
3389
3355
new_table.s= table->s; // Keep old share
3390
3356
*table= new_table;
3391
3357
*table->s= share;
3393
table->cursor->change_table_ptr(table, table->s);
3359
table->file->change_table_ptr(table, table->s);
3394
3360
table->use_all_columns();
3395
3361
if (save_proc_info)
3546
3507
memset(null_flags, 255, s->null_bytes);
3560
insert_values(NULL),
3562
next_number_field(NULL),
3563
found_next_number_field(NULL),
3564
timestamp_field(NULL),
3565
pos_in_table_list(NULL),
3574
derived_select_number(0),
3575
current_lock(F_UNLCK),
3585
open_placeholder(false),
3586
locked_by_name(false),
3588
auto_increment_field_not_null(false),
3589
alias_name_used(false),
3591
quick_condition_rows(0),
3592
timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
3595
record[0]= (unsigned char *) 0;
3596
record[1]= (unsigned char *) 0;
3598
covering_keys.reset();
3603
keys_in_use_for_query.reset();
3604
keys_in_use_for_group_by.reset();
3605
keys_in_use_for_order_by.reset();
3607
memset(quick_rows, 0, sizeof(ha_rows) * MAX_KEY);
3608
memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
3610
memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
3611
memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
3613
memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
3614
memset(&sort, 0, sizeof(filesort_info_st));
3617
3510
/*****************************************************************************
3618
3511
The different ways to read a record
3619
3512
Returns -1 if row was not found, 0 if row was found and 1 on errors
3620
3513
*****************************************************************************/
3622
/** Help function when we get some an error from the table Cursor. */
3515
/** Help function when we get some an error from the table handler. */
3624
3517
int Table::report_error(int error)