summaryrefslogtreecommitdiff
path: root/sql/sql_insert.cc
diff options
context:
space:
mode:
author <Dao-Gang.Qu@sun.com>2010-08-30 14:03:28 +0800
committer <Dao-Gang.Qu@sun.com>2010-08-30 14:03:28 +0800
commit0688c086a0739333bf642f77f85f9f36cc0dcbef (patch)
tree312b96bab339ccfd6d986901ceed2fe87e7ccb8d /sql/sql_insert.cc
parent19908377b81d867e65b01c4cfdc8ae28ebe7c846 (diff)
downloadmariadb-git-0688c086a0739333bf642f77f85f9f36cc0dcbef.tar.gz
Bug #54579 Wrong unsafe warning for INSERT DELAYED in SBR
The lock_type is upgrade to TL_WRITE from TL_WRITE_DELAYED for INSERT DELAYED when inserting multi values in one statement. It's safe. But it causes an unsafe warning in SBR. Make INSERT DELAYED safe by logging it as INSERT without DELAYED.
Diffstat (limited to 'sql/sql_insert.cc')
-rw-r--r--sql/sql_insert.cc51
1 files changed, 46 insertions, 5 deletions
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 5f6ab43e2ea..adbdc1ffbc8 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -621,6 +621,32 @@ bool open_and_lock_for_insert_delayed(THD *thd, TABLE_LIST *table_list)
/**
+ Create a new query string for removing DELAYED keyword for
+ multi INSERT DEALAYED statement.
+
+ @param[in] thd Thread handler
+ @param[in] buf Query string
+
+ @return
+ 0 ok
+ 1 error
+*/
+static int
+create_insert_stmt_from_insert_delayed(THD *thd, String *buf)
+{
+ /* Append the part of thd->query before "DELAYED" keyword */
+ if (buf->append(thd->query(),
+ thd->lex->keyword_delayed_begin - thd->query()))
+ return 1;
+ /* Append the part of thd->query after "DELAYED" keyword */
+ if (buf->append(thd->lex->keyword_delayed_begin + 7))
+ return 1;
+
+ return 0;
+}
+
+
+/**
INSERT statement implementation
@note Like implementations of other DDL/DML in MySQL, this function
@@ -999,13 +1025,28 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
such case the flag is ignored for constructing binlog event.
*/
DBUG_ASSERT(thd->killed != THD::KILL_BAD_DATA || error > 0);
- if (thd->binlog_query(THD::ROW_QUERY_TYPE,
- thd->query(), thd->query_length(),
- transactional_table, FALSE, FALSE,
- errcode))
+ if (was_insert_delayed && table_list->lock_type == TL_WRITE)
{
+ /* Binlog multi INSERT DELAYED as INSERT without DELAYED. */
+ String log_query;
+ if (create_insert_stmt_from_insert_delayed(thd, &log_query))
+ {
+ sql_print_error("Event Error: An error occurred while creating query string"
+ "for INSERT DELAYED stmt, before writing it into binary log.");
+
+ error= 1;
+ }
+ else if (thd->binlog_query(THD::ROW_QUERY_TYPE,
+ log_query.c_ptr(), log_query.length(),
+ transactional_table, FALSE, FALSE,
+ errcode))
+ error= 1;
+ }
+ else if (thd->binlog_query(THD::ROW_QUERY_TYPE,
+ thd->query(), thd->query_length(),
+ transactional_table, FALSE, FALSE,
+ errcode))
error= 1;
- }
}
}
DBUG_ASSERT(transactional_table || !changed ||