Skip to content

Commit 9293d40

Browse files
committed
MDEV-33145 support for old-mode=OLD_FLUSH_STATUS
add old-mode that restores inconsistent legacy behavior for FLUSH STATUS. It doesn't affect FLUSH { SESSION | GLOBAL } STATUS.
1 parent 9ecec1f commit 9293d40

15 files changed

+126
-10
lines changed

include/mysql_com.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ enum enum_indicator_type
194194
#define REFRESH_LOG (1ULL << 1) /* Start on new log file */
195195
#define REFRESH_TABLES (1ULL << 2) /* close all tables */
196196
#define REFRESH_HOSTS (1ULL << 3) /* Flush host cache */
197-
#define REFRESH_SESSION_STATUS (1ULL << 4) /* Flush status variables */
198-
#define REFRESH_STATUS REFRESH_SESSION_STATUS
197+
#define REFRESH_STATUS (1ULL << 4) /* Flush status variables */
199198
#define REFRESH_THREADS (1ULL << 5) /* Flush thread cache */
200199
#define REFRESH_SLAVE (1ULL << 6) /* Reset master info and restart
201200
slave thread */
@@ -220,6 +219,7 @@ enum enum_indicator_type
220219
#define REFRESH_FOR_EXPORT (1ULL << 20) /* FLUSH TABLES ... FOR EXPORT */
221220
#define REFRESH_SSL (1ULL << 21)
222221
#define REFRESH_GLOBAL_STATUS (1ULL << 22) /* Flush global status */
222+
#define REFRESH_SESSION_STATUS (1ULL << 23) /* Flush session status */
223223

224224
#define REFRESH_GENERIC (1ULL << 30)
225225
#define REFRESH_FAST (1ULL << 31) /* Intern flag */

