Bug #106684 time_zone caused Query_cache stored repetitive select queries.
Submitted: 10 Mar 2022 1:35 Modified: 10 Mar 2022 10:20
Reporter: teng wang (OCA) Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: Query Cache Severity:S3 (Non-critical)
Version:5.7.19, 5.7.37 OS:Linux
Assigned to: CPU Architecture:Any

[10 Mar 2022 1:35] teng wang
Description:
I set the config "query_cache_size=1355776" and "query_cache_type=1" in the config file in order to use Query_cache. 
However, for the same "Select *" operation, the Query_cache failed to identify them and stores the redundant queries, after I change the option "time_zone" on the fly.
It is not reasonable because the "Selected" table/rows are not time type or date type;
time_zone should not affect the query result. Similar situations for "default_week_format" and "lc_time_names". It would be more efficient for Query_cache to identify them accurately.

How to repeat:
I put the test case and result followed.
Test:
set  time_zone = SYSTEM;
reset query cache;
flush status;

create database if not exists mysqltest;
create table mysqltest.t1 (i int not null);
insert into mysqltest.t1 (i) values (1);
show status like "Qcache_queries_in_cache";

select * from mysqltest.t1 order by i;
show status like "Qcache_queries_in_cache";

set  time_zone = "+9:00";
select * from mysqltest.t1 order by i;
show status like "Qcache_queries_in_cache";

select * from mysqltest.t1 order by i;
show status like "Qcache_queries_in_cache";

Result:
set  time_zone = SYSTEM;
reset query cache;
flush status;
create database if not exists mysqltest;
create table mysqltest.t1 (i int not null);
insert into mysqltest.t1 (i) values (1);
show status like "Qcache_queries_in_cache";
Variable_name	Value
Qcache_queries_in_cache	0
select * from mysqltest.t1 order by i;
i
1
show status like "Qcache_queries_in_cache";
Variable_name	Value
Qcache_queries_in_cache	1
set  time_zone = "+9:00";
select * from mysqltest.t1 order by i;
i
1
show status like "Qcache_queries_in_cache";
Variable_name	Value
Qcache_queries_in_cache	2
select * from mysqltest.t1 order by i;
i
1
show status like "Qcache_queries_in_cache";
Variable_name	Value
Qcache_queries_in_cache	2

Suggested fix:
time_zone should not affect the query result, which are not time type of date type.
[10 Mar 2022 5:54] MySQL Verification Team
Hello!

Thank you for the report and feedback.
Please note that *query cache* is deprecated as of MySQL 5.7.20, and is removed in MySQL 8.0. 

regards,
Umesh
[10 Mar 2022 10:20] Ståle Deraas
Posted by developer:
 
QC is deprecated from 5.7.20 and removed in 8.0, so not feasible to fix.