Below is the list of changes that have just been committed into a local
5.1 repository of mats. When mats does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2007-05-14 14:45:38+02:00, mats@stripped +13 -0
WL#3339 (Issue warnings when statement-based replication may fail):
Replacing binlog_row_based_if_mixed with variable binlog_stmt_flags
holding several flags and adding member functions to manipulate the
flags.
Added code to generate a warning when an attempt to log an unsafe
statement to the binary log was made. The warning is both pushed to the
SHOW WARNINGS table and written to the error log. The prevent flooding
the error log, the warning is just written to the error log once per
open session.
mysql-test/r/binlog_unsafe.result@stripped, 2007-05-14 14:45:35+02:00, mats@stripped +13 -0
New BitKeeper file ``mysql-test/r/binlog_unsafe.result''
mysql-test/r/binlog_unsafe.result@stripped, 2007-05-14 14:45:35+02:00, mats@stripped +0 -0
mysql-test/t/binlog_unsafe.test@stripped, 2007-05-14 14:45:35+02:00, mats@stripped +16 -0
New BitKeeper file ``mysql-test/t/binlog_unsafe.test''
mysql-test/t/binlog_unsafe.test@stripped, 2007-05-14 14:45:35+02:00, mats@stripped +0 -0
sql/item_create.cc@stripped, 2007-05-14 14:45:34+02:00, mats@stripped +2 -2
Using {is,set,clear}_stmt_unsafe() member functions instead of
binlog_row_based_if_mixed member variable.
sql/share/errmsg.txt@stripped, 2007-05-14 14:45:35+02:00, mats@stripped +3 -0
Adding error message to indicate that an attempt to log an unsafe
statement was made.
sql/sp_head.cc@stripped, 2007-05-14 14:45:34+02:00, mats@stripped +1 -1
Using {is,set,clear}_stmt_unsafe() member functions instead of
binlog_row_based_if_mixed member variable.
sql/sp_head.h@stripped, 2007-05-14 14:45:34+02:00, mats@stripped +1 -1
Using {is,set,clear}_stmt_unsafe() member functions instead of
binlog_row_based_if_mixed member variable.
sql/sql_base.cc@stripped, 2007-05-14 14:45:34+02:00, mats@stripped +2 -2
Using {is,set,clear}_stmt_unsafe() member functions instead of
binlog_row_based_if_mixed member variable.
sql/sql_class.cc@stripped, 2007-05-14 14:45:34+02:00, mats@stripped +18 -1
Adding THD::binlog_flags to store thread-specific binary log state.
Adding code to push a warning and write an entry into the error log
when an attempt is made to log an unsafe statement.
sql/sql_class.h@stripped, 2007-05-14 14:45:34+02:00, mats@stripped +12 -0
Adding THD::binlog_flags to store thread-specific binary log state.
Adding BINLOG_FLAG_UNSAFE_STMT_PRINTED to denote that a warning for
an unsafe statement has already been generated for this thread.
sql/sql_insert.cc@stripped, 2007-05-14 14:45:34+02:00, mats@stripped +1 -0
Using {is,set,clear}_stmt_unsafe() member functions instead of
binlog_row_based_if_mixed member variable.
sql/sql_lex.cc@stripped, 2007-05-14 14:45:34+02:00, mats@stripped +1 -1
Replacing binlog_row_based_if_mixed with a variable binlog_stmt_flags
holding several flags.
sql/sql_lex.h@stripped, 2007-05-14 14:45:34+02:00, mats@stripped +36 -8
Replacing binlog_row_based_if_mixed with a variable binlog_stmt_flags
holding several flags.
sql/sql_view.cc@stripped, 2007-05-14 14:45:35+02:00, mats@stripped +2 -2
Using {is,set,clear}_stmt_unsafe() member functions instead of
binlog_row_based_if_mixed member variable.
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: mats
# Host: romeo.kindahl.net
# Root: /home/bk/w3339-mysql-5.1-rpl
--- 1.76/sql/item_create.cc 2007-05-14 14:45:46 +02:00
+++ 1.77/sql/item_create.cc 2007-05-14 14:45:46 +02:00
@@ -2341,7 +2341,7 @@
if (item_list != NULL)
arg_count= item_list->elements;
- thd->lex->binlog_row_based_if_mixed= TRUE;
+ thd->lex->set_stmt_unsafe();
DBUG_ASSERT( (udf->type == UDFTYPE_FUNCTION)
|| (udf->type == UDFTYPE_AGGREGATE));
@@ -4527,7 +4527,7 @@
Item*
Create_func_uuid::create(THD *thd)
{
- thd->lex->binlog_row_based_if_mixed= TRUE;
+ thd->lex->set_stmt_unsafe();
return new (thd->mem_root) Item_func_uuid();
}
--- 1.396/sql/sql_base.cc 2007-05-14 14:45:47 +02:00
+++ 1.397/sql/sql_base.cc 2007-05-14 14:45:47 +02:00
@@ -3591,7 +3591,7 @@
/*
CREATE ... SELECT UUID() locks no tables, we have to test here.
*/
- if (thd->lex->binlog_row_based_if_mixed)
+ if (thd->lex->is_stmt_unsafe())
thd->set_current_stmt_binlog_row_based_if_mixed();
if (!tables && !thd->lex->requires_prelocking())
@@ -3632,7 +3632,7 @@
if (thd->variables.binlog_format == BINLOG_FORMAT_MIXED &&
has_two_write_locked_tables_with_auto_increment(tables))
{
- thd->lex->binlog_row_based_if_mixed= TRUE;
+ thd->lex->set_stmt_unsafe();
thd->set_current_stmt_binlog_row_based_if_mixed();
}
}
--- 1.331/sql/sql_class.cc 2007-05-14 14:45:47 +02:00
+++ 1.332/sql/sql_class.cc 2007-05-14 14:45:47 +02:00
@@ -201,7 +201,7 @@
Open_tables_state(refresh_version), rli_fake(0),
lock_id(&main_lock_id),
user_time(0), in_sub_stmt(0),
- binlog_table_maps(0),
+ binlog_table_maps(0), binlog_flags(0UL),
global_read_lock(0), is_fatal_error(0),
rand_used(0), time_zone_used(0),
arg_of_last_insert_id_function(FALSE),
@@ -2888,6 +2888,23 @@
to how you treat this.
*/
case THD::STMT_QUERY_TYPE:
+ if (lex->is_stmt_unsafe())
+ {
+ DBUG_ASSERT(this->query != NULL);
+ push_warning(this, MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_BINLOG_UNSAFE_STATEMENT,
+ ER(ER_BINLOG_UNSAFE_STATEMENT));
+ if (!(binlog_flags & BINLOG_FLAG_UNSAFE_STMT_PRINTED))
+ {
+
+ char warn_buf[MYSQL_ERRMSG_SIZE];
+ my_snprintf(warn_buf, MYSQL_ERRMSG_SIZE, "%s Statement: %s",
+ ER(ER_BINLOG_UNSAFE_STATEMENT), this->query);
+ sql_print_warning(warn_buf);
+ binlog_flags|= BINLOG_FLAG_UNSAFE_STMT_PRINTED;
+ }
+ }
+
/*
The MYSQL_LOG::write() function will set the STMT_END_F flag and
flush the pending rows event if necessary.
--- 1.354/sql/sql_class.h 2007-05-14 14:45:47 +02:00
+++ 1.355/sql/sql_class.h 2007-05-14 14:45:47 +02:00
@@ -1048,6 +1048,17 @@
private:
uint binlog_table_maps; // Number of table maps currently in the binlog
+
+ enum enum_binlog_flag {
+ BINLOG_FLAG_UNSAFE_STMT_PRINTED,
+ BINLOG_FLAG_COUNT
+ };
+
+ /**
+ Flags with per-thread information regarding the status of the
+ binary log.
+ */
+ uint32 binlog_flags;
public:
uint get_binlog_table_maps() const {
return binlog_table_maps;
@@ -1599,6 +1610,7 @@
void restore_sub_statement_state(Sub_statement_state *backup);
void set_n_backup_active_arena(Query_arena *set, Query_arena *backup);
void restore_active_arena(Query_arena *set, Query_arena *backup);
+
inline void set_current_stmt_binlog_row_based_if_mixed()
{
/*
--- 1.261/sql/sql_insert.cc 2007-05-14 14:45:47 +02:00
+++ 1.262/sql/sql_insert.cc 2007-05-14 14:45:47 +02:00
@@ -1533,6 +1533,7 @@
Statement-based replication of INSERT DELAYED has problems with RAND()
and user vars, so in mixed mode we go to row-based.
*/
+ thd.lex->set_stmt_unsafe();
thd.set_current_stmt_binlog_row_based_if_mixed();
bzero((char*) &thd.net, sizeof(thd.net)); // Safety
--- 1.236/sql/sql_lex.cc 2007-05-14 14:45:47 +02:00
+++ 1.237/sql/sql_lex.cc 2007-05-14 14:45:47 +02:00
@@ -1719,7 +1719,7 @@
sroutines_list.empty();
sroutines_list_own_last= sroutines_list.next;
sroutines_list_own_elements= 0;
- binlog_row_based_if_mixed= FALSE;
+ binlog_stmt_flags= 0;
}
--- 1.271/sql/sql_lex.h 2007-05-14 14:45:47 +02:00
+++ 1.272/sql/sql_lex.h 2007-05-14 14:45:47 +02:00
@@ -910,14 +910,6 @@
uint sroutines_list_own_elements;
/*
- Tells if the parsing stage detected that some items require row-based
- binlogging to give a reliable binlog/replication, or if we will use
- stored functions or triggers which themselves need require row-based
- binlogging.
- */
- bool binlog_row_based_if_mixed;
-
- /*
These constructor and destructor serve for creation/destruction
of Query_tables_list instances which are used as backup storage.
*/
@@ -964,6 +956,41 @@
query_tables_own_last= 0;
}
}
+
+ /**
+ Has the parser/scanner detected that this statement is unsafe?
+ */
+ inline bool is_stmt_unsafe() const {
+ return binlog_stmt_flags & (1U << BINLOG_STMT_FLAG_UNSAFE);
+ }
+
+ /**
+ Flag the current (top-level) statement as unsafe.
+
+ The flag will be reset after the statement has finished.
+
+ */
+ inline void set_stmt_unsafe() {
+ binlog_stmt_flags|= (1U << BINLOG_STMT_FLAG_UNSAFE);
+ }
+
+ inline void clear_stmt_unsafe() {
+ binlog_stmt_flags&= ~(1U << BINLOG_STMT_FLAG_UNSAFE);
+ }
+
+private:
+ enum enum_binlog_stmt_flag {
+ BINLOG_STMT_FLAG_UNSAFE,
+ BINLOG_STMT_FLAG_COUNT
+ };
+
+ /*
+ Tells if the parsing stage detected properties of the statement,
+ for example: that some items require row-based binlogging to give
+ a reliable binlog/replication, or if we will use stored functions
+ or triggers which themselves need require row-based binlogging.
+ */
+ uint32 binlog_stmt_flags;
};
@@ -1299,6 +1326,7 @@
void restore_backup_query_tables_list(Query_tables_list *backup);
bool table_or_sp_used();
+
} LEX;
struct st_lex_local: public st_lex
--- 1.154/sql/share/errmsg.txt 2007-05-14 14:45:47 +02:00
+++ 1.155/sql/share/errmsg.txt 2007-05-14 14:45:47 +02:00
@@ -6059,3 +6059,6 @@
eng "The incident %s occured on the master. Message: %-.64s"
ER_NO_PARTITION_FOR_GIVEN_VALUE_SILENT
eng "Table has no partition for some existing values"
+ER_BINLOG_UNSAFE_STATEMENT
+ eng "Statement is not safe to log in statement format."
--- 1.129/sql/sql_view.cc 2007-05-14 14:45:47 +02:00
+++ 1.130/sql/sql_view.cc 2007-05-14 14:45:47 +02:00
@@ -1114,8 +1114,8 @@
If the view's body needs row-based binlogging (e.g. the VIEW is created
from SELECT UUID()), the top statement also needs it.
*/
- if (lex->binlog_row_based_if_mixed)
- old_lex->binlog_row_based_if_mixed= TRUE;
+ if (lex->is_stmt_unsafe())
+ old_lex->set_stmt_unsafe();
view_is_mergeable= (table->algorithm != VIEW_ALGORITHM_TMPTABLE &&
lex->can_be_merged());
LINT_INIT(view_main_select_tables);
--- New file ---
+++ mysql-test/r/binlog_unsafe.result 07/05/14 14:45:35
SET BINLOG_FORMAT=STATEMENT;
CREATE TABLE t1 (a CHAR(40));
CREATE TABLE t2 (a INT AUTO_INCREMENT PRIMARY KEY);
CREATE TABLE t3 (b INT AUTO_INCREMENT PRIMARY KEY);
CREATE VIEW v1(a,b) AS SELECT a,b FROM t2,t3;
INSERT INTO t1 SELECT UUID();
Warnings:
Warning 1588 Statement is not safe to log in statement format.
SHOW WARNINGS;
Level Warning
Code 1588
Message Statement is not safe to log in statement format.
DROP TABLE t1;
--- New file ---
+++ mysql-test/t/binlog_unsafe.test 07/05/14 14:45:35
# Test to check that a warning is generated for unsafe statements
# executed under statement mode logging.
SET BINLOG_FORMAT=STATEMENT;
CREATE TABLE t1 (a CHAR(40));
CREATE TABLE t2 (a INT AUTO_INCREMENT PRIMARY KEY);
CREATE TABLE t3 (b INT AUTO_INCREMENT PRIMARY KEY);
CREATE VIEW v1(a,b) AS SELECT a,b FROM t2,t3;
INSERT INTO t1 SELECT UUID();
query_vertical SHOW WARNINGS;
DROP TABLE t1;
--- 1.265/sql/sp_head.cc 2007-05-14 14:45:47 +02:00
+++ 1.266/sql/sp_head.cc 2007-05-14 14:45:47 +02:00
@@ -1873,7 +1873,7 @@
cannot switch from statement-based to row-based only for this
substatement).
*/
- if (sublex->binlog_row_based_if_mixed)
+ if (sublex->is_stmt_unsafe())
m_flags|= BINLOG_ROW_BASED_IF_MIXED;
/*
--- 1.103/sql/sp_head.h 2007-05-14 14:45:47 +02:00
+++ 1.104/sql/sp_head.h 2007-05-14 14:45:47 +02:00
@@ -379,7 +379,7 @@
the substatements not).
*/
if (m_flags & BINLOG_ROW_BASED_IF_MIXED)
- lex->binlog_row_based_if_mixed= TRUE;
+ lex->set_stmt_unsafe();
}
| Thread |
|---|
| • bk commit into 5.1 tree (mats:1.2578) | Mats Kindahl | 14 May |