Bug #62237 Query cache behaviour change based on database name and engine
Submitted: 23 Aug 2011 11:20 Modified: 23 Aug 2011 15:07
Reporter: Olivier Doucet Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Query Cache Severity:S3 (Non-critical)
Version:5.5.14 OS:Linux
Assigned to: CPU Architecture:Any

[23 Aug 2011 11:20] Olivier Doucet
Description:
A simple query does not get into cache, based on the database name : if the db name has a '-' (minus) it does not work. This problem seems to happen only if engine is InnoDB.

This has been tested on 3 different servers with different config files : 

5.1.49-3 (Debian) X86_64 debian-linux-gnu
5.5.8 (Source) X86_64 Linux
5.1.58 (Percona version) X86_64 Linux

I tried to debug this behaviour : it seems the function dict0dict.c::dict_table_get() returned NULL. Internal innodb name seems to be test@002fname/mytable , though different from 'test-name/mytable' => function dict_table_get() cannot find it and returned NULL.

How to repeat:
CREATE DATABASE `test-name`;
USE `test-name`;
CREATE TABLE `test-name`.`mytable`(     `id` INT NOT NULL ,     `name` VARCHAR(128) ,     PRIMARY KEY (`id`)  ) engine=InnoDB;
INSERT INTO `test-name`.`mytable`(`id`,`name`) VALUES ( '1','hello');
INSERT INTO `test-name`.`mytable`(`id`,`name`) VALUES ( '2','world');

reset query cache;

SHOW STATUS LIKE 'Qcache_queries_in_cache';
=> 0

SELECT SQL_CACHE * FROM mytable WHERE id=2;

SHOW STATUS LIKE 'Qcache_queries_in_cache';
=> 0

ALTER TABLE `test-name`.`mytable` ENGINE = MYISAM;

SELECT SQL_CACHE * FROM mytable WHERE id=2 LIMIT 0, 1000;
SHOW STATUS LIKE 'Qcache_queries_in_cache';
=> 1

ALTER TABLE `test-name`.`mytable` ENGINE = INNODB;
SHOW STATUS LIKE 'Qcache_queries_in_cache';
=> 0

SELECT * FROM mytable WHERE id=1;
 
SHOW STATUS LIKE 'Qcache_queries_in_cache';
=> 0

-----------------------------------------------------------------------

Here is what happen with different database name : 

CREATE DATABASE `testname`;
USE `testname`;
CREATE TABLE `testname`.`mytable`(     `id` INT NOT NULL ,     `name` VARCHAR(128) ,     PRIMARY KEY (`id`)  ) Engine=InnoDB;
INSERT INTO `testname`.`mytable`(`id`,`name`) VALUES ( '1','hello');
INSERT INTO `testname`.`mytable`(`id`,`name`) VALUES ( '2','world');

reset query cache;

SHOW STATUS LIKE 'Qcache_queries_in_cache';
=> 0

SELECT SQL_CACHE * FROM mytable WHERE id=2;

SHOW STATUS LIKE 'Qcache_queries_in_cache';
=> 1

ALTER TABLE `testname`.`mytable` ENGINE = MYISAM;

SELECT SQL_CACHE * FROM mytable WHERE id=2 LIMIT 0, 1000;
SHOW STATUS LIKE 'Qcache_queries_in_cache';
=> 1

ALTER TABLE `testname`.`mytable` ENGINE = INNODB;
SHOW STATUS LIKE 'Qcache_queries_in_cache';
=> 0

SELECT * FROM mytable WHERE id=1;
 
SHOW STATUS LIKE 'Qcache_queries_in_cache';
=> 1
[23 Aug 2011 13:31] Olivier Doucet
Same behaviour tested on : 
5.5.14 MySQL Community Server (GPL) x84_64
5.5.14 Percona Server (rel 20.5)
[23 Aug 2011 14:51] Olivier Doucet
Duplicate bug http://bugs.mysql.com/bug.php?id=55556
Sorry, I did not found this bug before submitting this one.
[23 Aug 2011 15:07] Valeriy Kravchuk
Duplicate of Bug #55556.