mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
BUG#53259 Unsafe statement binlogged in statement format w/MyIsam temp tables
BUG#54872 MBR: replication failure caused by using tmp table inside transaction Changed criteria to classify a statement as unsafe in order to reduce the number of spurious warnings. So a statement is classified as unsafe when there is on-going transaction at any point of the execution if: 1. The mixed statement is about to update a transactional table and a non-transactional table. 2. The mixed statement is about to update a temporary transactional table and a non-transactional table. 3. The mixed statement is about to update a transactional table and read from a non-transactional table. 4. The mixed statement is about to update a temporary transactional table and read from a non-transactional table. 5. The mixed statement is about to update a non-transactional table and read from a transactional table when the isolation level is lower than repeatable read. After updating a transactional table if: 6. The mixed statement is about to update a non-transactional table and read from a temporary transactional table. 7. The mixed statement is about to update a non-transactional table and read from a temporary transactional table. 8. The mixed statement is about to update a non-transactionala table and read from a temporary non-transactional table. 9. The mixed statement is about to update a temporary non-transactional table and update a non-transactional table. 10. The mixed statement is about to update a temporary non-transactional table and read from a non-transactional table. 11. A statement is about to update a non-transactional table and the option variables.binlog_direct_non_trans_update is OFF. The reason for this is that locks acquired may not protected a concurrent transaction of interfering in the current execution and by consequence in the result. So the patch reduced the number of spurious unsafe warnings. Besides we fixed a regression caused by BUG#51894, which makes temporary tables to go into the trx-cache if there is an on-going transaction. In MIXED mode, the patch for BUG#51894 ignores that the trx-cache may have updates to temporary non-transactional tables that must be written to the binary log while rolling back the transaction. So we fix this problem by writing the content of the trx-cache to the binary log while rolling back a transaction if a non-transactional temporary table was updated and the binary logging format is MIXED.
This commit is contained in:
126
sql/sql_class.h
126
sql/sql_class.h
@ -1566,6 +1566,125 @@ public:
|
||||
return current_stmt_binlog_format == BINLOG_FORMAT_ROW;
|
||||
}
|
||||
|
||||
enum enum_stmt_accessed_table
|
||||
{
|
||||
/*
|
||||
If a transactional table is about to be read. Note that
|
||||
a write implies a read.
|
||||
*/
|
||||
STMT_READS_TRANS_TABLE= 0,
|
||||
/*
|
||||
If a transactional table is about to be updated.
|
||||
*/
|
||||
STMT_WRITES_TRANS_TABLE,
|
||||
/*
|
||||
If a non-transactional table is about to be read. Note that
|
||||
a write implies a read.
|
||||
*/
|
||||
STMT_READS_NON_TRANS_TABLE,
|
||||
/*
|
||||
If a non-transactional table is about to be updated.
|
||||
*/
|
||||
STMT_WRITES_NON_TRANS_TABLE,
|
||||
/*
|
||||
If a temporary transactional table is about to be read. Note
|
||||
that a write implies a read.
|
||||
*/
|
||||
STMT_READS_TEMP_TRANS_TABLE,
|
||||
/*
|
||||
If a temporary transactional table is about to be updated.
|
||||
*/
|
||||
STMT_WRITES_TEMP_TRANS_TABLE,
|
||||
/*
|
||||
If a temporary non-transactional table is about to be read. Note
|
||||
that a write implies a read.
|
||||
*/
|
||||
STMT_READS_TEMP_NON_TRANS_TABLE,
|
||||
/*
|
||||
If a temporary non-transactional table is about to be updated.
|
||||
*/
|
||||
STMT_WRITES_TEMP_NON_TRANS_TABLE,
|
||||
/*
|
||||
The last element of the enumeration. Please, if necessary add
|
||||
anything before this.
|
||||
*/
|
||||
STMT_ACCESS_TABLE_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
Sets the type of table that is about to be accessed while executing a
|
||||
statement.
|
||||
|
||||
@param accessed_table Enumeration type that defines the type of table,
|
||||
e.g. temporary, transactional, non-transactional.
|
||||
*/
|
||||
inline void set_stmt_accessed_table(enum_stmt_accessed_table accessed_table)
|
||||
{
|
||||
DBUG_ENTER("THD::set_stmt_accessed_table");
|
||||
|
||||
DBUG_ASSERT(accessed_table >= 0 && accessed_table < STMT_ACCESS_TABLE_COUNT);
|
||||
stmt_accessed_table_flag |= (1U << accessed_table);
|
||||
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
/**
|
||||
Checks if a type of table is about to be accessed while executing a
|
||||
statement.
|
||||
|
||||
@param accessed_table Enumeration type that defines the type of table,
|
||||
e.g. temporary, transactional, non-transactional.
|
||||
|
||||
@return
|
||||
@retval TRUE if the type of the table is about to be accessed
|
||||
@retval FALSE otherwise
|
||||
*/
|
||||
inline bool stmt_accessed_table(enum_stmt_accessed_table accessed_table)
|
||||
{
|
||||
DBUG_ENTER("THD::stmt_accessed_table");
|
||||
|
||||
DBUG_ASSERT(accessed_table >= 0 && accessed_table < STMT_ACCESS_TABLE_COUNT);
|
||||
|
||||
DBUG_RETURN((stmt_accessed_table_flag & (1U << accessed_table)) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
Checks if a temporary table is about to be accessed while executing a
|
||||
statement.
|
||||
|
||||
@return
|
||||
@retval TRUE if a temporary table is about to be accessed
|
||||
@retval FALSE otherwise
|
||||
*/
|
||||
inline bool stmt_accessed_temp_table()
|
||||
{
|
||||
DBUG_ENTER("THD::stmt_accessed_temp_table");
|
||||
|
||||
DBUG_RETURN((stmt_accessed_table_flag &
|
||||
((1U << STMT_READS_TEMP_TRANS_TABLE) |
|
||||
(1U << STMT_WRITES_TEMP_TRANS_TABLE) |
|
||||
(1U << STMT_READS_TEMP_NON_TRANS_TABLE) |
|
||||
(1U << STMT_WRITES_TEMP_NON_TRANS_TABLE))) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
Checks if a temporary non-transactional table is about to be accessed
|
||||
while executing a statement.
|
||||
|
||||
@return
|
||||
@retval TRUE if a temporary non-transactional table is about to be
|
||||
accessed
|
||||
@retval FALSE otherwise
|
||||
*/
|
||||
inline bool stmt_accessed_non_trans_temp_table()
|
||||
{
|
||||
DBUG_ENTER("THD::stmt_accessed_non_trans_temp_table");
|
||||
|
||||
DBUG_RETURN((stmt_accessed_table_flag &
|
||||
((1U << STMT_READS_TEMP_NON_TRANS_TABLE) |
|
||||
(1U << STMT_WRITES_TEMP_NON_TRANS_TABLE))) != 0);
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
Indicates the format in which the current statement will be
|
||||
@ -1603,6 +1722,12 @@ private:
|
||||
*/
|
||||
uint32 binlog_unsafe_warning_flags;
|
||||
|
||||
/**
|
||||
Bit field that determines the type of tables that are about to be
|
||||
be accessed while executing a statement.
|
||||
*/
|
||||
uint32 stmt_accessed_table_flag;
|
||||
|
||||
void issue_unsafe_warnings();
|
||||
|
||||
/*
|
||||
@ -2021,7 +2146,6 @@ public:
|
||||
is set if a statement accesses a temporary table created through
|
||||
CREATE TEMPORARY TABLE.
|
||||
*/
|
||||
bool thread_temporary_used;
|
||||
bool charset_is_system_charset, charset_is_collation_connection;
|
||||
bool charset_is_character_set_filesystem;
|
||||
bool enable_slow_log; /* enable slow log for current statement */
|
||||
|
Reference in New Issue
Block a user