[MDEV-25868] CHECK constaint refers to old table name after temporary table rename Created: 2021-06-07  Updated: 2021-06-21  Resolved: 2021-06-07

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Temporary
Affects Version/s: 10.5.10
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Robert Humphries Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None

Issue Links:
Duplicate
is duplicated by MDEV-25672 table alias from previous statement i... Closed

 Description   

Starting in 10.5.10, when a temporary table is renamed, any CHECK constraints implicitly refer to the old table name. The below test script worked until upgrading from 10.5.9 to 10.5.10. If the `TEMPORARY` keyword is removed it works without issue.

# Ensure state is stable
DROP TEMPORARY TABLE IF EXISTS `t1`;
DROP TEMPORARY TABLE IF EXISTS `t2`;
 
# Run test
CREATE TEMPORARY TABLE `t1` (
  `i` INT AUTO_INCREMENT,
  `s` VARCHAR(16) CHECK (CHAR_LENGTH(`s`) > 5),
  PRIMARY KEY (`i`)
) ENGINE=INNODB;
 
RENAME TABLE `t1` TO `t2`;
 
ALTER TABLE `t2` AUTO_INCREMENT = 2; # Error: Unknown column '`test`.`t1`.`s`' in 'CHECK'
 
SHOW CREATE TABLE `t2`;
/*
CREATE TEMPORARY TABLE `t2` (
  `i` int(11) NOT NULL AUTO_INCREMENT,
  `s` varchar(16) DEFAULT NULL CHECK (char_length(`s`) > 5),
  PRIMARY KEY (`i`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
*/
 
# Cleanup
DROP TEMPORARY TABLE IF EXISTS `t1`;
DROP TEMPORARY TABLE IF EXISTS `t2`;

The above code is just how the error was found - the ALTER can be replaced by an insert or any statement where the CHECK is loaded.



 Comments   
Comment by Alice Sherepa [ 2021-06-07 ]

Thank you for the report!
This is the same bug as MDEV-25672

Generated at Thu Feb 08 09:41:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.