Bug #39945 "WITH CONSISTENT SNAPSHOT" does not isolate against table changes (i.e. RENAME)
Submitted: 9 Oct 2008 4:22 Modified: 19 Dec 2008 0:50
Reporter: Trent Lloyd Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.60 OS:Any
Assigned to: Assigned Account CPU Architecture:Any

[9 Oct 2008 4:22] Trent Lloyd
Description:
When using "WITH CONSISTENT SNAPSHOT".. if a table is for example renamed.. you can no longer read the table.  And the table rename is not blocked.  You read the new table (and get no new rows presumably because the innodb versions are newer)

How to repeat:
Test Case:

[in customer case was done with Master/Slave but has nothing to do with Master/Slave.. need second session so the DDL happens outside the transaction scope.]

== SESSION 1 ==
CREATE DATABASE IF NOT EXISTS `test`;
USE `test`;
DROP TABLE IF EXISTS `t1_30138`;
DROP TABLE IF EXISTS `t1_30138_old`;
DROP TABLE IF EXISTS `t1_30138_new`;
CREATE TABLE `t1_30138` (id INT) ENGINE=InnoDB;
INSERT INTO `t1_30138` VALUES (1),(2),(3);
SET AUTOCOMMIT=0;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
START TRANSACTION WITH CONSISTENT SNAPSHOT;
SELECT COUNT(*) FROM `t1_30138`;

== SESSION 2 ==
USE `test`;
CREATE TABLE `t1_30138_new` (id INT) ENGINE=InnoDB;
INSERT INTO `t1_30138_new` VALUES (4),(5),(6),(7);
INSERT INTO `t1_30138` VALUES(8);
RENAME TABLE `t1_30138` TO `t1_30138_old`, `t1_30138_new` TO `t1_30138`;

== SESSION 1 ==
SELECT COUNT(*) FROM `t1_30138`;
SELECT COUNT(*) FROM `t1_30138_old`;

== CLEANUP ==
COMMIT;
DROP TABLE IF EXISTS `t1_30138`;
DROP TABLE IF EXISTS `t1_30138_old`;
DROP TABLE IF EXISTS `t1_30138_new`;

Suggested fix:
This seems like quite a complex issue to fix I suspect.

Only "easy-out" I see would be to prevent DDL during CONSISTENT SNAPSHOT.
[15 Oct 2008 18:24] Davi Arnaut
WL#4284 Transactional DDL locking
[17 Dec 2008 17:31] Konstantin Osipov
Bug#989?
[19 Dec 2008 0:50] Omer Barnir
Based on above from Kostja (bug#989)