Commit ef976d20 authored by unknown's avatar unknown
Browse files

Bug#18775 - Temporary table from alter table visible to other threads

Continued implementation of WL#1324 (table name to filename encoding)

The intermediate (not temporary) files of the new table
during ALTER TABLE was visible for SHOW TABLES. These
intermediate files are copies of the original table with
the changes done by ALTER TABLE. After all the data is
copied over from the original table, these files are renamed 
to the original tables file names. So they are not temporary 
files. They persist after ALTER TABLE, but just with another 
name.

In 5.0 the intermediate files are invisible for SHOW TABLES
because all file names beginning with "#sql" were suppressed.

This failed since 5.1.6 because even temporary table names were
converted when making file names from them. The prefix became
converted to "@0023sql". Converting the prefix during SHOW TABLES
would suppress the listing of user tables that start with "#sql".

The solution of the problem is to continue the implementation of
the table name to file name conversion feature. One requirement
is to suppress the conversion for temporary table names.

This change is straightforward for real temporary tables as there
is a function that creates temporary file names.

But the generated path names are located in TMPDIR and have no
relation to the internal table name. This cannot be used for
ALTER TABLE. Its intermediate files need to be in the same
directory as the old table files. And it is necessary to be
able to deduce the same path from the same table name repeatedly.

