Commit 0688c086 authored by 's avatar

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.
parent 19908377
......@@ -52,13 +52,19 @@ inc $count;
FLUSH TABLES;
source include/show_binlog_events.inc;
insert delayed into t1 values (null),(null),(null),(null);
RESET MASTER;
insert /* before delayed */ delayed /* after delayed */ into t1 values (null),(null),(null),(null);
inc $count; inc $count; inc $count; inc $count;
--source include/wait_until_rows_count.inc
insert delayed into t1 values (null),(null),(400),(null);
insert /*! delayed */ into t1 values (null),(null),(400),(null);
inc $count; inc $count; inc $count; inc $count;
--source include/wait_until_rows_count.inc
if (`SELECT @@SESSION.BINLOG_FORMAT = 'STATEMENT'`) {
FLUSH TABLES;
source include/show_binlog_events.inc;
}
select * from t1;
drop table t1;
......@@ -338,10 +338,21 @@ if (`SELECT '$CRC_RET_stmt_sidef' != ''`) {
SHOW BINLOG EVENTS;
--die Warnings printed
}
# The first event is format_description, the second is
# Query_event('BEGIN'), and the third should be our Table_map.
--let $event_type= query_get_value(SHOW BINLOG EVENTS, Event_type, 3)
if (`SELECT '$event_type' != 'Table_map'`) {
# The first event is format_description, the second is
# Query_event('BEGIN'), and the third should be our Query
# for 'INSERT DELAYED' unsafe_type 3, which is safe after
# the fix of bug#54579.
if (`SELECT $unsafe_type = 3 AND '$event_type' != 'Query'`) {
--enable_query_log
--echo ******** Failure! Event number 3 was a '$event_type', not a 'Query'. ********
SHOW BINLOG EVENTS;
--die Wrong events in binlog.
}
# The first event is format_description, the second is
# Query_event('BEGIN'), and the third should be our Table_map
# for unsafe statement.
if (`SELECT $unsafe_type != 3 AND '$event_type' != 'Table_map'`) {
--enable_query_log
--echo ******** Failure! Event number 3 was a '$event_type', not a 'Table_map'. ********
SHOW BINLOG EVENTS;
......
......@@ -1267,8 +1267,9 @@ master-bin.000001 # Table_map # # table_id: # (test.t1)
master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Query # # use `test`; FLUSH TABLES
insert delayed into t1 values (null),(null),(null),(null);
insert delayed into t1 values (null),(null),(400),(null);
RESET MASTER;
insert /* before delayed */ delayed /* after delayed */ into t1 values (null),(null),(null),(null);
insert /*! delayed */ into t1 values (null),(null),(400),(null);
select * from t1;
a
207
......
......@@ -20,12 +20,21 @@ master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; insert delayed into t1 values (300)
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Query # # use `test`; FLUSH TABLES
insert delayed into t1 values (null),(null),(null),(null);
Warnings:
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. The statement is unsafe because it uses INSERT DELAYED. This is unsafe because the times when rows are inserted cannot be predicted.
insert delayed into t1 values (null),(null),(400),(null);
Warnings:
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. The statement is unsafe because it uses INSERT DELAYED. This is unsafe because the times when rows are inserted cannot be predicted.
RESET MASTER;
insert /* before delayed */ delayed /* after delayed */ into t1 values (null),(null),(null),(null);
insert /*! delayed */ into t1 values (null),(null),(400),(null);
FLUSH TABLES;
show binlog events from <binlog_start>;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Intvar # # INSERT_ID=301
master-bin.000001 # Query # # use `test`; insert /* before delayed */ /* after delayed */ into t1 values (null),(null),(null),(null)
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Intvar # # INSERT_ID=305
master-bin.000001 # Query # # use `test`; insert /*! */ into t1 values (null),(null),(400),(null)
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Query # # use `test`; FLUSH TABLES
select * from t1;
a
207
......
......@@ -758,8 +758,9 @@ master-bin.000001 # Table_map # # table_id: # (test.t1)
master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Query # # use `test`; FLUSH TABLES
insert delayed into t1 values (null),(null),(null),(null);
insert delayed into t1 values (null),(null),(400),(null);
RESET MASTER;
insert /* before delayed */ delayed /* after delayed */ into t1 values (null),(null),(null),(null);
insert /*! delayed */ into t1 values (null),(null),(400),(null);
select * from t1;
a
207
......
......@@ -179,13 +179,13 @@ while (`SELECT $unsafe_type < 9`) {
}
if (`SELECT $unsafe_type = 3`) {
--echo ==== Testing INSERT DELAYED unsafeness ====
--echo ==== Testing INSERT DELAYED safeness after BUG#54579 is fixed ====
--let $desc_0= unsafe INSERT DELAYED statement
--let $stmt_sidef_0= INSERT DELAYED INTO t0 VALUES (1), (2)
--let $value_0=
--let $sel_sidef_0=
--let $sel_retval_0=
--let $CRC_ARG_expected_number_of_warnings= 1
--let $CRC_ARG_expected_number_of_warnings= 0
}
if (`SELECT $unsafe_type = 4`) {
......@@ -227,7 +227,7 @@ while (`SELECT $unsafe_type < 9`) {
--let $value_0=
--let $sel_sidef_0=
--let $sel_retval_0=
--let $CRC_ARG_expected_number_of_warnings= 7
--let $CRC_ARG_expected_number_of_warnings= 6
}
if (`SELECT $unsafe_type = 8`) {
......
......@@ -620,6 +620,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
......@@ -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 ||
......
......@@ -2354,8 +2354,14 @@ struct LEX: public Query_tables_list
This pointer is required to add possibly omitted DEFINER-clause to the
DDL-statement before dumping it to the binlog.
keyword_delayed_begin points to the begin of the DELAYED keyword in
INSERT DELAYED statement.
*/
const char *stmt_definition_begin;
union {
const char *stmt_definition_begin;
const char *keyword_delayed_begin;
};
const char *stmt_definition_end;
......
......@@ -10446,8 +10446,8 @@ insert_lock_option:
| LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; }
| DELAYED_SYM
{
Lex->keyword_delayed_begin= YYLIP->get_tok_start();
$$= TL_WRITE_DELAYED;
Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_INSERT_DELAYED);
}
| HIGH_PRIORITY { $$= TL_WRITE; }
;
......@@ -10456,8 +10456,8 @@ replace_lock_option:
opt_low_priority { $$= $1; }
| DELAYED_SYM
{
Lex->keyword_delayed_begin= YYLIP->get_tok_start();
$$= TL_WRITE_DELAYED;
Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_INSERT_DELAYED);
}
;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment