Bug #106675 Query_cache stored redundant queries after dynamically updating max_sort_length
Submitted: 9 Mar 2022 6:02 Modified: 10 Mar 2022 10:18
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.35, 5.7.37 OS:Linux
Assigned to: CPU Architecture:Any

[9 Mar 2022 6:02] teng wang
Description:
I set the config option "query_cache_size=1355776" and "query_cache_type=1" in the config file in order to use Query_cache. I am amazed that every time I update option "max_sort_length" to a large value, the Query_cache stores the redundant queries, which might reduce query efficiency and waste cache space. Because updating "max_sort_length" had no effect on results. Maybe Query_cacher should have a smart identification for redundant queries. The test case and result are followed.

How to repeat:
Test:
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;
show status like "Qcache_queries_in_cache";

set session max_sort_length = 51200;
select * from mysqltest.t1;
show status like "Qcache_queries_in_cache";

set session max_sort_length = 51202;
select * from mysqltest.t1;
show status like "Qcache_queries_in_cache";

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

drop database mysqltest;

Result:
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;
i
1
show status like "Qcache_queries_in_cache";
Variable_name	Value
Qcache_queries_in_cache	1
set session max_sort_length = 51200;
select * from mysqltest.t1;
i
1
show status like "Qcache_queries_in_cache";
Variable_name	Value
Qcache_queries_in_cache	2
set session max_sort_length = 51202;
select * from mysqltest.t1;
i
1
show status like "Qcache_queries_in_cache";
Variable_name	Value
Qcache_queries_in_cache	3
select * from mysqltest.t1;
i
1
show status like "Qcache_queries_in_cache";
Variable_name	Value
Qcache_queries_in_cache	3
drop database mysqltest;

Suggested fix:
Maybe Query_cacher should have a smart identification for redundant queries.
[9 Mar 2022 8:15] 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:18] Ståle Deraas
Posted by developer:
 
QC is deprecated from 5.7.20 and removed in 8.0, so not feasible to fix.