1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

SQL: create..select revisited [closes #370]

This commit is contained in:
Aleksey Midenkov
2017-12-12 21:30:49 +03:00
committed by GitHub
parent a0e137c4a9
commit 459f40a232
17 changed files with 619 additions and 346 deletions

View File

@ -3608,7 +3608,8 @@ select_insert::select_insert(THD *thd_arg, TABLE_LIST *table_list_par,
select_result_interceptor(thd_arg),
table_list(table_list_par), table(table_par), fields(fields_par),
autoinc_value_of_last_inserted_row(0),
insert_into_view(table_list_par && table_list_par->view != 0)
insert_into_view(table_list_par && table_list_par->view != 0),
versioned_write(false)
{
bzero((char*) &info,sizeof(info));
info.handle_duplicates= duplic;
@ -3643,6 +3644,8 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
check_insert_fields(thd, table_list, *fields, values,
!insert_into_view, 1, &map));
versioned_write= table_list->table->versioned();
if (!res && fields->elements)
{
bool saved_abort_on_warning= thd->abort_on_warning;
@ -3846,8 +3849,6 @@ int select_insert::send_data(List<Item> &values)
DBUG_RETURN(0);
thd->count_cuted_fields= CHECK_FIELD_WARN; // Calculate cuted fields
if (table->versioned())
table->vers_update_fields();
store_values(values);
if (table->default_field && table->update_default_fields(0, info.ignore))
DBUG_RETURN(1);
@ -3857,6 +3858,9 @@ int select_insert::send_data(List<Item> &values)
table->auto_increment_field_not_null= FALSE;
DBUG_RETURN(1);
}
table->vers_write= versioned_write;
if (table->versioned())
table->vers_update_fields();
if (table_list) // Not CREATE ... SELECT
{
switch (table_list->view_check_option(thd, info.ignore)) {
@ -3868,6 +3872,7 @@ int select_insert::send_data(List<Item> &values)
}
error= write_record(thd, table, &info);
table->vers_write= table->versioned();
table->auto_increment_field_not_null= FALSE;
if (!error)
@ -4141,10 +4146,7 @@ Field *Item::create_field_for_create_select(TABLE *table)
@retval 0 Error
*/
static TABLE *create_table_from_items(THD *thd,
Table_specification_st *create_info,
TABLE_LIST *create_table,
Alter_info *alter_info,
TABLE *select_create::create_table_from_items(THD *thd,
List<Item> *items,
MYSQL_LOCK **lock,
TABLEOP_HOOKS *hooks)
@ -4205,8 +4207,8 @@ static TABLE *create_table_from_items(THD *thd,
alter_info->create_list.push_back(cr_field, thd->mem_root);
}
if (create_info->vers_info.check_and_fix_implicit(
thd, alter_info, create_info, create_table->table_name))
if (create_info->vers_fix_system_fields(thd, alter_info, *create_table,
select_tables, items, &versioned_write))
{
DBUG_RETURN(NULL);
}
@ -4417,10 +4419,7 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
DEBUG_SYNC(thd,"create_table_select_before_check_if_exists");
if (!(table= create_table_from_items(thd, create_info,
create_table,
alter_info, &values,
&extra_lock, hook_ptr)))
if (!(table= create_table_from_items(thd, &values, &extra_lock, hook_ptr)))
/* abort() deletes table */
DBUG_RETURN(-1);