Consequently the intermediate table files must be handled like normal
tables. Their internal names shall start with tmp_file_prefix
(#sql) and they shall not be converted like normal table names.

I added a flags parameter to all relevant functions that are
called from ALTER TABLE. It is used to suppress the conversion
for the intermediate table files.

The outcome is that the suppression of #sql in SHOW TABLES
works again. It does not suppress user tables as these are
converted to @0023sql on file level.

This patch does also fix ALTER TABLE ... RENAME, which could not 
rename a table with non-ASCII characters in its name.

It does also fix the problem that a user could create a table like
`#sql-xxxx-yyyy`, where xxxx is mysqld's pid and yyyy is the thread
ID of some other thread, which prevented this thread from running 
ALTER TABLE.

Some of the above problems are mentioned in Bug 1405, which can
be closed with this patch.

This patch does also contain some minor fixes for other forgotten
conversions. Still known problems are reported as bugs 21370,
21373, and 21387.


mysql-test/r/alter_table.result:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added test results.
mysql-test/r/backup.result:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added test results.
mysql-test/r/repair.result:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added test results.
mysql-test/t/alter_table.test:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added test cases.
mysql-test/t/backup.test:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added test cases.
mysql-test/t/repair.test:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added a test case.
sql/ha_myisam.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added missing table name mapping calls to backup() and restore().
sql/ha_myisammrg.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added an zero argument for the new 'flags' parameter.
sql/ha_ndbcluster.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added an zero argument for the new 'flags' parameter.
sql/ha_ndbcluster_binlog.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added an zero argument for the new 'flags' parameter.
sql/ha_ndbcluster_binlog.h:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Removed unnecessary check for wrong temp file prefix.
sql/mysql_priv.h:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Extended quick_rm_table(), mysql_rename_table(), and
  build_table_filename() by an flags argument, which can indicate
  temporary table names that should not be converted.
  Added symbolic flag values.
sql/sql_acl.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added an zero argument for the new 'flags' parameter.
sql/sql_base.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Fixed a comment.
  Added DBUG calls.
sql/sql_db.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added an zero argument for the new 'flags' parameter.
sql/sql_delete.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added an zero argument for the new 'flags' parameter.
sql/sql_insert.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added an zero argument for the new 'flags' parameter.
sql/sql_partition.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added an zero argument for the new 'flags' parameter.
sql/sql_rename.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added an zero argument for the new 'flags' parameter.
sql/sql_show.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Reverted the former fix for this bug. tmp_file_prefix is now used
  verbatim in the comparison of file names.
sql/sql_table.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added a check for a tmp_file_prefix file name to
  filename_to_tablename(). These names are now accepted without
  conversion.
  Extended quick_rm_table(), mysql_rename_table(), and
  build_table_filename() by an flags argument, which can indicate
  temporary table names that should not be converted.
  Removed the table to file name conversion from
  build_tmptable_filename().
  Disabled REPAIR TABLE ... USE_FRM for temporary tables.
  Added the forgotten conversion to mysql_alter_table() for the case
  of ALTER TABLE ... RENAME.
  Added comments and DBUG calls.
sql/sql_trigger.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added an zero argument for the new 'flags' parameter.
sql/sql_view.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Added an zero argument for the new 'flags' parameter.
sql/table.cc:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Replaced a literal ".frm" by reg_ext.
  Added DBUG calls.
storage/innobase/row/row0mysql.c:
  Bug#18775 - Temporary table from alter table visible to other threads
  Continued implementation of WL#1324 (table name to filename encoding)
  Changed back the encoded temp file prefix to #sql.
parent 4b6e8fa6
Loading
Loading
Loading
Loading
+60 −0
Original line number Diff line number Diff line
@@ -657,3 +657,63 @@ SELECT * FROM t1;
v	b
abc	5
DROP TABLE t1;
DROP DATABASE IF EXISTS mysqltest;
CREATE DATABASE mysqltest;
use mysqltest;
DROP TABLE IF EXISTS `t1_ngel`, `t1_blten`;
CREATE TABLE `t1_ngel` (c1 INT);
ALTER TABLE  `t1_ngel` RENAME `t1_blten`;
CREATE TABLE `t1_ngel` (c1 INT);
ALTER TABLE  `t1_ngel` RENAME `t1_blten`;
ERROR 42S01: Table 't1_blЭten' already exists
DROP TABLE   `t1_ngel`, `t1_blten`;
CREATE TEMPORARY TABLE `tt1_ngel` (c1 INT);
ALTER TABLE  `tt1_ngel` RENAME `tt1_blten`;
CREATE TEMPORARY TABLE `tt1_ngel` (c1 INT);
ALTER TABLE  `tt1_ngel` RENAME `tt1_blten`;
ERROR 42S01: Table 'tt1_blЭten' already exists
SHOW CREATE TABLE `tt1_blten`;
Table	Create Table
tt1_blten	CREATE TEMPORARY TABLE `tt1_blten` (
  `c1` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE   `tt1_ngel`, `tt1_blten`;
CREATE TABLE `#sql1` (c1 INT);
CREATE TABLE `@0023sql2` (c1 INT);
SHOW TABLES;
Tables_in_mysqltest
#sql1
@0023sql2
RENAME TABLE `#sql1`     TO `@0023sql1`;
RENAME TABLE `@0023sql2` TO `#sql2`;
SHOW TABLES;
Tables_in_mysqltest
#sql2
@0023sql1
ALTER TABLE `@0023sql1`  RENAME `#sql-1`;
ALTER TABLE `#sql2`      RENAME `@0023sql-2`;
SHOW TABLES;
Tables_in_mysqltest
#sql-1
@0023sql-2
INSERT INTO `#sql-1`     VALUES (1);
INSERT INTO `@0023sql-2` VALUES (2);
DROP TABLE `#sql-1`, `@0023sql-2`;
CREATE TEMPORARY TABLE `#sql1` (c1 INT);
CREATE TEMPORARY TABLE `@0023sql2` (c1 INT);
SHOW TABLES;
Tables_in_mysqltest
ALTER TABLE `#sql1`      RENAME `@0023sql1`;
ALTER TABLE `@0023sql2`  RENAME `#sql2`;
SHOW TABLES;
Tables_in_mysqltest
INSERT INTO `#sql2`      VALUES (1);
INSERT INTO `@0023sql1`  VALUES (2);
SHOW CREATE TABLE `@0023sql1`;
Table	Create Table
@0023sql1	CREATE TEMPORARY TABLE `@0023sql1` (
  `c1` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE `#sql2`, `@0023sql1`;
use test;
DROP DATABASE mysqltest;
+20 −0
Original line number Diff line number Diff line
@@ -101,3 +101,23 @@ test.t5 backup status OK
Warnings:
Warning	1541	The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 5.2. Please use MySQL Administrator (mysqldump, mysql) instead.
drop table t5;
DROP TABLE IF EXISTS `t-blten`;
CREATE  TABLE `t-blten` (c1 INT);
INSERT  INTO  `t-blten` VALUES (1), (2), (3);
BACKUP  TABLE `t-blten` TO '../tmp';
Table	Op	Msg_type	Msg_text
test.t-blten	backup	status	OK
Warnings:
Warning	1541	The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 5.2. Please use MySQL Administrator (mysqldump, mysql) instead.
DROP    TABLE `t-blten`;
RESTORE TABLE `t-blten` FROM '../tmp';
Table	Op	Msg_type	Msg_text
test.t-blten	restore	status	OK
Warnings:
Warning	1541	The syntax 'RESTORE TABLE' is deprecated and will be removed in MySQL 5.2. Please use MySQL Administrator (mysqldump, mysql) instead.
SELECT * FROM `t-blten`;
c1
1
2
3
DROP    TABLE `t-blten`;
+6 −0
Original line number Diff line number Diff line
@@ -41,3 +41,9 @@ Table Op Msg_type Msg_text
test.t1	repair	warning	Number of rows changed from 0 to 1
test.t1	repair	status	OK
drop table t1;
DROP TABLE IF EXISTS tt1;
CREATE TEMPORARY TABLE tt1 (c1 INT);
REPAIR TABLE tt1 USE_FRM;
Table	Op	Msg_type	Msg_text
tt1	repair	error	Cannot repair temporary table from .frm file
DROP TABLE tt1;
+63 −0
Original line number Diff line number Diff line
@@ -482,3 +482,66 @@ SELECT * FROM t1;
ALTER TABLE t1 MODIFY COLUMN v VARCHAR(4);
SELECT * FROM t1;
DROP TABLE t1;

# End of 5.0 tests

#
# Bug#18775 - Temporary table from alter table visible to other threads
#
# Use a special database to avoid name clashes with user tables.
--disable_warnings
DROP DATABASE IF EXISTS mysqltest;
--enable_warnings
CREATE DATABASE mysqltest;
use mysqltest;
#
# Check if non-ASCII alphabetic characters work and duplicates are detected.
--disable_warnings
DROP TABLE IF EXISTS `t1_ngel`, `t1_blten`;
--enable_warnings
CREATE TABLE `t1_ngel` (c1 INT);
ALTER TABLE  `t1_ngel` RENAME `t1_blten`;
CREATE TABLE `t1_ngel` (c1 INT);
--error ER_TABLE_EXISTS_ERROR
ALTER TABLE  `t1_ngel` RENAME `t1_blten`;
DROP TABLE   `t1_ngel`, `t1_blten`;
#
# Same for temporary tables though these names do not become file names.
CREATE TEMPORARY TABLE `tt1_ngel` (c1 INT);
ALTER TABLE  `tt1_ngel` RENAME `tt1_blten`;
CREATE TEMPORARY TABLE `tt1_ngel` (c1 INT);
--error ER_TABLE_EXISTS_ERROR
ALTER TABLE  `tt1_ngel` RENAME `tt1_blten`;
SHOW CREATE TABLE `tt1_blten`;
DROP TABLE   `tt1_ngel`, `tt1_blten`;
#
# Check if special characters as in tmp_file_prefix work.
CREATE TABLE `#sql1` (c1 INT);
CREATE TABLE `@0023sql2` (c1 INT);
SHOW TABLES;
RENAME TABLE `#sql1`     TO `@0023sql1`;
RENAME TABLE `@0023sql2` TO `#sql2`;
SHOW TABLES;
ALTER TABLE `@0023sql1`  RENAME `#sql-1`;
ALTER TABLE `#sql2`      RENAME `@0023sql-2`;
SHOW TABLES;
INSERT INTO `#sql-1`     VALUES (1);
INSERT INTO `@0023sql-2` VALUES (2);
DROP TABLE `#sql-1`, `@0023sql-2`;
#
# Same for temporary tables though these names do not become file names.
CREATE TEMPORARY TABLE `#sql1` (c1 INT);
CREATE TEMPORARY TABLE `@0023sql2` (c1 INT);
SHOW TABLES;
ALTER TABLE `#sql1`      RENAME `@0023sql1`;
ALTER TABLE `@0023sql2`  RENAME `#sql2`;
SHOW TABLES;
INSERT INTO `#sql2`      VALUES (1);
INSERT INTO `@0023sql1`  VALUES (2);
SHOW CREATE TABLE `@0023sql1`;
DROP TABLE `#sql2`, `@0023sql1`;
#
# Cleanup
use test;
DROP DATABASE mysqltest;
+19 −0
Original line number Diff line number Diff line
@@ -58,3 +58,22 @@ drop table t5;
--system rm $MYSQLTEST_VARDIR/tmp/t?.*

# End of 4.1 tests
# End of 5.0 tests

#
# Bug#18775 - Temporary table from alter table visible to other threads
#
# Backup did not encode table names.
--disable_warnings
DROP TABLE IF EXISTS `t-blten`;
--enable_warnings
CREATE  TABLE `t-blten` (c1 INT);
INSERT  INTO  `t-blten` VALUES (1), (2), (3);
BACKUP  TABLE `t-blten` TO '../tmp';
DROP    TABLE `t-blten`;
#
# Same for restore.
RESTORE TABLE `t-blten` FROM '../tmp';
SELECT * FROM `t-blten`;
DROP    TABLE `t-blten`;
Loading