28 #include <drizzled/error.h>
29 #include <drizzled/gettext.h>
31 #include <drizzled/plugin/transactional_storage_engine.h>
32 #include <drizzled/plugin/authorization.h>
33 #include <drizzled/nested_join.h>
34 #include <drizzled/sql_parse.h>
35 #include <drizzled/item/sum.h>
36 #include <drizzled/table_list.h>
37 #include <drizzled/session.h>
38 #include <drizzled/sql_base.h>
39 #include <drizzled/sql_select.h>
40 #include <drizzled/field/blob.h>
41 #include <drizzled/field/varstring.h>
42 #include <drizzled/field/double.h>
43 #include <drizzled/message/table.pb.h>
45 #include <drizzled/charset.h>
46 #include <drizzled/internal/m_string.h>
47 #include <plugin/myisam/myisam.h>
48 #include <drizzled/plugin/storage_engine.h>
49 #include <drizzled/item/string.h>
50 #include <drizzled/item/int.h>
51 #include <drizzled/item/decimal.h>
52 #include <drizzled/item/float.h>
53 #include <drizzled/item/null.h>
55 #include <drizzled/table/singular.h>
56 #include <drizzled/table_proto.h>
57 #include <drizzled/typelib.h>
58 #include <drizzled/sql_lex.h>
59 #include <drizzled/statistics_variables.h>
60 #include <drizzled/system_variables.h>
61 #include <drizzled/open_tables_state.h>
67 extern plugin::StorageEngine *heap_engine;
68 extern plugin::StorageEngine *myisam_engine;
75 int Table::delete_table(
bool free_share)
80 error= cursor->close();
85 for (
Field **ptr=field ; *ptr ; ptr++)
103 mem_root.free_root(MYF(0));
107 void Table::resetTable(Session *session,
109 uint32_t db_stat_arg)
124 db_stat= db_stat_arg;
126 record[0]= (
unsigned char *) NULL;
127 record[1]= (
unsigned char *) NULL;
129 insert_values.clear();
131 next_number_field= NULL;
132 found_next_number_field= NULL;
133 timestamp_field= NULL;
135 pos_in_table_list= NULL;
145 derived_select_number= 0;
146 current_lock= F_UNLCK;
160 open_placeholder=
false;
161 locked_by_name=
false;
164 auto_increment_field_not_null=
false;
165 alias_name_used=
false;
168 quick_condition_rows= 0;
170 timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
175 covering_keys.reset();
180 keys_in_use_for_query.reset();
181 keys_in_use_for_group_by.reset();
182 keys_in_use_for_order_by.reset();
184 memset(quick_rows, 0,
sizeof(ha_rows) * MAX_KEY);
185 memset(const_key_parts, 0,
sizeof(ha_rows) * MAX_KEY);
187 memset(quick_key_parts, 0,
sizeof(
unsigned int) * MAX_KEY);
188 memset(quick_n_ranges, 0,
sizeof(
unsigned int) * MAX_KEY);
190 mem_root.init(TABLE_ALLOC_BLOCK_SIZE);
197 void free_blobs(Table *table)
200 for (ptr= table->getBlobField(), end=ptr + table->sizeBlobFields();
204 ((Field_blob*) table->getField(*ptr))->free();
209 TYPELIB *typelib(memory::Root& mem_root, List<String> &strings)
211 TYPELIB *result=
new (mem_root) TYPELIB;
212 result->count= strings.size();
214 result->type_names= (
const char**) mem_root.alloc((
sizeof(
char*) +
sizeof(uint32_t)) * (result->count + 1));
215 result->type_lengths= (uint*) (result->type_names + result->count + 1);
217 List<String>::iterator it(strings.begin());
219 for (uint32_t i= 0; (tmp= it++); i++)
221 result->type_names[i]= tmp->ptr();
222 result->type_lengths[i]= tmp->length();
225 result->type_names[result->count]= 0;
226 result->type_lengths[result->count]= 0;
233 int set_zone(
int nr,
int min_zone,
int max_zone)
257 void append_unescaped(String *res,
const char *pos, uint32_t length)
259 const char *end= pos+length;
262 for (; pos != end ; pos++)
265 if (use_mb(default_charset_info) &&
266 (mblen= my_ismbchar(default_charset_info, pos, end)))
268 res->append(pos, mblen);
309 bool check_table_name(
str_ref str)
311 return str.empty() || str.size() > NAME_LEN || str.data()[str.size() - 1] ==
' ' || check_identifier_name(str);
320 bool check_column_name(
const char *name)
322 uint32_t name_length= 0;
323 bool last_char_is_space=
true;
327 last_char_is_space= system_charset_info->isspace(*name);
328 if (use_mb(system_charset_info))
330 int len=my_ismbchar(system_charset_info, name,
331 name+system_charset_info->mbmaxlen);
347 assert(*name != NAMES_SEP_CHAR);
352 return last_char_is_space || (uint32_t) name_length > NAME_CHAR_LEN;
362 void Table::clear_column_bitmaps()
369 def_read_set.reset();
370 def_write_set.reset();
371 column_bitmaps_set(def_read_set, def_write_set);
384 void Table::prepare_for_position()
387 if ((cursor->getEngine()->check_flag(HTON_BIT_PRIMARY_KEY_IN_READ_INDEX)) &&
388 getShare()->hasPrimaryKey())
390 mark_columns_used_by_index_no_reset(getShare()->getPrimaryKey());
406 void Table::mark_columns_used_by_index(uint32_t index)
408 boost::dynamic_bitset<> *bitmap= &tmp_set;
410 (void) cursor->extra(HA_EXTRA_KEYREAD);
412 mark_columns_used_by_index_no_reset(index, *bitmap);
413 column_bitmaps_set(*bitmap, *bitmap);
429 void Table::restore_column_maps_after_mark_index()
433 (void) cursor->extra(HA_EXTRA_NO_KEYREAD);
434 default_column_bitmaps();
443 void Table::mark_columns_used_by_index_no_reset(uint32_t index)
445 mark_columns_used_by_index_no_reset(index, *read_set);
449 void Table::mark_columns_used_by_index_no_reset(uint32_t index,
450 boost::dynamic_bitset<>& bitmap)
452 KeyPartInfo *key_part= key_info[index].key_part;
453 KeyPartInfo *key_part_end= (key_part + key_info[index].key_parts);
454 for (; key_part != key_part_end; key_part++)
456 if (! bitmap.empty())
457 bitmap.set(key_part->fieldnr-1);
470 void Table::mark_auto_increment_column()
472 assert(found_next_number_field);
477 setReadSet(found_next_number_field->position());
478 setWriteSet(found_next_number_field->position());
479 if (getShare()->next_number_keypart)
480 mark_columns_used_by_index_no_reset(getShare()->next_number_index);
502 void Table::mark_columns_needed_for_delete()
511 if (not getShare()->hasPrimaryKey())
518 mark_columns_used_by_index_no_reset(getShare()->getPrimaryKey());
521 if (cursor->getEngine()->check_flag(HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE))
524 for (reg_field= field ; *reg_field ; reg_field++)
526 if ((*reg_field)->flags & PART_KEY_FLAG)
527 setReadSet((*reg_field)->position());
551 void Table::mark_columns_needed_for_update()
559 if (not getShare()->hasPrimaryKey())
566 mark_columns_used_by_index_no_reset(getShare()->getPrimaryKey());
568 if (cursor->getEngine()->check_flag(HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE))
572 for (reg_field= field ; *reg_field ; reg_field++)
575 if (is_overlapping(merge_keys, (*reg_field)->part_of_key))
576 setReadSet((*reg_field)->position());
590 void Table::mark_columns_needed_for_insert()
592 if (found_next_number_field)
593 mark_auto_increment_column();
598 size_t Table::max_row_length(
const unsigned char *data)
600 size_t length= getRecordLength() + 2 * sizeFields();
601 uint32_t *
const beg= getBlobField();
602 uint32_t *
const end= beg + sizeBlobFields();
604 for (uint32_t *ptr= beg ; ptr != end ; ++ptr)
606 Field_blob*
const blob= (Field_blob*) field[*ptr];
607 length+= blob->get_length((
const unsigned char*)
608 (data + blob->offset(getInsertRecord()))) +
614 void Table::setVariableWidth(
void)
617 if (in_use && in_use->lex().sql_command == SQLCOM_CREATE_TABLE)
619 getMutableShare()->setVariableWidth();
652 const char *name,
Table *table,
653 Item_field *item, uint32_t convert_blob_length)
661 if (convert_blob_length && convert_blob_length <= Field_varstring::MAX_SIZE && (org_field->flags & BLOB_FLAG))
663 table->setVariableWidth();
664 new_field=
new Field_varstring(convert_blob_length, org_field->maybe_null(), org_field->
field_name, org_field->charset());
668 new_field= org_field->new_field(session->
mem_root, table, table == org_field->getTable());
672 new_field->init(table);
675 item->result_field= new_field;
678 new_field->flags|= (org_field->flags & NO_DEFAULT_VALUE_FLAG);
679 if (org_field->maybe_null() || (item && item->
maybe_null))
680 new_field->flags&= ~NOT_NULL_FLAG;
681 if (org_field->type() == DRIZZLE_TYPE_VARCHAR)
682 table->getMutableShare()->db_create_options|= HA_OPTION_PACK_RECORD;
683 else if (org_field->type() == DRIZZLE_TYPE_DOUBLE)
718 Order *group,
bool distinct,
bool save_sum_fields,
719 uint64_t select_options, ha_rows rows_limit,
720 const char *table_alias)
722 uint i,field_count,null_count,null_pack_length;
723 uint32_t copy_func_count= param->func_count;
724 uint32_t hidden_null_count, hidden_null_pack_length, hidden_field_count;
725 uint32_t blob_count,group_null_items, string_count;
727 ulong reclength, string_total_length;
728 bool using_unique_constraint=
false;
729 bool not_all_columns= !(select_options & TMP_TABLE_ALL_COLUMNS);
730 unsigned char *pos, *group_buff;
731 unsigned char *null_flags;
732 Field **reg_field, **from_field, **default_field;
738 uint32_t total_uneven_bit_length= 0;
739 bool force_copy_fields= param->force_copy_fields;
740 uint64_t max_rows= 0;
742 session->status_var.created_tmp_tables++;
746 if (! param->quick_group)
750 else for (
Order *tmp=group ; tmp ; tmp=tmp->next)
758 (*tmp->item)->marker= 4;
759 if ((*tmp->item)->max_length >= CONVERT_IF_BIGGER_TO_BLOB)
760 using_unique_constraint=
true;
762 if (param->group_length >= MAX_BLOB_WIDTH)
763 using_unique_constraint=
true;
768 field_count=param->field_count+param->func_count+param->sum_func_count;
769 hidden_field_count=param->hidden_field_count;
778 if (param->precomputed_group_by)
780 copy_func_count+= param->sum_func_count;
786 &default_field,
sizeof(
Field*) * (field_count),
787 &from_field,
sizeof(
Field*)*field_count,
788 ©_func,
sizeof(*copy_func)*(copy_func_count+1),
789 ¶m->keyinfo,
sizeof(*param->keyinfo),
790 &key_part_info,
sizeof(*key_part_info)*(param->group_parts+1),
791 ¶m->start_recinfo,
sizeof(*param->recinfo)*(field_count*2+4),
792 &group_buff, (group && ! using_unique_constraint ? param->group_length : 0),
796 param->items_to_copy= copy_func;
799 memset(default_field, 0,
sizeof(
Field*) * (field_count));
800 memset(from_field, 0,
sizeof(
Field*)*field_count);
805 table->getMutableShare()->setFields(field_count+1);
806 table->setFields(table->getMutableShare()->getFields(
true));
807 reg_field= table->getMutableShare()->getFields(
true);
808 table->setAlias(table_alias);
809 table->reginfo.lock_type=TL_WRITE;
810 table->
db_stat=HA_OPEN_KEYFILE+HA_OPEN_RNDFILE;
815 table->quick_keys.reset();
816 table->covering_keys.reset();
817 table->keys_in_use_for_query.reset();
819 table->getMutableShare()->blob_field.resize(field_count+1);
820 uint32_t *blob_field= &table->getMutableShare()->blob_field[0];
821 table->getMutableShare()->db_low_byte_first=1;
822 table->getMutableShare()->table_charset= param->table_charset;
823 table->getMutableShare()->keys_for_keyread.reset();
824 table->getMutableShare()->keys_in_use.reset();
828 reclength= string_total_length= 0;
829 blob_count= string_count= null_count= hidden_null_count= group_null_items= 0;
830 param->using_indirect_summary_function= 0;
833 Field **tmp_from_field=from_field;
834 while (
Item* item=li++)
836 Item::Type type=item->type();
839 if (item->with_sum_func && type != Item::SUM_FUNC_ITEM)
841 if (item->used_tables() & OUTER_REF_TABLE_BIT)
842 item->update_used_tables();
843 if (type == Item::SUBSELECT_ITEM ||
844 (item->used_tables() & ~OUTER_REF_TABLE_BIT))
851 param->using_indirect_summary_function=1;
855 if (item->const_item() && (int) hidden_field_count <= 0)
858 if (type == Item::SUM_FUNC_ITEM && !group && !save_sum_fields)
860 ((
Item_sum*) item)->result_field= 0;
861 for (i= 0 ; i < ((
Item_sum*) item)->arg_count ; i++)
869 tmp_from_field, &default_field[fieldnr],
870 group != 0,not_all_columns,
872 param->convert_blob_length);
877 if (new_field->flags & BLOB_FLAG)
879 *blob_field++= fieldnr;
882 *(reg_field++)= new_field;
883 if (new_field->real_type() == DRIZZLE_TYPE_VARCHAR)
891 if (!(new_field->flags & NOT_NULL_FLAG))
898 (*argp)->maybe_null=1;
900 new_field->setPosition(fieldnr++);
918 tmp_from_field, &default_field[fieldnr],
920 !force_copy_fields &&
921 (not_all_columns || group != 0),
923 param->convert_blob_length);
931 if (type == Item::SUM_FUNC_ITEM)
932 ((
Item_sum *) item)->result_field= new_field;
935 if (!(new_field->flags & NOT_NULL_FLAG))
937 if (new_field->flags & BLOB_FLAG)
939 *blob_field++= fieldnr;
942 if (item->marker == 4 && item->maybe_null)
945 new_field->flags|= GROUP_FLAG;
947 new_field->setPosition(fieldnr++);
948 *(reg_field++)= new_field;
950 if (!--hidden_field_count)
956 hidden_null_count=null_count;
961 param->hidden_field_count= fieldnr;
965 assert(fieldnr == (uint32_t) (reg_field - table->getFields()));
966 assert(field_count >= (uint32_t) (reg_field - table->getFields()));
967 field_count= fieldnr;
970 table->getMutableShare()->setFieldSize(field_count);
974 if (blob_count || using_unique_constraint ||
975 (session->lex().select_lex.options & SELECT_BIG_RESULT) ||
976 (session->lex().current_select->olap == ROLLUP_TYPE) ||
977 (select_options & (OPTION_BIG_TABLES | SELECT_SMALL_RESULT)) == OPTION_BIG_TABLES)
979 table->getMutableShare()->storage_engine= myisam_engine;
980 table->
cursor= table->getMutableShare()->db_type()->getCursor(*table);
982 (param->group_parts > table->
cursor->getEngine()->max_key_parts() ||
983 param->group_length > table->
cursor->getEngine()->max_key_length()))
985 using_unique_constraint=
true;
990 table->getMutableShare()->storage_engine= heap_engine;
991 table->
cursor= table->getMutableShare()->db_type()->getCursor(*table);
997 if (! using_unique_constraint)
998 reclength+= group_null_items;
1000 table->getMutableShare()->blob_fields= blob_count;
1001 if (blob_count == 0)
1004 if (param->hidden_field_count)
1005 hidden_null_count++;
1009 hidden_null_pack_length=(hidden_null_count+7)/8;
1010 null_pack_length= (hidden_null_pack_length +
1011 (null_count + total_uneven_bit_length + 7) / 8);
1012 reclength+=null_pack_length;
1016 table->getMutableShare()->setRecordLength(reclength);
1018 uint32_t alloc_length=ALIGN_SIZE(reclength+MI_UNIQUE_HASH_LENGTH+1);
1019 table->getMutableShare()->rec_buff_length= alloc_length;
1020 table->
record[0]= table->alloc(alloc_length*2);
1021 table->
record[1]= table->getInsertRecord()+alloc_length;
1022 table->getMutableShare()->resizeDefaultValues(alloc_length);
1025 param->func_count= copy_func - param->items_to_copy;
1027 table->setup_tmp_table_column_bitmaps();
1029 recinfo=param->start_recinfo;
1030 null_flags= table->getInsertRecord();
1031 pos=table->getInsertRecord()+ null_pack_length;
1032 if (null_pack_length)
1034 memset(recinfo, 0,
sizeof(*recinfo));
1035 recinfo->type=FIELD_NORMAL;
1036 recinfo->length=null_pack_length;
1038 memset(null_flags, 255, null_pack_length);
1040 table->null_flags= table->getInsertRecord();
1041 table->getMutableShare()->null_fields= null_count+ hidden_null_count;
1042 table->getMutableShare()->null_bytes= null_pack_length;
1044 null_count= (blob_count == 0) ? 1 : 0;
1045 hidden_field_count=param->hidden_field_count;
1046 for (i= 0,reg_field= table->getFields(); i < field_count; i++,reg_field++,recinfo++)
1048 Field *field= *reg_field;
1050 memset(recinfo, 0,
sizeof(*recinfo));
1052 if (!(field->flags & NOT_NULL_FLAG))
1054 if (field->flags & GROUP_FLAG && !using_unique_constraint)
1062 recinfo->type=FIELD_NORMAL;
1064 memset(recinfo, 0,
sizeof(*recinfo));
1068 recinfo->null_bit= 1 << (null_count & 7);
1069 recinfo->null_pos= null_count/8;
1071 field->move_field(pos,null_flags+null_count/8,
1072 1 << (null_count & 7));
1076 field->move_field(pos,(
unsigned char*) 0,0);
1083 if (default_field[i] && default_field[i]->ptr)
1091 Field *orig_field= default_field[i];
1093 diff= (ptrdiff_t) (orig_field->getTable()->getDefaultValues() - orig_field->getTable()->getInsertRecord());
1094 orig_field->move_field_offset(diff);
1095 if (orig_field->is_real_null())
1099 field->set_notnull();
1102 orig_field->move_field_offset(-diff);
1107 copy->set(field,from_field[i],save_sum_fields);
1114 recinfo->length=length;
1115 if (field->flags & BLOB_FLAG)
1116 recinfo->type= (int) FIELD_BLOB;
1118 recinfo->type=FIELD_NORMAL;
1119 if (!--hidden_field_count)
1120 null_count=(null_count+7) & ~7;
1123 param->copy_field_end=copy;
1124 param->recinfo=recinfo;
1125 table->storeRecordAsDefault();
1127 if (session->
variables.tmp_table_size == ~ (uint64_t) 0)
1129 max_rows= ~(uint64_t) 0;
1133 max_rows= (uint64_t) (((table->getMutableShare()->db_type() == heap_engine) ?
1135 session->
variables.max_heap_table_size) :
1137 table->getMutableShare()->getRecordLength());
1140 set_if_bigger(max_rows, (uint64_t)1);
1145 set_if_smaller(max_rows, rows_limit);
1147 table->getMutableShare()->setMaxRows(max_rows);
1149 param->end_write_records= rows_limit;
1151 keyinfo= param->keyinfo;
1156 param->group_buff=group_buff;
1157 table->getMutableShare()->keys=1;
1158 table->getMutableShare()->uniques= test(using_unique_constraint);
1160 keyinfo->key_part=key_part_info;
1161 keyinfo->flags=HA_NOSAME;
1162 keyinfo->usable_key_parts=keyinfo->key_parts= param->group_parts;
1163 keyinfo->key_length= 0;
1164 keyinfo->rec_per_key= 0;
1165 keyinfo->algorithm= HA_KEY_ALG_UNDEF;
1166 keyinfo->name= (
char*)
"group_key";
1167 Order *cur_group= group;
1168 for (; cur_group ; cur_group= cur_group->next, key_part_info++)
1170 Field *field=(*cur_group->item)->get_tmp_table_field();
1171 bool maybe_null=(*cur_group->item)->maybe_null;
1172 key_part_info->null_bit= 0;
1173 key_part_info->field= field;
1174 key_part_info->offset= field->offset(table->getInsertRecord());
1175 key_part_info->length= (uint16_t) field->key_length();
1176 key_part_info->type= (uint8_t) field->key_type();
1177 key_part_info->key_type=
1178 ((ha_base_keytype) key_part_info->type == HA_KEYTYPE_TEXT ||
1179 (ha_base_keytype) key_part_info->type == HA_KEYTYPE_VARTEXT1 ||
1180 (ha_base_keytype) key_part_info->type == HA_KEYTYPE_VARTEXT2) ?
1182 if (!using_unique_constraint)
1184 cur_group->buff=(
char*) group_buff;
1185 if (!(cur_group->field= field->new_key_field(session->
mem_root,table,
1199 keyinfo->flags|= HA_NULL_ARE_EQUAL;
1200 key_part_info->null_bit=field->
null_bit;
1201 key_part_info->null_offset= (uint32_t) (field->
null_ptr -
1202 (
unsigned char*) table->getInsertRecord());
1207 key_part_info->key_part_flag|= HA_END_SPACE_ARE_EQUAL;
1210 keyinfo->key_length+= key_part_info->length;
1214 if (distinct && field_count != param->hidden_field_count)
1229 table->getMutableShare()->uniques= 1;
1231 null_pack_length-=hidden_null_pack_length;
1232 keyinfo->key_parts= ((field_count-param->hidden_field_count)+
1233 (table->getMutableShare()->uniques ? test(null_pack_length) : 0));
1235 table->getMutableShare()->keys= 1;
1236 key_part_info=
new (table->mem())
KeyPartInfo[keyinfo->key_parts];
1237 memset(key_part_info, 0, keyinfo->key_parts *
sizeof(
KeyPartInfo));
1239 keyinfo->key_part=key_part_info;
1240 keyinfo->flags=HA_NOSAME | HA_NULL_ARE_EQUAL;
1241 keyinfo->key_length=(uint16_t) reclength;
1242 keyinfo->name= (
char*)
"distinct_key";
1243 keyinfo->algorithm= HA_KEY_ALG_UNDEF;
1244 keyinfo->rec_per_key= 0;
1251 if (null_pack_length && table->getMutableShare()->uniques)
1253 key_part_info->null_bit= 0;
1254 key_part_info->offset=hidden_null_pack_length;
1255 key_part_info->length=null_pack_length;
1256 table->setVariableWidth();
1258 (uint32_t) key_part_info->length,
1264 if (!key_part_info->field)
1266 key_part_info->field->init(table);
1267 key_part_info->key_type= 1;
1268 key_part_info->type= HA_KEYTYPE_BINARY;
1272 for (i=param->hidden_field_count, reg_field=table->getFields() + i ;
1274 i++, reg_field++, key_part_info++)
1276 key_part_info->null_bit= 0;
1277 key_part_info->field= *reg_field;
1278 key_part_info->offset= (*reg_field)->offset(table->getInsertRecord());
1279 key_part_info->length= (uint16_t) (*reg_field)->pack_length();
1287 key_part_info->store_length= key_part_info->length;
1289 if ((*reg_field)->real_maybe_null())
1290 key_part_info->store_length+= HA_KEY_NULL_LENGTH;
1291 if ((*reg_field)->type() == DRIZZLE_TYPE_BLOB ||
1292 (*reg_field)->real_type() == DRIZZLE_TYPE_VARCHAR)
1293 key_part_info->store_length+= HA_KEY_BLOB_LENGTH;
1295 key_part_info->type= (uint8_t) (*reg_field)->key_type();
1296 key_part_info->key_type =
1297 ((ha_base_keytype) key_part_info->type == HA_KEYTYPE_TEXT ||
1298 (ha_base_keytype) key_part_info->type == HA_KEYTYPE_VARTEXT1 ||
1299 (ha_base_keytype) key_part_info->type == HA_KEYTYPE_VARTEXT2) ?
1306 table->getMutableShare()->db_record_offset= 1;
1307 if (table->getShare()->db_type() == myisam_engine)
1309 if (table->create_myisam_tmp_table(param->keyinfo, param->start_recinfo,
1310 ¶m->recinfo, select_options))
1314 if (table->open_tmp_table())
1330 void Table::column_bitmaps_set(boost::dynamic_bitset<>& read_set_arg,
1331 boost::dynamic_bitset<>& write_set_arg)
1333 read_set= &read_set_arg;
1334 write_set= &write_set_arg;
1338 const boost::dynamic_bitset<> Table::use_all_columns(boost::dynamic_bitset<>& in_map)
1340 const boost::dynamic_bitset<> old= in_map;
1341 in_map= getShare()->all_set;
1345 void Table::restore_column_map(
const boost::dynamic_bitset<>& old)
1347 for (boost::dynamic_bitset<>::size_type i= 0; i < old.size(); i++)
1360 uint32_t Table::find_shortest_key(
const key_map *usable_keys)
1362 uint32_t min_length= UINT32_MAX;
1363 uint32_t best= MAX_KEY;
1364 if (usable_keys->any())
1366 for (uint32_t nr= 0; nr < getShare()->sizeKeys() ; nr++)
1368 if (usable_keys->test(nr))
1370 if (key_info[nr].key_length < min_length)
1372 min_length= key_info[nr].key_length;
1389 bool Table::compare_record(Field **ptr)
1391 for (; *ptr ; ptr++)
1393 if ((*ptr)->cmp_offset(getShare()->rec_buff_length))
1403 bool Table::records_are_comparable()
1405 return ((getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ) == 0) ||
1406 write_set->is_subset_of(*read_set));
1422 bool Table::compare_records()
1424 if (getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ) != 0)
1431 for (
Field **ptr= this->field ; *ptr != NULL; ptr++)
1434 if (write_set->test(f->position()))
1436 if (f->real_maybe_null())
1438 unsigned char null_byte_index= f->
null_ptr - record[0];
1440 if (((record[0][null_byte_index]) & f->
null_bit) !=
1441 ((record[1][null_byte_index]) & f->
null_bit))
1444 if (f->cmp_binary_offset(getShare()->rec_buff_length))
1456 if (not getShare()->blob_fields + getShare()->hasVariableWidth())
1458 return memcmp(this->getInsertRecord(), this->getUpdateRecord(), (size_t) getShare()->getRecordLength());
1461 if (memcmp(null_flags, null_flags + getShare()->rec_buff_length, getShare()->null_bytes))
1465 for (
Field **ptr= field ; *ptr ; ptr++)
1467 if (isWriteSet((*ptr)->position()) &&
1468 (*ptr)->cmp_binary_offset(getShare()->rec_buff_length))
1478 void Table::storeRecord()
1480 memcpy(getUpdateRecord(), getInsertRecord(), (
size_t) getShare()->getRecordLength());
1487 void Table::storeRecordAsInsert()
1489 assert(insert_values.size() >= getShare()->getRecordLength());
1490 memcpy(&insert_values[0], getInsertRecord(), (
size_t) getShare()->getRecordLength());
1497 void Table::storeRecordAsDefault()
1499 memcpy(getMutableShare()->getDefaultValues(), getInsertRecord(), (
size_t) getShare()->getRecordLength());
1506 void Table::restoreRecord()
1508 memcpy(getInsertRecord(), getUpdateRecord(), (
size_t) getShare()->getRecordLength());
1515 void Table::restoreRecordAsDefault()
1517 memcpy(getInsertRecord(), getMutableShare()->getDefaultValues(), (
size_t) getShare()->getRecordLength());
1524 void Table::emptyRecord()
1526 restoreRecordAsDefault();
1527 memset(null_flags, 255, getShare()->null_bytes);
1544 next_number_field(NULL),
1545 found_next_number_field(NULL),
1546 timestamp_field(NULL),
1547 pos_in_table_list(NULL),
1555 derived_select_number(0),
1556 current_lock(F_UNLCK),
1566 open_placeholder(false),
1567 locked_by_name(false),
1569 auto_increment_field_not_null(false),
1570 alias_name_used(false),
1572 quick_condition_rows(0),
1573 timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
1580 record[0]= (
unsigned char *) 0;
1581 record[1]= (
unsigned char *) 0;
1593 if (error == HA_ERR_END_OF_FILE || error == HA_ERR_KEY_NOT_FOUND)
1595 status= STATUS_GARBAGE;
1602 if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT)
1603 errmsg_printf(error::ERROR, _(
"Got error %d when reading table '%s'"),
1604 error, getShare()->getPath());
1605 print_error(error, MYF(0));
1616 status= STATUS_NO_RECORD;
1618 TableList *embedding= table_list->getEmbedding();
1619 while (!maybe_null && embedding)
1622 embedding= embedding->getEmbedding();
1624 tablenr= table_number;
1625 map= (table_map) 1 << table_number;
1627 covering_keys= getShare()->keys_for_keyread;
1643 void Table::filesort_free_buffers(
bool full)
1645 free(sort.record_pointers);
1646 sort.record_pointers=0;
1649 free(sort.sort_keys);
1653 sort.buffpek_len= 0;
1655 free(sort.addon_buf);
1656 free(sort.addon_field);
1664 bool Table::needs_reopen_or_name_lock()
const
1666 return getShare()->getVersion() != g_refresh_version;
1669 uint32_t Table::index_flags(uint32_t idx)
const
1671 return getShare()->getEngine()->index_flags(getShare()->getKeyInfo(idx).algorithm);
1674 void Table::print_error(
int error, myf errflag)
const
1676 getShare()->getEngine()->
print_error(error, errflag, *
this);
virtual uint32_t pack_length() const
virtual bool const_item() const
Field * create_tmp_field_from_field(Session *session, Field *org_field, const char *name, Table *table, Item_field *item, uint32_t convert_blob_length)
table_map map
ID bit of table (1,2,4,8,16...)
Table * create_tmp_table(Session *session, Tmp_Table_Param *param, List< Item > &fields, Order *group, bool distinct, bool save_sum_fields, uint64_t select_options, ha_rows rows_limit, const char *alias)
virtual void print_error(int error, myf errflag, const Table &table) const
int report_error(int error)
Field * create_tmp_field(Session *session, Table *table, Item *item, Item::Type type, Item ***copy_func, Field **from_field, Field **default_field, bool group, bool modify_item, bool make_copy_field, uint32_t convert_blob_length)
unsigned char * record[2]
uint32_t outer_join
Which join type.
bool force_index
prefer index over table scan
void fill_item_list(List< Item > &) const
void * multi_alloc(int unused,...)
Allocate many pointers at the same time.
drizzle_system_variables & variables
void setup_table_map(TableList *table_list, uint32_t tablenr)