mysql-test/main/mysqld--help.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,8 @@ The following specify which files/extra groups are read (specified before remain
739739
NO_DUP_KEY_WARNINGS_WITH_IGNORE, NO_PROGRESS_INFO,
740740
ZERO_DATE_TIME_CAST, UTF8_IS_UTF8MB3,
741741
IGNORE_INDEX_ONLY_FOR_JOIN, COMPAT_5_1_CHECKSUM,
742-
NO_NULL_COLLATION_IDS, LOCK_ALTER_TABLE_COPY, or ALL to
743-
set all combinations
742+
NO_NULL_COLLATION_IDS, LOCK_ALTER_TABLE_COPY,
743+
OLD_FLUSH_STATUS, or ALL to set all combinations
744744
--old-passwords Use old password encryption method (needed for 4.0 and
745745
older clients)
746746
--old-style-user-limits

mysql-test/main/status.result

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,4 +488,29 @@ select $new_local_flush_status >= $local_flush_status as "1";
488488
select $new_global_flush_status < $new_local_flush_status as "1";
489489
1
490490
1
491+
create or replace table t1 (a int, key(a)) engine=MyISAM;
492+
insert into t1 values (1),(2);
493+
connect con1,localhost,root;
494+
set old_mode=OLD_FLUSH_STATUS;
495+
Warnings:
496+
Warning 1287 'OLD_FLUSH_STATUS' is deprecated and will be removed in a future release
497+
insert into t1 values (3),(4);
498+
drop table t1;
499+
select t1.variable_name, t1.variable_value as global_value, t2.variable_value as session_value
500+
from information_schema.global_status t1 join information_schema.session_status t2
501+
on t1.variable_name = t2.variable_name
502+
where t1.variable_name in ('Key_writes','Com_insert');
503+
variable_name global_value session_value
504+
COM_INSERT 2 1
505+
KEY_WRITES 2 2
506+
flush status;
507+
select t1.variable_name, t1.variable_value as global_value, t2.variable_value as session_value
508+
from information_schema.global_status t1 join information_schema.session_status t2
509+
on t1.variable_name = t2.variable_name
510+
where t1.variable_name in ('Key_writes','Com_insert');
511+
variable_name global_value session_value
512+
COM_INSERT 2 0
513+
KEY_WRITES 0 0
514+
disconnect con1;
515+
connection default;
491516
# end of 11.5 tests

mysql-test/main/status.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,4 +506,32 @@ let $new_local_flush_status= `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESS
506506
--evalp select $new_local_flush_status >= $local_flush_status as "1"
507507
--evalp select $new_global_flush_status < $new_local_flush_status as "1"
508508

509+
#
510+
# Test OLD_FLUSH_STATUS
511+
#
512+
513+
create or replace table t1 (a int, key(a)) engine=MyISAM;
514+
insert into t1 values (1),(2);
515+
516+
--connect con1,localhost,root
517+
set old_mode=OLD_FLUSH_STATUS;
518+
519+
insert into t1 values (3),(4);
520+
drop table t1;
521+
522+
select t1.variable_name, t1.variable_value as global_value, t2.variable_value as session_value
523+
from information_schema.global_status t1 join information_schema.session_status t2
524+
on t1.variable_name = t2.variable_name
525+
where t1.variable_name in ('Key_writes','Com_insert');
526+
527+
flush status;
528+
529+
select t1.variable_name, t1.variable_value as global_value, t2.variable_value as session_value
530+
from information_schema.global_status t1 join information_schema.session_status t2
531+
on t1.variable_name = t2.variable_name
532+
where t1.variable_name in ('Key_writes','Com_insert');
533+
534+
disconnect con1;
535+
connection default;
536+
509537
--echo # end of 11.5 tests

mysql-test/suite/sys_vars/r/old_mode_basic.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ Warning 1287 'ZERO_DATE_TIME_CAST' is deprecated and will be removed in a future
132132
SELECT @@global.old_mode;
133133
@@global.old_mode
134134
ZERO_DATE_TIME_CAST
135-
SET @@global.old_mode = 256;
136-
ERROR 42000: Variable 'old_mode' can't be set to the value of '256'
135+
SET @@global.old_mode = 6536;
136+
ERROR 42000: Variable 'old_mode' can't be set to the value of '6536'
137137
SELECT @@global.old_mode;
138138
@@global.old_mode
139139
ZERO_DATE_TIME_CAST

mysql-test/suite/sys_vars/r/sysvars_server_embedded.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2329,7 +2329,7 @@ VARIABLE_COMMENT Used to emulate old behavior from earlier MariaDB or MySQL vers
23292329
NUMERIC_MIN_VALUE NULL
23302330
NUMERIC_MAX_VALUE NULL
23312331
NUMERIC_BLOCK_SIZE NULL
2332-
ENUM_VALUE_LIST NO_DUP_KEY_WARNINGS_WITH_IGNORE,NO_PROGRESS_INFO,ZERO_DATE_TIME_CAST,UTF8_IS_UTF8MB3,IGNORE_INDEX_ONLY_FOR_JOIN,COMPAT_5_1_CHECKSUM,NO_NULL_COLLATION_IDS,LOCK_ALTER_TABLE_COPY
2332+
ENUM_VALUE_LIST NO_DUP_KEY_WARNINGS_WITH_IGNORE,NO_PROGRESS_INFO,ZERO_DATE_TIME_CAST,UTF8_IS_UTF8MB3,IGNORE_INDEX_ONLY_FOR_JOIN,COMPAT_5_1_CHECKSUM,NO_NULL_COLLATION_IDS,LOCK_ALTER_TABLE_COPY,OLD_FLUSH_STATUS
23332333
READ_ONLY NO
23342334
COMMAND_LINE_ARGUMENT REQUIRED
23352335
VARIABLE_NAME OLD_PASSWORDS

mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2539,7 +2539,7 @@ VARIABLE_COMMENT Used to emulate old behavior from earlier MariaDB or MySQL vers
25392539
NUMERIC_MIN_VALUE NULL
25402540
NUMERIC_MAX_VALUE NULL
25412541
NUMERIC_BLOCK_SIZE NULL
2542-
ENUM_VALUE_LIST NO_DUP_KEY_WARNINGS_WITH_IGNORE,NO_PROGRESS_INFO,ZERO_DATE_TIME_CAST,UTF8_IS_UTF8MB3,IGNORE_INDEX_ONLY_FOR_JOIN,COMPAT_5_1_CHECKSUM,NO_NULL_COLLATION_IDS,LOCK_ALTER_TABLE_COPY
2542+
ENUM_VALUE_LIST NO_DUP_KEY_WARNINGS_WITH_IGNORE,NO_PROGRESS_INFO,ZERO_DATE_TIME_CAST,UTF8_IS_UTF8MB3,IGNORE_INDEX_ONLY_FOR_JOIN,COMPAT_5_1_CHECKSUM,NO_NULL_COLLATION_IDS,LOCK_ALTER_TABLE_COPY,OLD_FLUSH_STATUS
25432543
READ_ONLY NO
25442544
COMMAND_LINE_ARGUMENT REQUIRED
25452545
VARIABLE_NAME OLD_PASSWORDS

mysql-test/suite/sys_vars/t/old_mode_basic.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ SET @@global.old_mode = 4;
172172
SELECT @@global.old_mode;
173173

174174
--Error ER_WRONG_VALUE_FOR_VAR
175-
SET @@global.old_mode = 256;
175+
SET @@global.old_mode = 6536;
176176
SELECT @@global.old_mode;
177177

178178
# use of decimal values

sql/mysqld.cc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9227,6 +9227,52 @@ void refresh_global_status()
92279227
max_used_connections_time= time(nullptr);
92289228
}
92299229

9230+
/** Emulate the legacy FLUSH STATUS inconsistent behavior
9231+
9232+
* additive session variables are added to global and set to 0 in session
9233+
* non-additive global variables are set to 0
9234+
*/
9235+
void refresh_status_legacy(THD *thd)
9236+
{
9237+
mysql_mutex_lock(&LOCK_status);
9238+
9239+
#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
9240+
/* Reset aggregated status counters. */
9241+
reset_pfs_status_stats();
9242+
#endif
9243+
9244+
/* Add thread's status variabes to global status */
9245+
add_to_status(&global_status_var, &thd->status_var);
9246+
9247+
/* Reset thread's status variables */
9248+
thd->set_status_var_init();
9249+
thd->status_var.global_memory_used= 0;
9250+
bzero((uchar*) &thd->org_status_var, sizeof(thd->org_status_var));
9251+
thd->start_bytes_received= 0;
9252+
9253+
/* Reset some global variables */
9254+
reset_status_vars();
9255+
#ifdef WITH_WSREP
9256+
if (WSREP_ON)
9257+
{
9258+
Wsrep_server_state::instance().provider().reset_status();
9259+
}
9260+
#endif /* WITH_WSREP */
9261+
9262+
/* Reset the counters of all key caches (default and named). */
9263+
process_key_caches(reset_key_cache_counters, 0);
9264+
global_status_var.flush_status_time= my_time(0);
9265+
mysql_mutex_unlock(&LOCK_status);
9266+
9267+
/*
9268+
Set max_used_connections to the number of currently open
9269+
connections. This is not perfect, but status data is not exact anyway.
9270+
*/
9271+
max_used_connections= connection_count + extra_connection_count;
9272+
max_used_connections_time= time(nullptr);
9273+
}
9274+
9275+
92309276

92319277
#ifdef HAVE_PSI_INTERFACE
92329278
static PSI_file_info all_server_files[]=

sql/mysqld.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ void close_connection(THD *thd, uint sql_errno= 0);
8080
void handle_connection_in_main_thread(CONNECT *thd);
8181
void create_thread_to_handle_connection(CONNECT *connect);
8282
void unlink_thd(THD *thd);
83+
void refresh_status_legacy(THD *thd);
8384
void refresh_session_status(THD *thd);
8485
void refresh_global_status();
8586
bool is_secure_file_path(char *path);

0 commit comments

Comments
 (0)