Skip to content

Commit c38b8f4

Browse files
vuvovasanja-byelkin
authored andcommitted
cleanup: consolidate binlog-related THD::*_used into one bitmap
1 parent 4ce1470 commit c38b8f4

15 files changed

+61
-72
lines changed

sql/item_func.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ bool Item_func_connection_id::fix_fields(THD *thd, Item **ref)
775775
{
776776
if (Item_int_func::fix_fields(thd, ref))
777777
return TRUE;
778-
thd->thread_specific_used= TRUE;
778+
thd->used|= THD::THREAD_SPECIFIC_USED;
779779
value= thd->variables.pseudo_thread_id;
780780
return FALSE;
781781
}
@@ -2818,9 +2818,9 @@ bool Item_func_rand::fix_fields(THD *thd,Item **ref)
28182818
Once events are forwarded rather than recreated,
28192819
the following can be skipped if inside the slave thread
28202820
*/
2821-
if (!thd->rand_used)
2821+
if (!(thd->used & THD::RAND_USED))
28222822
{
2823-
thd->rand_used= 1;
2823+
thd->used|= THD::RAND_USED;
28242824
thd->rand_saved_seed1= thd->rand.seed1;
28252825
thd->rand_saved_seed2= thd->rand.seed2;
28262826
}

sql/item_timefunc.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ bool Item_func_from_days::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzz
15091509
void Item_func_curdate_local::store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)
15101510
{
15111511
thd->variables.time_zone->gmt_sec_to_TIME(now_time, thd->query_start());
1512-
thd->time_zone_used= 1;
1512+
thd->used |= THD::TIME_ZONE_USED;
15131513
}
15141514

15151515

@@ -1601,7 +1601,7 @@ void Item_func_curtime_local::store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)
16011601
now_time->year= now_time->month= now_time->day= 0;
16021602
now_time->time_type= MYSQL_TIMESTAMP_TIME;
16031603
set_sec_part(thd->query_start_sec_part(), now_time, this);
1604-
thd->time_zone_used= 1;
1604+
thd->used|= THD::TIME_ZONE_USED;
16051605
}
16061606

16071607

@@ -1667,7 +1667,7 @@ void Item_func_now_local::store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)
16671667
{
16681668
thd->variables.time_zone->gmt_sec_to_TIME(now_time, thd->query_start());
16691669
set_sec_part(thd->query_start_sec_part(), now_time, this);
1670-
thd->time_zone_used= 1;
1670+
thd->used|= THD::TIME_ZONE_USED;
16711671
}
16721672

16731673

@@ -1710,7 +1710,7 @@ void Item_func_sysdate_local::store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)
17101710
my_hrtime_t now= my_hrtime();
17111711
thd->variables.time_zone->gmt_sec_to_TIME(now_time, hrtime_to_my_time(now));
17121712
set_sec_part(hrtime_sec_part(now), now_time, this);
1713-
thd->time_zone_used= 1;
1713+
thd->used|= THD::TIME_ZONE_USED;
17141714
}
17151715

17161716

@@ -2732,7 +2732,7 @@ String *Item_func_tochar::val_str(String* str)
27322732

