Bug #21370 View renaming lacks tablename_to_filename encoding
Submitted: 31 Jul 2006 19:08 Modified: 17 Nov 2006 18:02
Reporter: Ingo Strüwing Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Views Severity:S2 (Serious)
Version:5.1.12 OS:Linux (Linux)
Assigned to: Alexander Barkov CPU Architecture:Any

[31 Jul 2006 19:08] Ingo Strüwing
Description:
In the function mysql_rename_view() some tablename_to_filename encodings are missing. Same in some functions called by it. The below test result shows the misbehaviour:

! DROP TABLE IF EXISTS t1, `t-blüten`;
! CREATE TABLE t1 (c1 INT);
! CREATE VIEW  v1 AS SELECT c1 FROM t1;
! SHOW TABLES;
! Tables_in_test
! t1
! v1
! RENAME TABLE t1 TO t2;
! RENAME TABLE v1 TO v2;
! SHOW TABLES;
! Tables_in_test
! t2
! v2
! DROP TABLE t2;
! DROP VIEW  v2;
! CREATE TABLE `t-blüten` (c1 INT);
! CREATE VIEW  `v-blüten` AS SELECT c1 FROM `t-blüten`;
! SHOW TABLES;
! Tables_in_test
! t-blüten
! v-blüten
! RENAME TABLE `t-blüten` TO `t-nägel`;
! RENAME TABLE `v-blüten` TO `v-nägel`;
! ERROR HY000: Can't get stat of './test/v-blüten.frm' (Errcode: 2)
! SHOW TABLES;
! Tables_in_test
! t-nägel
! v-blüten
! DROP TABLE `t-nägel`;
! DROP VIEW  `v-nägel`;
! ERROR 42S02: Unknown table 'test.v-nägel'
! DROP VIEW  `v-blüten`;
! CREATE TABLE `#sql-t1` (c1 INT);
! CREATE VIEW  `#sql-v1` AS SELECT c1 FROM `#sql-t1`;
! SHOW TABLES;
! Tables_in_test
! #sql-t1
! #sql-v1
! RENAME TABLE `#sql-t1` TO `#sql-t2`;
! RENAME TABLE `#sql-v1` TO `#sql-v2`;
! ERROR HY000: Can't get stat of './test/#sql-v1.frm' (Errcode: 2)
! SHOW TABLES;
! Tables_in_test
! #sql-t2
! #sql-v1
! DROP TABLE `#sql-t2`;
! DROP VIEW  `#sql-v2`;
! ERROR 42S02: Unknown table 'test.#sql-v2'
! DROP VIEW  `#sql-v1`;

How to repeat:
# For demo purposes
--disable_abort_on_error

#
# Bug#????? - View renaming lacks tablename_to_filename encoding
#
--disable_warnings
DROP TABLE IF EXISTS t1, `t-blüten`, `#sql-t1`;
DROP TABLE IF EXISTS t2, `t-nägel`,  `#sql-t2`;
DROP VIEW  IF EXISTS v1, `v-blüten`, `#sql-v1`;
DROP VIEW  IF EXISTS v2, `v-nägel`,  `#sql-v2`;
--enable_warnings
#
# How everything should go
CREATE TABLE t1 (c1 INT);
CREATE VIEW  v1 AS SELECT c1 FROM t1;
SHOW TABLES;
RENAME TABLE t1 TO t2;
RENAME TABLE v1 TO v2;
SHOW TABLES;
DROP TABLE t2;
DROP VIEW  v2;
#
# Now the same with names that should be encoded
CREATE TABLE `t-blüten` (c1 INT);
CREATE VIEW  `v-blüten` AS SELECT c1 FROM `t-blüten`;
SHOW TABLES;
RENAME TABLE `t-blüten` TO `t-nägel`;
# Wrong: --error 13
RENAME TABLE `v-blüten` TO `v-nägel`;
SHOW TABLES;
DROP TABLE `t-nägel`;
# Wrong: --error ER_BAD_TABLE_ERROR
DROP VIEW  `v-nägel`;
#
#This should not be necessary and even fail
# Right: --error ER_BAD_TABLE_ERROR
DROP VIEW  `v-blüten`;
#
# Now the same with special names that should be encoded too
CREATE TABLE `#sql-t1` (c1 INT);
CREATE VIEW  `#sql-v1` AS SELECT c1 FROM `#sql-t1`;
SHOW TABLES;
RENAME TABLE `#sql-t1` TO `#sql-t2`;
# Wrong: --error 13
RENAME TABLE `#sql-v1` TO `#sql-v2`;
SHOW TABLES;
DROP TABLE `#sql-t2`;
# Wrong: --error ER_BAD_TABLE_ERROR
DROP VIEW  `#sql-v2`;
#
#This should not be necessary and even fail
# Right: --error ER_BAD_TABLE_ERROR
DROP VIEW  `#sql-v1`;
[8 Sep 2006 6:41] Alexander Barkov
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

http://lists.mysql.com/commits/11594
[16 Oct 2006 17:42] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/13759

ChangeSet@1.2309, 2006-10-16 22:42:03+05:00, bar@mysql.com +4 -0
  Bug#21370: View renaming lacks tablename_to_filename encoding
    Problem: renaming of FRM file and ARC files didn't use file name
    encoding, so RENAME TABLE for views failed for views having
    "tricky" characters in their names.
    Fix: adding build_table_filename() in missing places.
[16 Nov 2006 16:21] Alexander Barkov
Appeared in 5.1.14
[17 Nov 2006 18:02] Paul Dubois
Noted in 5.1.14 changelog.