diff options
author | unknown <ingo@mysql.com> | 2005-01-19 21:20:55 +0100 |
---|---|---|
committer | unknown <ingo@mysql.com> | 2005-01-19 21:20:55 +0100 |
commit | ab7f56e36559d0ad234ad5760f0c4628a3c408ea (patch) | |
tree | c6d0c97d5f422270c1c63a8e94fbca2afd16bf64 /sql/sql_insert.cc | |
parent | 09aa1e07630efa7388c8b128ec3635a0aa1f4600 (diff) | |
download | mariadb-git-ab7f56e36559d0ad234ad5760f0c4628a3c408ea.tar.gz |
BUG#6034 - Error code 124: Wrong medium type.
Version for 5.0. Committed for merge.
If the result table is one of the select tables in INSERT SELECT,
we must not disable the result tables indexes before selecting.
Now the preparation is split into two prepare methods.
The first detects the situation and defers some preparations
until the second phase.
mysql-test/r/insert_select.result:
BUG#6034 - Error code 124: Wrong medium type.
The test results.
mysql-test/t/insert_select.test:
BUG#6034 - Error code 124: Wrong medium type.
The test case.
sql/sql_class.h:
BUG#6034 - Error code 124: Wrong medium type.
Added a new method for deferred preparation actions.
sql/sql_insert.cc:
BUG#6034 - Error code 124: Wrong medium type.
If the insert table is one of the select tables, a part
of the result table preparations like disabling indexes
has to be done after the select phase.
This is now done in the new method select_insert::prepare2().
sql/sql_select.cc:
BUG#6034 - Error code 124: Wrong medium type.
The result table preparation is now split into prepare() and
prepare2(). Disabling indexes and other preparation stuff
is deferred until after the selection phase.
Diffstat (limited to 'sql/sql_insert.cc')
-rw-r--r-- | sql/sql_insert.cc | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index ceb31f76953..4cb62d5e9d7 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1802,13 +1802,22 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u) thd->lex->current_select->options|= OPTION_BUFFER_RESULT; thd->lex->current_select->join->select_options|= OPTION_BUFFER_RESULT; } - + else + { + /* + We must not yet prepare the result table if it is the same as one of the + source tables (INSERT SELECT). The preparation may disable + indexes on the result table, which may be used during the select, if it + is the same table (Bug #6034). Do the preparation after the select phase + in select_insert::prepare2(). + */ + if (info.ignore || info.handle_duplicates != DUP_ERROR) + table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); + table->file->start_bulk_insert((ha_rows) 0); + } restore_record(table,s->default_values); // Get empty record table->next_number_field=table->found_next_number_field; thd->cuted_fields=0; - if (info.ignore || info.handle_duplicates != DUP_ERROR) - table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); - table->file->start_bulk_insert((ha_rows) 0); thd->no_trans_update= 0; thd->abort_on_warning= (!info.ignore && (thd->variables.sql_mode & @@ -1819,6 +1828,36 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u) } +/* + Finish the preparation of the result table. + + SYNOPSIS + select_insert::prepare2() + void + + DESCRIPTION + If the result table is the same as one of the source tables (INSERT SELECT), + the result table is not finally prepared at the join prepair phase. + Do the final preparation now. + + RETURN + 0 OK +*/ + +int select_insert::prepare2(void) +{ + DBUG_ENTER("select_insert::prepare2"); + + if (thd->lex->current_select->options & OPTION_BUFFER_RESULT) + { + if (info.ignore || info.handle_duplicates != DUP_ERROR) + table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); + table->file->start_bulk_insert((ha_rows) 0); + } + return 0; +} + + void select_insert::cleanup() { /* select_insert/select_create are never re-used in prepared statement */ |