27332733
bool Item_func_from_unixtime::fix_length_and_dec(THD *thd)
27342734
{
2735-
thd->time_zone_used= 1;
2735+
thd->used|= THD::TIME_ZONE_USED;
27362736
tz= thd->variables.time_zone;
27372737
Type_std_attributes::set(
27382738
Type_temporal_attributes_not_fixed_dec(MAX_DATETIME_WIDTH,

sql/log.cc

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -834,14 +834,13 @@ bool Log_to_csv_event_handler::
834834
uint field_index;
835835
Silence_log_table_errors error_handler;
836836
Open_tables_backup open_tables_backup;
837-
bool save_time_zone_used;
837+
THD::used_t save_time_zone_used= thd->used & THD::TIME_ZONE_USED;
838838
DBUG_ENTER("log_general");
839839

840840
/*
841841
CSV uses TIME_to_timestamp() internally if table needs to be repaired
842-
which will set thd->time_zone_used
842+
which will set TIME_ZONE_USED
843843
*/
844-
save_time_zone_used= thd->time_zone_used;
845844

846845
table_list.init_one_table(&MYSQL_SCHEMA_NAME, &GENERAL_LOG_NAME, 0,
847846
TL_WRITE_CONCURRENT_INSERT);
@@ -942,7 +941,7 @@ bool Log_to_csv_event_handler::
942941
if (need_close)
943942
close_log_table(thd, &open_tables_backup);
944943

945-
thd->time_zone_used= save_time_zone_used;
944+
thd->used= (thd->used & ~THD::TIME_ZONE_USED) | save_time_zone_used;
946945
DBUG_RETURN(result);
947946
}
948947

@@ -989,19 +988,14 @@ bool Log_to_csv_event_handler::
989988
Silence_log_table_errors error_handler;
990989
Open_tables_backup open_tables_backup;
991990
CHARSET_INFO *client_cs= thd->variables.character_set_client;
992-
bool save_time_zone_used;
991+
THD::used_t save_time_zone_used= thd->used & THD::TIME_ZONE_USED;
993992
ulong query_time= (ulong) MY_MIN(query_utime/1000000, TIME_MAX_VALUE_SECONDS);
994993
ulong lock_time= (ulong) MY_MIN(lock_utime/1000000, TIME_MAX_VALUE_SECONDS);
995994
ulong query_time_micro= (ulong) (query_utime % 1000000);
996995
ulong lock_time_micro= (ulong) (lock_utime % 1000000);
997996
DBUG_ENTER("Log_to_csv_event_handler::log_slow");
998997

999998
thd->push_internal_handler(& error_handler);
1000-
/*
1001-
CSV uses TIME_to_timestamp() internally if table needs to be repaired
1002-
which will set thd->time_zone_used
1003-
*/
1004-
save_time_zone_used= thd->time_zone_used;
1005999

10061000
table_list.init_one_table(&MYSQL_SCHEMA_NAME, &SLOW_LOG_NAME, 0,
10071001
TL_WRITE_CONCURRENT_INSERT);
@@ -1129,7 +1123,7 @@ bool Log_to_csv_event_handler::
11291123
}
11301124
if (need_close)
11311125
close_log_table(thd, &open_tables_backup);
1132-
thd->time_zone_used= save_time_zone_used;
1126+
thd->used= (thd->used & ~THD::TIME_ZONE_USED) | save_time_zone_used;
11331127
DBUG_RETURN(result);
11341128
}
11351129

@@ -6853,7 +6847,7 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info, my_bool *with_annotate)
68536847
if (write_event(&e, cache_data, file))
68546848
goto err;
68556849
}
6856-
if (thd->rand_used)
6850+
if (thd->used & THD::RAND_USED)
68576851
{
68586852
Rand_log_event e(thd,thd->rand_saved_seed1,thd->rand_saved_seed2,
68596853
using_trans, direct);

sql/log_event_server.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ bool Query_log_event::write()
12891289
}
12901290
}
12911291

1292-
if (thd && thd->query_start_sec_part_used)
1292+
if (thd && (thd->used & THD::QUERY_START_SEC_PART_USED))
12931293
{
12941294
*start++= Q_HRNOW;
12951295
get_time();
@@ -1415,8 +1415,8 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
14151415
bool direct, bool suppress_use, int errcode)
14161416

