Bug #105957 The table "slow_log" not close when config option slow_query_log set into OFF
Submitted: 22 Dec 2021 7:44 Modified: 22 Dec 2021 8:00
Reporter: teng wang (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Options Severity:S3 (Non-critical)
Version:5.7.35, 8.0.27 OS:Linux
Assigned to: CPU Architecture:Any

[22 Dec 2021 7:44] teng wang
Description:
This is similar to Bug #105933. When we set the config option "slow_query_log" as ON, and "log_output" as TABLE in the config file, MySQL records the related slow logs into the table named "slow_log". However, if we runtime change the option "slow_query_log" into OFF, the table "slow_log" is still keeping open until "flush tables" command is entered.

The ideal situation is that when slow_query_log turns into OFF, the table slow_log should be closed right now. In some situations, the table slow_log may be big and occupy lots of caches, which might affect the performance of the cache-related operations.

We check the open tables by the command "show open tables from mysql;"

How to repeat:
set global slow_query_log = 'ON';
set global log_output = 'TABLE';
set global log_queries_not_using_indexes = 1;
show global variables where variable_name like 'slow_query_log';
show global variables where variable_name like 'log_output';

flush tables;
show open tables from mysql;

create table t1(
  a int primary key,
  b char(10)
);
insert into t1 values (1,'one'), (2,'two');
create table t2(
  a int primary key,
  b char(10)
);
insert into t2 values (1,'ONE'), (2,'TWO');
select * from t1 LEFT JOIN t2 on t1.a=t2.a;
show open tables from mysql;

set global slow_query_log = OFF;
show global variables where variable_name like 'slow_query_log';
show open tables from mysql;

flush tables;
show global variables where variable_name like 'slow_query_log';
show open tables from mysql;

Suggested fix:
when runtime change "slow_query_log", the function fix_slow_log_state will be called. Maybe we can close the table slow_log during fix_slow_log_state().

/* /sql/sys_vars.cc */
static bool fix_slow_log_state(sys_var *self, THD *thd, enum_var_type type)
[22 Dec 2021 8:00] MySQL Verification Team
Hello!

Thank you for the report and feedback.

regards,
Umesh