cleanup: consolidate binlog-related THD::*_used into one bitmap

This commit is contained in:
Sergei Golubchik 2022-07-03 17:35:27 +02:00 committed by Oleksandr Byelkin
parent 4ce1470a70
commit c38b8f49b8
15 changed files with 61 additions and 72 deletions

View File

@ -775,7 +775,7 @@ bool Item_func_connection_id::fix_fields(THD *thd, Item **ref)
{
if (Item_int_func::fix_fields(thd, ref))
return TRUE;
thd->thread_specific_used= TRUE;
thd->used|= THD::THREAD_SPECIFIC_USED;
value= thd->variables.pseudo_thread_id;
return FALSE;
}
@ -2818,9 +2818,9 @@ bool Item_func_rand::fix_fields(THD *thd,Item **ref)
Once events are forwarded rather than recreated,
the following can be skipped if inside the slave thread
*/
if (!thd->rand_used)
if (!(thd->used & THD::RAND_USED))
{
thd->rand_used= 1;
thd->used|= THD::RAND_USED;
thd->rand_saved_seed1= thd->rand.seed1;
thd->rand_saved_seed2= thd->rand.seed2;
}

View File

@ -1509,7 +1509,7 @@ bool Item_func_from_days::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzz
void Item_func_curdate_local::store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)
{
thd->variables.time_zone->gmt_sec_to_TIME(now_time, thd->query_start());
thd->time_zone_used= 1;
thd->used |= THD::TIME_ZONE_USED;
}
@ -1601,7 +1601,7 @@ void Item_func_curtime_local::store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)
now_time->year= now_time->month= now_time->day= 0;
now_time->time_type= MYSQL_TIMESTAMP_TIME;
set_sec_part(thd->query_start_sec_part(), now_time, this);
thd->time_zone_used= 1;
thd->used|= THD::TIME_ZONE_USED;
}
@ -1667,7 +1667,7 @@ void Item_func_now_local::store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)
{
thd->variables.time_zone->gmt_sec_to_TIME(now_time, thd->query_start());
set_sec_part(thd->query_start_sec_part(), now_time, this);
thd->time_zone_used= 1;
thd->used|= THD::TIME_ZONE_USED;
}
@ -1710,7 +1710,7 @@ void Item_func_sysdate_local::store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)
my_hrtime_t now= my_hrtime();
thd->variables.time_zone->gmt_sec_to_TIME(now_time, hrtime_to_my_time(now));
set_sec_part(hrtime_sec_part(now), now_time, this);
thd->time_zone_used= 1;
thd->used|= THD::TIME_ZONE_USED;
}
@ -2732,7 +2732,7 @@ null_date:
bool Item_func_from_unixtime::fix_length_and_dec(THD *thd)
{
thd->time_zone_used= 1;
thd->used|= THD::TIME_ZONE_USED;
tz= thd->variables.time_zone;
Type_std_attributes::set(
Type_temporal_attributes_not_fixed_dec(MAX_DATETIME_WIDTH,

View File

@ -834,14 +834,13 @@ bool Log_to_csv_event_handler::
uint field_index;
Silence_log_table_errors error_handler;
Open_tables_backup open_tables_backup;
bool save_time_zone_used;
THD::used_t save_time_zone_used= thd->used & THD::TIME_ZONE_USED;
DBUG_ENTER("log_general");
/*
CSV uses TIME_to_timestamp() internally if table needs to be repaired
which will set thd->time_zone_used
which will set TIME_ZONE_USED
*/
save_time_zone_used= thd->time_zone_used;
table_list.init_one_table(&MYSQL_SCHEMA_NAME, &GENERAL_LOG_NAME, 0,
TL_WRITE_CONCURRENT_INSERT);
@ -942,7 +941,7 @@ err:
if (need_close)
close_log_table(thd, &open_tables_backup);
thd->time_zone_used= save_time_zone_used;
thd->used= (thd->used & ~THD::TIME_ZONE_USED) | save_time_zone_used;
DBUG_RETURN(result);
}
@ -989,7 +988,7 @@ bool Log_to_csv_event_handler::
Silence_log_table_errors error_handler;
Open_tables_backup open_tables_backup;
CHARSET_INFO *client_cs= thd->variables.character_set_client;
bool save_time_zone_used;
THD::used_t save_time_zone_used= thd->used & THD::TIME_ZONE_USED;
ulong query_time= (ulong) MY_MIN(query_utime/1000000, TIME_MAX_VALUE_SECONDS);
ulong lock_time= (ulong) MY_MIN(lock_utime/1000000, TIME_MAX_VALUE_SECONDS);
ulong query_time_micro= (ulong) (query_utime % 1000000);
@ -997,11 +996,6 @@ bool Log_to_csv_event_handler::
DBUG_ENTER("Log_to_csv_event_handler::log_slow");
thd->push_internal_handler(& error_handler);
/*
CSV uses TIME_to_timestamp() internally if table needs to be repaired
which will set thd->time_zone_used
*/
save_time_zone_used= thd->time_zone_used;
table_list.init_one_table(&MYSQL_SCHEMA_NAME, &SLOW_LOG_NAME, 0,
TL_WRITE_CONCURRENT_INSERT);
@ -1129,7 +1123,7 @@ err:
}
if (need_close)
close_log_table(thd, &open_tables_backup);
thd->time_zone_used= save_time_zone_used;
thd->used= (thd->used & ~THD::TIME_ZONE_USED) | save_time_zone_used;
DBUG_RETURN(result);
}
@ -6853,7 +6847,7 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info, my_bool *with_annotate)
if (write_event(&e, cache_data, file))
goto err;
}
if (thd->rand_used)
if (thd->used & THD::RAND_USED)
{
Rand_log_event e(thd,thd->rand_saved_seed1,thd->rand_saved_seed2,
using_trans, direct);

View File

@ -1289,7 +1289,7 @@ bool Query_log_event::write()
}
}
if (thd && thd->query_start_sec_part_used)
if (thd && (thd->used & THD::QUERY_START_SEC_PART_USED))
{
*start++= Q_HRNOW;
get_time();
@ -1415,8 +1415,8 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
bool direct, bool suppress_use, int errcode)
:Log_event(thd_arg,
(thd_arg->thread_specific_used ? LOG_EVENT_THREAD_SPECIFIC_F :
0) |
((thd_arg->used & THD::THREAD_SPECIFIC_USED)
? LOG_EVENT_THREAD_SPECIFIC_F : 0) |
(suppress_use ? LOG_EVENT_SUPPRESS_USE_F : 0),
using_trans),
data_buf(0), query(query_arg), catalog(thd_arg->catalog),
@ -1502,7 +1502,7 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
int2store(charset, thd_arg->variables.character_set_client->number);
int2store(charset+2, thd_arg->variables.collation_connection->number);
int2store(charset+4, thd_arg->variables.collation_server->number);
if (thd_arg->time_zone_used)
if (thd_arg->used & THD::TIME_ZONE_USED)
{
/*
Note that our event becomes dependent on the Time_zone object
@ -2951,7 +2951,8 @@ Load_log_event::Load_log_event(THD *thd_arg, const sql_exchange *ex,
enum enum_duplicates handle_dup,
bool ignore, bool using_trans)
:Log_event(thd_arg,
thd_arg->thread_specific_used ? LOG_EVENT_THREAD_SPECIFIC_F : 0,
(thd_arg->used & THD::THREAD_SPECIFIC_USED)
? LOG_EVENT_THREAD_SPECIFIC_F : 0,
using_trans),
thread_id(thd_arg->thread_id),
slave_proxy_id((ulong)thd_arg->variables.pseudo_thread_id),

View File

@ -687,8 +687,7 @@ bool AUTHID::read_from_mysql_proc_row(THD *thd, TABLE *table)
*/
int
Sp_handler::db_find_routine(THD *thd,
const Database_qualified_name *name,
Sp_handler::db_find_routine(THD *thd, const Database_qualified_name *name,
sp_head **sphp) const
{
TABLE *table;
@ -697,7 +696,7 @@ Sp_handler::db_find_routine(THD *thd,
longlong created;
longlong modified;
Sp_chistics chistics;
bool saved_time_zone_used= thd->time_zone_used;
THD::used_t saved_time_zone_used= thd->used & THD::TIME_ZONE_USED;
bool trans_commited= 0;
sql_mode_t sql_mode;
Stored_program_creation_ctx *creation_ctx;
@ -763,15 +762,14 @@ Sp_handler::db_find_routine(THD *thd,
thd->commit_whole_transaction_and_close_tables();
new_trans.restore_old_transaction();
ret= db_load_routine(thd, name, sphp,
sql_mode, params, returns, body, chistics, definer,
created, modified, NULL, creation_ctx);
ret= db_load_routine(thd, name, sphp, sql_mode, params, returns, body,
chistics, definer, created, modified, NULL, creation_ctx);
done:
/*
Restore the time zone flag as the timezone usage in proc table
does not affect replication.
*/
thd->time_zone_used= saved_time_zone_used;
thd->used= (thd->used & ~THD::TIME_ZONE_USED) | saved_time_zone_used;
if (!trans_commited)
{
if (table)

View File

@ -635,7 +635,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
protocol_text(this), protocol_binary(this), initial_status_var(0),
m_current_stage_key(0), m_psi(0),
in_sub_stmt(0), log_all_errors(0),
binlog_unsafe_warning_flags(0),
binlog_unsafe_warning_flags(0), used(0),
current_stmt_binlog_format(BINLOG_FORMAT_MIXED),
bulk_param(0),
table_map_for_update(0),
@ -655,8 +655,6 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
is_fatal_error(0),
transaction_rollback_request(0),
is_fatal_sub_stmt_error(false),
rand_used(0),
time_zone_used(0),
in_lock_tables(0),
bootstrap(0),
derived_tables_processing(FALSE),
@ -769,11 +767,10 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
security_ctx= &main_security_ctx;
no_errors= 0;
password= 0;
query_start_sec_part_used= 0;
count_cuted_fields= CHECK_FIELD_IGNORE;
killed= NOT_KILLED;
killed_err= 0;
is_slave_error= thread_specific_used= FALSE;
is_slave_error= FALSE;
my_hash_clear(&handler_tables_hash);
my_hash_clear(&ull_hash);
tmp_table=0;
@ -2232,13 +2229,13 @@ void THD::cleanup_after_query()
thd_progress_end(this);
/*
Reset rand_used so that detection of calls to rand() will save random
Reset RAND_USED so that detection of calls to rand() will save random
seeds if needed by the slave.
Do not reset rand_used if inside a stored function or trigger because
Do not reset RAND_USED if inside a stored function or trigger because
only the call to these operations is logged. Thus only the calling
statement needs to detect rand() calls made by its substatements. These
substatements must not set rand_used to 0 because it would remove the
substatements must not set RAND_USED to 0 because it would remove the
detection of rand() by the calling statement.
*/
if (!in_sub_stmt) /* stored functions and triggers are a special case */
@ -2246,7 +2243,7 @@ void THD::cleanup_after_query()
/* Forget those values, for next binlogger: */
stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
auto_inc_intervals_in_cur_stmt_for_binlog.empty();
rand_used= 0;
used&= ~THD::RAND_USED;
#ifndef EMBEDDED_LIBRARY
/*
Clean possible unused INSERT_ID events by current statement.
@ -7537,7 +7534,7 @@ MYSQL_TIME THD::query_start_TIME()
MYSQL_TIME res;
variables.time_zone->gmt_sec_to_TIME(&res, query_start());
res.second_part= query_start_sec_part();
time_zone_used= 1;
used|= TIME_ZONE_USED;
return res;
}
@ -8276,7 +8273,7 @@ Query_arena_stmt::~Query_arena_stmt()
bool THD::timestamp_to_TIME(MYSQL_TIME *ltime, my_time_t ts,
ulong sec_part, date_mode_t fuzzydate)
{
time_zone_used= 1;
used|= TIME_ZONE_USED;
if (ts == 0 && sec_part == 0)
{
if (fuzzydate & TIME_NO_ZERO_DATE)

View File

@ -2908,6 +2908,12 @@ public:
*/
uint32 binlog_unsafe_warning_flags;
typedef uint used_t;
enum { RAND_USED=1, TIME_ZONE_USED=2, QUERY_START_SEC_PART_USED=4,
THREAD_SPECIFIC_USED=8 };
used_t used;
#ifndef MYSQL_CLIENT
binlog_cache_mngr * binlog_setup_trx_data();
/*
@ -3592,15 +3598,11 @@ public:
Reset to FALSE when we leave the sub-statement mode.
*/
bool is_fatal_sub_stmt_error;
bool rand_used, time_zone_used;
bool query_start_sec_part_used;
/* for IS NULL => = last_insert_id() fix in remove_eq_conds() */
bool substitute_null_with_insert_id;
bool in_lock_tables;
bool bootstrap, cleanup_done, free_connection_done;
/** is set if some thread specific value(s) used in a statement. */
bool thread_specific_used;
/**
is set if a statement accesses a temporary table created through
CREATE TEMPORARY TABLE.
@ -3908,7 +3910,7 @@ public:
ulong sec_part, date_mode_t fuzzydate);
inline my_time_t query_start() { return start_time; }
inline ulong query_start_sec_part()
{ query_start_sec_part_used=1; return start_time_sec_part; }
{ used|= QUERY_START_SEC_PART_USED; return start_time_sec_part; }
MYSQL_TIME query_start_TIME();
time_round_mode_t temporal_round_mode() const
{

View File

@ -1640,7 +1640,7 @@ bool multi_delete::send_eof()
thd->clear_error();
else
errcode= query_error_code(thd, killed_status == NOT_KILLED);
thd->thread_specific_used= TRUE;
thd->used|= THD::THREAD_SPECIFIC_USED;
StatementBinlog stmt_binlog(thd, thd->binlog_need_stmt_format(transactional_tables));
if (unlikely(thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query(), thd->query_length(),

View File

@ -2280,7 +2280,8 @@ public:
ulong start_time_sec_part;
sql_mode_t sql_mode;
bool auto_increment_field_not_null;
bool ignore, log_query, query_start_sec_part_used;
bool ignore, log_query;
THD::used_t query_start_sec_part_used;
bool stmt_depends_on_first_successful_insert_id_in_prev_stmt;
ulonglong first_successful_insert_id_in_prev_stmt;
ulonglong forced_insert_id;
@ -2938,7 +2939,7 @@ int write_delayed(THD *thd, TABLE *table, enum_duplicates duplic,
row->start_time= thd->start_time;
row->start_time_sec_part= thd->start_time_sec_part;
row->query_start_sec_part_used= thd->query_start_sec_part_used;
row->query_start_sec_part_used= thd->used & THD::QUERY_START_SEC_PART_USED;
/*
those are for the binlog: LAST_INSERT_ID() has been evaluated at this
time, so record does not need it, but statement-based binlogging of the
@ -2955,7 +2956,7 @@ int write_delayed(THD *thd, TABLE *table, enum_duplicates duplic,
So we can get time_zone object from thread which handling delayed statement.
See the comment of my_tz_find() for detail.
*/
if (thd->time_zone_used)
if (thd->used & THD::TIME_ZONE_USED)
{
row->time_zone = thd->variables.time_zone;
}
@ -3569,7 +3570,7 @@ bool Delayed_insert::handle_inserts(void)
thd.start_time=row->start_time;
thd.start_time_sec_part=row->start_time_sec_part;
thd.query_start_sec_part_used=row->query_start_sec_part_used;
thd.used= row->query_start_sec_part_used;
/*
To get the exact auto_inc interval to store in the binlog we must not
use values from the previous interval (of the previous rows).

View File

@ -7575,8 +7575,8 @@ void THD::reset_for_next_command(bool do_clear_error)
}
#endif /* WITH_WSREP */
query_start_sec_part_used= 0;
is_fatal_error= time_zone_used= 0;
used= 0;
is_fatal_error= 0;
variables.option_bits&= ~OPTION_BINLOG_THIS_STMT;
/*
@ -7595,14 +7595,12 @@ void THD::reset_for_next_command(bool do_clear_error)
transaction->all.reset();
}
DBUG_ASSERT(security_ctx== &main_security_ctx);
thread_specific_used= FALSE;
if (opt_bin_log)
reset_dynamic(&user_var_events);
DBUG_ASSERT(user_var_events_alloc == &main_mem_root);
enable_slow_log= true;
get_stmt_da()->reset_for_next_command();
rand_used= 0;
m_sent_row_count= m_examined_row_count= 0;
accessed_rows_and_keys= 0;

View File

@ -1816,7 +1816,7 @@ report_error:
table->table ? table->table->s : NULL));
}
DEBUG_SYNC(thd, "rm_table_no_locks_before_binlog");
thd->thread_specific_used= TRUE;
thd->used|= THD::THREAD_SPECIFIC_USED;
error= 0;
err:
@ -4620,7 +4620,7 @@ int create_table_impl(THD *thd,
if (is_trans != NULL)
*is_trans= table->file->has_transactions();
thd->thread_specific_used= TRUE;
thd->used|= THD::THREAD_SPECIFIC_USED;
create_info->table= table; // Store pointer to table
}
@ -4811,11 +4811,9 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table,
thd->abort_on_warning= thd->is_strict_mode();
if (mysql_create_table_no_lock(thd, &ddl_log_state_create, &ddl_log_state_rm,
&create_table->db,
&create_table->table_name, create_info,
alter_info,
&is_trans, create_table_mode,
create_table) > 0)
&create_table->db, &create_table->table_name,
create_info, alter_info, &is_trans,
create_table_mode, create_table) > 0)
{
result= 1;
goto err;

View File

@ -499,7 +499,7 @@ bool int_to_datetime_with_warn(THD *thd, const Longlong_hybrid &nr,
my_time_t TIME_to_timestamp(THD *thd, const MYSQL_TIME *t, uint *error_code)
{
thd->time_zone_used= 1;
thd->used|= THD::TIME_ZONE_USED;
return thd->variables.time_zone->TIME_to_gmt_sec(t, error_code);
}
@ -1265,7 +1265,7 @@ mix_date_and_time(MYSQL_TIME *to, const MYSQL_TIME *from)
void set_current_date(THD *thd, MYSQL_TIME *to)
{
thd->variables.time_zone->gmt_sec_to_TIME(to, thd->query_start());
thd->time_zone_used= 1;
thd->used|= THD::TIME_ZONE_USED;
datetime_to_date(to);
}

View File

@ -1064,7 +1064,7 @@ Datetime::Datetime(THD *thd, const timeval &tv)
{
thd->variables.time_zone->gmt_sec_to_TIME(this, tv.tv_sec);
second_part= tv.tv_usec;
thd->time_zone_used= 1;
thd->used|= THD::TIME_ZONE_USED;
DBUG_ASSERT(is_valid_value_slow());
}

View File

@ -2241,7 +2241,7 @@ public:
timezone). If it's the global value which was used we can't replicate
(binlog code stores session value only).
*/
thd->time_zone_used= 1;
thd->used|= THD::TIME_ZONE_USED;
return valptr(thd, session_var(thd, Time_zone *));
}
const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const

View File

@ -427,7 +427,7 @@ bool THD::open_temporary_table(TABLE_LIST *tl)
#endif
table->query_id= query_id;
thread_specific_used= true;
used|= THREAD_SPECIFIC_USED;
/* It is neither a derived table nor non-updatable view. */
tl->updatable= true;
@ -1355,7 +1355,7 @@ bool THD::log_events_and_free_tmp_shares()
{
if (IS_USER_TABLE(share))
{
bool save_thread_specific_used= thread_specific_used;
used_t save_thread_specific_used= used & THREAD_SPECIFIC_USED;
my_thread_id save_pseudo_thread_id= variables.pseudo_thread_id;
char db_buf[FN_REFLEN];
String db(db_buf, sizeof(db_buf), system_charset_info);
@ -1405,7 +1405,7 @@ bool THD::log_events_and_free_tmp_shares()
clear_error();
CHARSET_INFO *cs_save= variables.character_set_client;
variables.character_set_client= system_charset_info;
thread_specific_used= true;
used|= THREAD_SPECIFIC_USED;
Query_log_event qinfo(this, s_query.ptr(),
s_query.length() - 1 /* to remove trailing ',' */,
@ -1438,7 +1438,7 @@ bool THD::log_events_and_free_tmp_shares()
get_stmt_da()->set_overwrite_status(false);
}
variables.pseudo_thread_id= save_pseudo_thread_id;
thread_specific_used= save_thread_specific_used;
used = (used & ~THREAD_SPECIFIC_USED) | save_thread_specific_used;
}
else
{