14171417
:Log_event(thd_arg,
1418-
(thd_arg->thread_specific_used ? LOG_EVENT_THREAD_SPECIFIC_F :
1419-
0) |
1418+
((thd_arg->used & THD::THREAD_SPECIFIC_USED)
1419+
? LOG_EVENT_THREAD_SPECIFIC_F : 0) |
14201420
(suppress_use ? LOG_EVENT_SUPPRESS_USE_F : 0),
14211421
using_trans),
14221422
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,
15021502
int2store(charset, thd_arg->variables.character_set_client->number);
15031503
int2store(charset+2, thd_arg->variables.collation_connection->number);
15041504
int2store(charset+4, thd_arg->variables.collation_server->number);
1505-
if (thd_arg->time_zone_used)
1505+
if (thd_arg->used & THD::TIME_ZONE_USED)
15061506
{
15071507
/*
15081508
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,
29512951
enum enum_duplicates handle_dup,
29522952
bool ignore, bool using_trans)
29532953
:Log_event(thd_arg,
2954-
thd_arg->thread_specific_used ? LOG_EVENT_THREAD_SPECIFIC_F : 0,
2954+
(thd_arg->used & THD::THREAD_SPECIFIC_USED)
2955+
? LOG_EVENT_THREAD_SPECIFIC_F : 0,
29552956
using_trans),
29562957
thread_id(thd_arg->thread_id),
29572958
slave_proxy_id((ulong)thd_arg->variables.pseudo_thread_id),

sql/sp.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,7 @@ bool AUTHID::read_from_mysql_proc_row(THD *thd, TABLE *table)
687687
*/
688688

689689
int
690-
Sp_handler::db_find_routine(THD *thd,
691-
const Database_qualified_name *name,
690+
Sp_handler::db_find_routine(THD *thd, const Database_qualified_name *name,
692691
sp_head **sphp) const
693692
{
694693
TABLE *table;
@@ -697,7 +696,7 @@ Sp_handler::db_find_routine(THD *thd,
697696
longlong created;
698697
longlong modified;
699698
Sp_chistics chistics;
700-
bool saved_time_zone_used= thd->time_zone_used;
699+
THD::used_t saved_time_zone_used= thd->used & THD::TIME_ZONE_USED;
701700
bool trans_commited= 0;
702701
sql_mode_t sql_mode;
703702
Stored_program_creation_ctx *creation_ctx;
@@ -763,15 +762,14 @@ Sp_handler::db_find_routine(THD *thd,
763762
thd->commit_whole_transaction_and_close_tables();
764763
new_trans.restore_old_transaction();
765764

766-
ret= db_load_routine(thd, name, sphp,
767-
sql_mode, params, returns, body, chistics, definer,
768-
created, modified, NULL, creation_ctx);
765+
ret= db_load_routine(thd, name, sphp, sql_mode, params, returns, body,
766+
chistics, definer, created, modified, NULL, creation_ctx);
769767
done:
770768
/*
771769
Restore the time zone flag as the timezone usage in proc table
772770
does not affect replication.
773771
*/
774-
thd->time_zone_used= saved_time_zone_used;
772+
thd->used= (thd->used & ~THD::TIME_ZONE_USED) | saved_time_zone_used;
775773
if (!trans_commited)
776774
{
777775
if (table)

sql/sql_class.cc

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
635635
protocol_text(this), protocol_binary(this), initial_status_var(0),
636636
m_current_stage_key(0), m_psi(0),
637637
in_sub_stmt(0), log_all_errors(0),
638-
binlog_unsafe_warning_flags(0),
638+
binlog_unsafe_warning_flags(0), used(0),
639639
current_stmt_binlog_format(BINLOG_FORMAT_MIXED),
640640
bulk_param(0),
641641
table_map_for_update(0),
@@ -655,8 +655,6 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
655655
is_fatal_error(0),
656656
transaction_rollback_request(0),
657657
is_fatal_sub_stmt_error(false),
658-
rand_used(0),
659-
time_zone_used(0),
660658
in_lock_tables(0),
661659
bootstrap(0),
662660
derived_tables_processing(FALSE),
@@ -769,11 +767,10 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
769767
security_ctx= &main_security_ctx;
770768
no_errors= 0;
771769
password= 0;
772-
query_start_sec_part_used= 0;
773770
count_cuted_fields= CHECK_FIELD_IGNORE;
774771
killed= NOT_KILLED;
775772
killed_err= 0;
776-
is_slave_error= thread_specific_used= FALSE;
773+
is_slave_error= FALSE;
777774
my_hash_clear(&handler_tables_hash);
778775
my_hash_clear(&ull_hash);
779776
tmp_table=0;
@@ -2232,21 +2229,21 @@ void THD::cleanup_after_query()
22322229
thd_progress_end(this);
22332230

22342231
/*
2235-
Reset rand_used so that detection of calls to rand() will save random
2232+
Reset RAND_USED so that detection of calls to rand() will save random
22362233
seeds if needed by the slave.
22372234
2238-
Do not reset rand_used if inside a stored function or trigger because
2235+
Do not reset RAND_USED if inside a stored function or trigger because
22392236
only the call to these operations is logged. Thus only the calling
22402237
statement needs to detect rand() calls made by its substatements. These
2241-
substatements must not set rand_used to 0 because it would remove the
2238+
substatements must not set RAND_USED to 0 because it would remove the
22422239
detection of rand() by the calling statement.
22432240
*/
22442241
if (!in_sub_stmt) /* stored functions and triggers are a special case */
22452242
{
22462243
/* Forget those values, for next binlogger: */
22472244
stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
22482245
auto_inc_intervals_in_cur_stmt_for_binlog.empty();
2249-
rand_used= 0;
2246+
used&= ~THD::RAND_USED;
22502247
#ifndef EMBEDDED_LIBRARY
22512248
/*
22522249
Clean possible unused INSERT_ID events by current statement.
@@ -7537,7 +7534,7 @@ MYSQL_TIME THD::query_start_TIME()
75377534
MYSQL_TIME res;
75387535
variables.time_zone->gmt_sec_to_TIME(&res, query_start());
75397536
res.second_part= query_start_sec_part();
7540-
time_zone_used= 1;
7537+
used|= TIME_ZONE_USED;
75417538
return res;
75427539
}
75437540

@@ -8276,7 +8273,7 @@ Query_arena_stmt::~Query_arena_stmt()
82768273
bool THD::timestamp_to_TIME(MYSQL_TIME *ltime, my_time_t ts,
82778274
ulong sec_part, date_mode_t fuzzydate)
82788275
{
8279-
time_zone_used= 1;
8276+
used|= TIME_ZONE_USED;
82808277
if (ts == 0 && sec_part == 0)
82818278
{
82828279
if (fuzzydate & TIME_NO_ZERO_DATE)

sql/sql_class.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,6 +2908,12 @@ class THD: public THD_count, /* this must be first */
29082908
*/
29092909
uint32 binlog_unsafe_warning_flags;
29102910

2911+
typedef uint used_t;
2912+
enum { RAND_USED=1, TIME_ZONE_USED=2, QUERY_START_SEC_PART_USED=4,
2913+
THREAD_SPECIFIC_USED=8 };
2914+
2915+
used_t used;
2916+
29112917
#ifndef MYSQL_CLIENT
29122918
binlog_cache_mngr * binlog_setup_trx_data();
29132919
/*
@@ -3592,15 +3598,11 @@ class THD: public THD_count, /* this must be first */
35923598
Reset to FALSE when we leave the sub-statement mode.
35933599
*/
35943600
bool is_fatal_sub_stmt_error;
3595-
bool rand_used, time_zone_used;
3596-
bool query_start_sec_part_used;
35973601
/* for IS NULL => = last_insert_id() fix in remove_eq_conds() */
35983602
bool substitute_null_with_insert_id;
35993603
bool in_lock_tables;
36003604
bool bootstrap, cleanup_done, free_connection_done;
36013605

3602-
/** is set if some thread specific value(s) used in a statement. */
3603-
bool thread_specific_used;
36043606
/**
36053607
is set if a statement accesses a temporary table created through
36063608
CREATE TEMPORARY TABLE.
@@ -3908,7 +3910,7 @@ class THD: public THD_count, /* this must be first */
39083910
ulong sec_part, date_mode_t fuzzydate);
39093911
inline my_time_t query_start() { return start_time; }
39103912
inline ulong query_start_sec_part()
3911-
{ query_start_sec_part_used=1; return start_time_sec_part; }
3913+
{ used|= QUERY_START_SEC_PART_USED; return start_time_sec_part; }
39123914
MYSQL_TIME query_start_TIME();
39133915
time_round_mode_t temporal_round_mode() const
39143916
{

sql/sql_delete.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ bool multi_delete::send_eof()
16401640
thd->clear_error();
16411641
else
16421642
errcode= query_error_code(thd, killed_status == NOT_KILLED);
1643-
thd->thread_specific_used= TRUE;
1643+
thd->used|= THD::THREAD_SPECIFIC_USED;
16441644
StatementBinlog stmt_binlog(thd, thd->binlog_need_stmt_format(transactional_tables));
16451645
if (unlikely(thd->binlog_query(THD::ROW_QUERY_TYPE,
16461646
thd->query(), thd->query_length(),

sql/sql_insert.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,7 +2280,8 @@ class delayed_row :public ilink {
22802280
ulong start_time_sec_part;
22812281
sql_mode_t sql_mode;
22822282
bool auto_increment_field_not_null;
2283-
bool ignore, log_query, query_start_sec_part_used;
2283+
bool ignore, log_query;
2284+
THD::used_t query_start_sec_part_used;
22842285
bool stmt_depends_on_first_successful_insert_id_in_prev_stmt;
22852286
ulonglong first_successful_insert_id_in_prev_stmt;
22862287
ulonglong forced_insert_id;
@@ -2938,7 +2939,7 @@ int write_delayed(THD *thd, TABLE *table, enum_duplicates duplic,
29382939

29392940
row->start_time= thd->start_time;
29402941
row->start_time_sec_part= thd->start_time_sec_part;
2941-
row->query_start_sec_part_used= thd->query_start_sec_part_used;
2942+
row->query_start_sec_part_used= thd->used & THD::QUERY_START_SEC_PART_USED;
29422943
/*
29432944
those are for the binlog: LAST_INSERT_ID() has been evaluated at this
29442945
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,
29552956
So we can get time_zone object from thread which handling delayed statement.
29562957
See the comment of my_tz_find() for detail.
29572958
*/
2958-
if (thd->time_zone_used)
2959+
if (thd->used & THD::TIME_ZONE_USED)
29592960
{
29602961
row->time_zone = thd->variables.time_zone;
29612962
}
@@ -3569,7 +3570,7 @@ bool Delayed_insert::handle_inserts(void)
35693570

35703571
thd.start_time=row->start_time;
35713572
thd.start_time_sec_part=row->start_time_sec_part;
3572-
thd.query_start_sec_part_used=row->query_start_sec_part_used;
3573+
thd.used= row->query_start_sec_part_used;
35733574
/*
35743575
To get the exact auto_inc interval to store in the binlog we must not
35753576
use values from the previous interval (of the previous rows).

sql/sql_parse.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7575,8 +7575,8 @@ void THD::reset_for_next_command(bool do_clear_error)
75757575
}
75767576
#endif /* WITH_WSREP */
75777577

7578-
query_start_sec_part_used= 0;
7579-
is_fatal_error= time_zone_used= 0;
7578+
used= 0;
7579+
is_fatal_error= 0;
75807580
variables.option_bits&= ~OPTION_BINLOG_THIS_STMT;
75817581

75827582
/*
@@ -7595,14 +7595,12 @@ void THD::reset_for_next_command(bool do_clear_error)
75957595
transaction->all.reset();
75967596
}
75977597
DBUG_ASSERT(security_ctx== &main_security_ctx);
7598-
thread_specific_used= FALSE;
75997598

76007599
if (opt_bin_log)
76017600
reset_dynamic(&user_var_events);
76027601
DBUG_ASSERT(user_var_events_alloc == &main_mem_root);
76037602
enable_slow_log= true;
76047603
get_stmt_da()->reset_for_next_command();
7605-
rand_used= 0;
76067604
m_sent_row_count= m_examined_row_count= 0;
76077605
accessed_rows_and_keys= 0;
76087606

0 commit comments

Comments
 (0)