MDEV-6500: Stale data returned after TRUNCATE PARTITION operation

When truncating a table's partition, we also need to invalidate the
query cache for it.
This commit is contained in:
Vicențiu Ciorbaru 2015-06-03 23:31:05 +03:00
parent 08fa02cf22
commit a477cd1754
3 changed files with 74 additions and 2 deletions

View File

@ -0,0 +1,33 @@
SET GLOBAL query_cache_size=1024*1024*8;
CREATE TABLE `test` (
`uniqueId` INT NOT NULL,
`partitionId` INT NOT NULL,
PRIMARY KEY (`uniqueId`,`partitionId`)
) ENGINE=InnoDB PARTITION BY LIST (partitionId) (
PARTITION p01 VALUES IN (1),
PARTITION p02 VALUES IN (2)
);
INSERT INTO `test`(`uniqueId`,`partitionId`) VALUES(407237055, 2);
SELECT * FROM `test`;
uniqueId partitionId
407237055 2
#Confirms 1 row in partition 'p02'
SELECT TABLE_NAME, PARTITION_NAME, TABLE_ROWS FROM information_schema.PARTITIONS where TABLE_NAME = 'test';
TABLE_NAME PARTITION_NAME TABLE_ROWS
test p01 0
test p02 1
ALTER TABLE `test` TRUNCATE PARTITION `p02`;
#Confirms no more rows in partition 'p02'
SELECT TABLE_NAME, PARTITION_NAME, TABLE_ROWS FROM information_schema.PARTITIONS where TABLE_NAME = 'test';
TABLE_NAME PARTITION_NAME TABLE_ROWS
test p01 0
test p02 0
#Before the patch, this returned the previously existing values.
SELECT * FROM `test`;
uniqueId partitionId
SELECT SQL_CACHE * FROM `test`;
uniqueId partitionId
SELECT SQL_NO_CACHE * FROM `test`;
uniqueId partitionId
DROP TABLE test;
SET GLOBAL query_cache_size=DEFAULT;

View File

@ -0,0 +1,32 @@
--source include/have_innodb.inc
--source include/have_partition.inc
SET GLOBAL query_cache_size=1024*1024*8;
CREATE TABLE `test` (
`uniqueId` INT NOT NULL,
`partitionId` INT NOT NULL,
PRIMARY KEY (`uniqueId`,`partitionId`)
) ENGINE=InnoDB PARTITION BY LIST (partitionId) (
PARTITION p01 VALUES IN (1),
PARTITION p02 VALUES IN (2)
);
INSERT INTO `test`(`uniqueId`,`partitionId`) VALUES(407237055, 2);
SELECT * FROM `test`;
--echo #Confirms 1 row in partition 'p02'
SELECT TABLE_NAME, PARTITION_NAME, TABLE_ROWS FROM information_schema.PARTITIONS where TABLE_NAME = 'test';
ALTER TABLE `test` TRUNCATE PARTITION `p02`;
--echo #Confirms no more rows in partition 'p02'
SELECT TABLE_NAME, PARTITION_NAME, TABLE_ROWS FROM information_schema.PARTITIONS where TABLE_NAME = 'test';
--echo #Before the patch, this returned the previously existing values.
SELECT * FROM `test`;
SELECT SQL_CACHE * FROM `test`;
SELECT SQL_NO_CACHE * FROM `test`;
DROP TABLE test;
SET GLOBAL query_cache_size=DEFAULT;

View File

@ -174,9 +174,16 @@ bool Alter_table_truncate_partition_statement::execute(THD *thd)
log. The exception is a unimplemented truncate method or failure log. The exception is a unimplemented truncate method or failure
before any call to handler::truncate() is done. before any call to handler::truncate() is done.
Also, it is logged in statement format, regardless of the binlog format. Also, it is logged in statement format, regardless of the binlog format.
Since we've changed data within the table, we also have to invalidate
the query cache for it.
*/ */
if (error != HA_ERR_WRONG_COMMAND && binlog_stmt) if (error != HA_ERR_WRONG_COMMAND)
{
query_cache_invalidate3(thd, first_table, FALSE);
if (binlog_stmt)
error|= write_bin_log(thd, !error, thd->query(), thd->query_length()); error|= write_bin_log(thd, !error, thd->query(), thd->query_length());
}
/* /*
A locked table ticket was upgraded to a exclusive lock. After the A locked table ticket was upgraded to a exclusive lock. After the