MCPcopy Create free account
hub / github.com/MariaDB/server / create_table_from_items

Method create_table_from_items

sql/sql_insert.cc:4896–5128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4894*/
4895
4896TABLE *select_create::create_table_from_items(THD *thd, List<Item> *items,
4897 MYSQL_LOCK **lock)
4898{
4899 TABLE tmp_table; // Used during 'Create_field()'
4900 TABLE_SHARE share;
4901 TABLE *table= 0;
4902 alter_info->select_field_count= items->elements;
4903 /* Add selected items to field list */
4904 List_iterator_fast<Item> it(*items);
4905 Item *item;
4906 bool save_table_creation_was_logged;
4907 DBUG_ENTER("select_create::create_table_from_items");
4908
4909 tmp_table.reset();
4910 tmp_table.s= &share;
4911 init_tmp_table_share(thd, &share, "", 0, "", "", true);
4912 tmp_table.in_use= thd;
4913
4914 if (!(thd->variables.option_bits & OPTION_EXPLICIT_DEF_TIMESTAMP))
4915 promote_first_timestamp_column(&alter_info->create_list);
4916
4917 while ((item=it++))
4918 {
4919 Field *tmp_field= item->create_field_for_create_select(thd->mem_root,
4920 &tmp_table);
4921
4922 if (!tmp_field)
4923 DBUG_RETURN(NULL);
4924
4925 Field *table_field;
4926
4927 switch (item->type())
4928 {
4929 /*
4930 We have to take into account both the real table's fields and
4931 pseudo-fields used in trigger's body. These fields are used
4932 to copy defaults values later inside constructor of
4933 the class Create_field.
4934 */
4935 case Item::FIELD_ITEM:
4936 case Item::TRIGGER_FIELD_ITEM:
4937 table_field= ((Item_field *) item)->field;
4938 break;
4939 default:
4940 table_field= NULL;
4941 }
4942
4943 Create_field *cr_field= new (thd->mem_root)
4944 Create_field(thd, tmp_field, table_field);
4945 /*
4946 rather inconsistently we copy constant defaults and compression
4947 from the original field, but not default expression or check constraint
4948 */
4949 if (table_field && table_field->default_value &&
4950 !table_field->default_value->expr->const_item())
4951 cr_field->default_value= 0;
4952 cr_field->check_constraint= 0;
4953

Callers

nothing calls this directly

Calls 15

init_tmp_table_shareFunction · 0.85
quick_rm_tableFunction · 0.85
table_case_nameFunction · 0.85
my_okFunction · 0.85
ddl_log_completeFunction · 0.85
mysql_lock_tablesFunction · 0.85
my_errorFunction · 0.85
mysql_unlock_tablesFunction · 0.85
drop_open_tableFunction · 0.85
fix_create_fieldsMethod · 0.80

Tested by

no test coverage detected