1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

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.
This commit is contained in:
ingo/istruewing@chilla.local
2006-08-02 17:57:06 +02:00
parent ddcb190eac
commit 8e4c36ad4a
25 changed files with 503 additions and 160 deletions

View File

@ -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_n<5F>gel`, `t1_bl<62>ten`;
--enable_warnings
CREATE TABLE `t1_n<5F>gel` (c1 INT);
ALTER TABLE `t1_n<5F>gel` RENAME `t1_bl<62>ten`;
CREATE TABLE `t1_n<5F>gel` (c1 INT);
--error ER_TABLE_EXISTS_ERROR
ALTER TABLE `t1_n<5F>gel` RENAME `t1_bl<62>ten`;
DROP TABLE `t1_n<5F>gel`, `t1_bl<62>ten`;
#
# Same for temporary tables though these names do not become file names.
CREATE TEMPORARY TABLE `tt1_n<5F>gel` (c1 INT);
ALTER TABLE `tt1_n<5F>gel` RENAME `tt1_bl<62>ten`;
CREATE TEMPORARY TABLE `tt1_n<5F>gel` (c1 INT);
--error ER_TABLE_EXISTS_ERROR
ALTER TABLE `tt1_n<5F>gel` RENAME `tt1_bl<62>ten`;
SHOW CREATE TABLE `tt1_bl<62>ten`;
DROP TABLE `tt1_n<5F>gel`, `tt1_bl<62>ten`;
#
# 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;