mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Clean up and speed up interfaces for binary row logging
MDEV-21605 Clean up and speed up interfaces for binary row logging MDEV-21617 Bug fix for previous version of this code The intention is to have as few 'if' as possible in ha_write() and related functions. This is done by pre-calculating once per statement the row_logging state for all tables. Benefits are simpler and faster code both when binary logging is disabled and when it's enabled. Changes: - Added handler->row_logging to make it easy to check it table should be row logged. This also made it easier to disabling row logging for system, internal and temporary tables. - The tables row_logging capabilities are checked once per "statements that updates tables" in THD::binlog_prepare_for_row_logging() which is called when needed from THD::decide_logging_format(). - Removed most usage of tmp_disable_binlog(), reenable_binlog() and temporary saving and setting of thd->variables.option_bits. - Moved checks that can't change during a statement from check_table_binlog_row_based() to check_table_binlog_row_based_internal() - Removed flag row_already_logged (used by sequence engine) - Moved binlog_log_row() to a handler:: - Moved write_locked_table_maps() to THD::binlog_write_table_maps() as most other related binlog functions are in THD. - Removed binlog_write_table_map() and binlog_log_row_internal() as they are now obsolete as 'has_transactions()' is pre-calculated in prepare_for_row_logging(). - Remove 'is_transactional' argument from binlog_write_table_map() as this can now be read from handler. - Changed order of 'if's in handler::external_lock() and wsrep_mysqld.h to first evaluate fast and likely cases before more complex ones. - Added error checking in ha_write_row() and related functions if binlog_log_row() failed. - Don't clear check_table_binlog_row_based_result in clear_cached_table_binlog_row_based_flag() as it's not needed. - THD::clear_binlog_table_maps() has been replaced with THD::reset_binlog_for_next_statement() - Added 'MYSQL_OPEN_IGNORE_LOGGING_FORMAT' flag to open_and_lock_tables() to avoid calculating of binary log format for internal opens. This flag is also used to avoid reading statistics tables for internal tables. - Added OPTION_BINLOG_LOG_OFF as a simple way to turn of binlog temporary for create (instead of using THD::sql_log_bin_off. - Removed flag THD::sql_log_bin_off (not needed anymore) - Speed up THD::decide_logging_format() by remembering if blackhole engine is used and avoid a loop over all tables if it's not used (the common case). - THD::decide_logging_format() is not called anymore if no tables are used for the statement. This will speed up pure stored procedure code with about 5%+ according to some simple tests. - We now get annotated events on slave if a CREATE ... SELECT statement is transformed on the slave from statement to row logging. - In the original code, the master could come into a state where row logging is enforced for all future events if statement could be used. This is now partly fixed. Other changes: - Ensure that all tables used by a statement has query_id set. - Had to restore the row_logging flag for not used tables in THD::binlog_write_table_maps (not normal scenario) - Removed injector::transaction::use_table(server_id_type sid, table tbl) as it's not used. - Cleaned up set_slave_thread_options() - Some more DBUG_ENTER/DBUG_RETURN, code comments and minor indentation changes. - Ensure we only call THD::decide_logging_format_low() once in mysql_insert() (inefficiency). - Don't annotate INSERT DELAYED - Removed zeroing pos_in_table_list in THD::open_temporary_table() as it's already 0
This commit is contained in:
@ -610,6 +610,7 @@ given at all. */
|
||||
#define HA_CREATE_USED_SEQUENCE (1UL << 25)
|
||||
|
||||
typedef ulonglong alter_table_operations;
|
||||
typedef bool Log_func(THD*, TABLE*, bool, const uchar*, const uchar*);
|
||||
|
||||
/*
|
||||
These flags are set by the parser and describes the type of
|
||||
@ -3050,8 +3051,6 @@ public:
|
||||
bool mark_trx_read_write_done; /* mark_trx_read_write was called */
|
||||
bool check_table_binlog_row_based_done; /* check_table_binlog.. was called */
|
||||
bool check_table_binlog_row_based_result; /* cached check_table_binlog... */
|
||||
/* Set to 1 if handler logged last insert/update/delete operation */
|
||||
bool row_already_logged;
|
||||
/*
|
||||
TRUE <=> the engine guarantees that returned records are within the range
|
||||
being scanned.
|
||||
@ -3192,10 +3191,16 @@ public:
|
||||
void end_psi_batch_mode();
|
||||
|
||||
bool set_top_table_fields;
|
||||
|
||||
struct TABLE *top_table;
|
||||
Field **top_table_field;
|
||||
uint top_table_fields;
|
||||
|
||||
/* If we have row logging enabled for this table */
|
||||
bool row_logging, row_logging_init;
|
||||
/* If the row logging should be done in transaction cache */
|
||||
bool row_logging_has_trans;
|
||||
|
||||
private:
|
||||
/**
|
||||
The lock type set by when calling::ha_external_lock(). This is
|
||||
@ -3213,7 +3218,6 @@ private:
|
||||
/** Stores next_insert_id for handling duplicate key errors. */
|
||||
ulonglong m_prev_insert_id;
|
||||
|
||||
|
||||
public:
|
||||
handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
|
||||
:table_share(share_arg), table(0),
|
||||
@ -3223,7 +3227,6 @@ public:
|
||||
mark_trx_read_write_done(0),
|
||||
check_table_binlog_row_based_done(0),
|
||||
check_table_binlog_row_based_result(0),
|
||||
row_already_logged(0),
|
||||
in_range_check_pushed_down(FALSE), errkey(-1),
|
||||
key_used_on_scan(MAX_KEY),
|
||||
active_index(MAX_KEY), keyread(MAX_KEY),
|
||||
@ -3242,6 +3245,7 @@ public:
|
||||
m_psi_locker(NULL),
|
||||
set_top_table_fields(FALSE), top_table(0),
|
||||
top_table_field(0), top_table_fields(0),
|
||||
row_logging(0), row_logging_init(0),
|
||||
m_lock_type(F_UNLCK), ha_share(NULL), m_prev_insert_id(0)
|
||||
{
|
||||
DBUG_PRINT("info",
|
||||
@ -4598,13 +4602,17 @@ protected:
|
||||
virtual int delete_table(const char *name);
|
||||
|
||||
public:
|
||||
bool check_table_binlog_row_based(bool binlog_row);
|
||||
bool check_table_binlog_row_based();
|
||||
bool prepare_for_row_logging();
|
||||
int prepare_for_insert(bool force_update_handler= 0);
|
||||
int binlog_log_row(TABLE *table,
|
||||
const uchar *before_record,
|
||||
const uchar *after_record,
|
||||
Log_func *log_func);
|
||||
|
||||
inline void clear_cached_table_binlog_row_based_flag()
|
||||
{
|
||||
check_table_binlog_row_based_done= 0;
|
||||
check_table_binlog_row_based_result= 0;
|
||||
}
|
||||
private:
|
||||
/* Cache result to avoid extra calls */
|
||||
@ -4619,7 +4627,7 @@ private:
|
||||
|
||||
private:
|
||||
void mark_trx_read_write_internal();
|
||||
bool check_table_binlog_row_based_internal(bool binlog_row);
|
||||
bool check_table_binlog_row_based_internal();
|
||||
|
||||
protected:
|
||||
/*
|
||||
@ -5202,7 +5210,6 @@ int binlog_log_row(TABLE* table,
|
||||
if (unlikely(this_tracker)) \
|
||||
tracker->stop_tracking(table->in_use); \
|
||||
}
|
||||
int binlog_write_table_map(THD *thd, TABLE *table, bool with_annotate);
|
||||
void print_keydup_error(TABLE *table, KEY *key, const char *msg, myf errflag);
|
||||
void print_keydup_error(TABLE *table, KEY *key, myf errflag);
|
||||
|
||||
|
Reference in New Issue
Block a user