summaryrefslogtreecommitdiff
path: root/sql/sql_insert.cc
diff options
context:
space:
mode:
authorGuilhem Bichot <guilhem@mysql.com>2009-08-04 13:25:19 +0200
committerGuilhem Bichot <guilhem@mysql.com>2009-08-04 13:25:19 +0200
commitb57e4dbd88671df86e2cf39aff5178976d710b64 (patch)
tree32be2bfec3ca062c65566c60ecf59b673d1f97e9 /sql/sql_insert.cc
parent1a0c2153a036296785dcdfa7b5f4974515616e11 (diff)
parent94efc1c6b084ed531b513e70fb66e7b7a1186b56 (diff)
downloadmariadb-git-b57e4dbd88671df86e2cf39aff5178976d710b64.tar.gz
Creation of mysql-trunk = {summit + "Innodb plugin replacing the builtin"}:
bzr branch mysql-5.1-performance-version mysql-trunk # Summit cd mysql-trunk bzr merge mysql-5.1-innodb_plugin # which is 5.1 + Innodb plugin bzr rm innobase # remove the builtin Next step: build, test fixes.
Diffstat (limited to 'sql/sql_insert.cc')
-rw-r--r--sql/sql_insert.cc83
1 files changed, 67 insertions, 16 deletions
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 9eef9d224e6..77b83b0e6fe 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -301,9 +301,7 @@ static int check_update_fields(THD *thd, TABLE_LIST *insert_table_list,
List<Item> &update_fields, table_map *map)
{
TABLE *table= insert_table_list->table;
- my_bool timestamp_mark;
-
- LINT_INIT(timestamp_mark);
+ my_bool timestamp_mark= 0;
if (table->timestamp_field)
{
@@ -393,7 +391,7 @@ void upgrade_lock_type(THD *thd, thr_lock_type *lock_type,
bool is_multi_insert)
{
if (duplic == DUP_UPDATE ||
- duplic == DUP_REPLACE && *lock_type == TL_WRITE_CONCURRENT_INSERT)
+ (duplic == DUP_REPLACE && *lock_type == TL_WRITE_CONCURRENT_INSERT))
{
*lock_type= TL_WRITE_DEFAULT;
return;
@@ -858,11 +856,13 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
*/
query_cache_invalidate3(thd, table_list, 1);
}
- if (changed && error <= 0 || thd->transaction.stmt.modified_non_trans_table
- || was_insert_delayed)
+ if ((changed && error <= 0) ||
+ thd->transaction.stmt.modified_non_trans_table ||
+ was_insert_delayed)
{
if (mysql_bin_log.is_open())
{
+ int errcode= 0;
if (error <= 0)
{
/*
@@ -877,6 +877,9 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
/* todo: consider removing */
thd->clear_error();
}
+ else
+ errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
+
/* bug#22725:
A query which per-row-loop can not be interrupted with
@@ -893,8 +896,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
if (thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length,
transactional_table, FALSE,
- (error>0) ? thd->killed : THD::NOT_KILLED) &&
- transactional_table)
+ errcode))
{
error=1;
}
@@ -1114,6 +1116,33 @@ static bool mysql_prepare_insert_check_table(THD *thd, TABLE_LIST *table_list,
/*
+ Get extra info for tables we insert into
+
+ @param table table(TABLE object) we insert into,
+ might be NULL in case of view
+ @param table(TABLE_LIST object) or view we insert into
+*/
+
+static void prepare_for_positional_update(TABLE *table, TABLE_LIST *tables)
+{
+ if (table)
+ {
+ if(table->reginfo.lock_type != TL_WRITE_DELAYED)
+ table->prepare_for_position();
+ return;
+ }
+
+ DBUG_ASSERT(tables->view);
+ List_iterator<TABLE_LIST> it(*tables->view_tables);
+ TABLE_LIST *tbl;
+ while ((tbl= it++))
+ prepare_for_positional_update(tbl->table, tbl);
+
+ return;
+}
+
+
+/*
Prepare items in INSERT statement
SYNOPSIS
@@ -1262,9 +1291,8 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
Only call prepare_for_posistion() if we are not performing a DELAYED
operation. It will instead be executed by delayed insert thread.
*/
- if ((duplic == DUP_UPDATE || duplic == DUP_REPLACE) &&
- (table->reginfo.lock_type != TL_WRITE_DELAYED))
- table->prepare_for_position();
+ if (duplic == DUP_UPDATE || duplic == DUP_REPLACE)
+ prepare_for_positional_update(table, table_list);
DBUG_RETURN(FALSE);
}
@@ -2667,6 +2695,12 @@ bool Delayed_insert::handle_inserts(void)
thd.variables.time_zone = row->time_zone;
}
+ /* if the delayed insert was killed, the killed status is
+ ignored while binlogging */
+ int errcode= 0;
+ if (thd.killed == THD::NOT_KILLED)
+ errcode= query_error_code(&thd, TRUE);
+
/*
If the query has several rows to insert, only the first row will come
here. In row-based binlogging, this means that the first row will be
@@ -2677,7 +2711,7 @@ bool Delayed_insert::handle_inserts(void)
*/
thd.binlog_query(THD::ROW_QUERY_TYPE,
row->query.str, row->query.length,
- FALSE, FALSE);
+ FALSE, FALSE, errcode);
thd.time_zone_used = backup_time_zone_used;
thd.variables.time_zone = backup_time_zone;
@@ -3090,7 +3124,10 @@ bool select_insert::send_data(List<Item> &values)
store_values(values);
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
if (thd->is_error())
+ {
+ table->auto_increment_field_not_null= FALSE;
DBUG_RETURN(1);
+ }
if (table_list) // Not CREATE ... SELECT
{
switch (table_list->view_check_option(thd, info.ignore)) {
@@ -3104,6 +3141,9 @@ bool select_insert::send_data(List<Item> &values)
// Release latches in case bulk insert takes a long time
ha_release_temporary_latches(thd);
+ // Release latches in case bulk insert takes a long time
+ ha_release_temporary_latches(thd);
+
error= write_record(thd, table, &info);
table->auto_increment_field_not_null= FALSE;
@@ -3176,7 +3216,8 @@ bool select_insert::send_eof()
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
- if (changed= (info.copied || info.deleted || info.updated))
+ changed= (info.copied || info.deleted || info.updated);
+ if (changed)
{
/*
We must invalidate the table in the query cache before binlog writing
@@ -3197,11 +3238,14 @@ bool select_insert::send_eof()
*/
if (mysql_bin_log.is_open())
{
+ int errcode= 0;
if (!error)
thd->clear_error();
+ else
+ errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length,
- trans_table, FALSE, killed_status);
+ trans_table, FALSE, errcode);
}
table->file->ha_release_auto_increment();
@@ -3268,8 +3312,11 @@ void select_insert::abort() {
if (thd->transaction.stmt.modified_non_trans_table)
{
if (mysql_bin_log.is_open())
+ {
+ int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query, thd->query_length,
- transactional_table, FALSE);
+ transactional_table, FALSE, errcode);
+ }
if (!thd->current_stmt_binlog_row_based && !can_rollback_data())
thd->transaction.all.modified_non_trans_table= TRUE;
if (changed)
@@ -3661,10 +3708,14 @@ select_create::binlog_show_create_table(TABLE **tables, uint count)
DBUG_ASSERT(result == 0); /* store_create_info() always return 0 */
if (mysql_bin_log.is_open())
+ {
+ int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
thd->binlog_query(THD::STMT_QUERY_TYPE,
query.ptr(), query.length(),
/* is_trans */ TRUE,
- /* suppress_use */ FALSE);
+ /* suppress_use */ FALSE,
+ errcode);
+ }
}
void select_create::store_values(List<Item> &values)