Commit 4c52d3dd authored by ingo@mysql.com's avatar ingo@mysql.com

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

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.

Normal GRANT checking takes place for the intermediate table.
Everyone who can see the original table (and hence the final
table) can also see the intermediate table. But noone else.

In 5.0 the intermediate files are invisible for SHOW TABLES
because all file names beginning with "#sql" were suppressed.
In 5.1 temporary files are created in TMPDIR, so that they
don't appear in the database directories. Also in 5.1 a
translation between table names and file names is done. The
tmp_file_prefix on file level is now "@0023sql".

The suppression of files starting with tmp_file_prefix is
still in place, but still only files beginning with "#sql"
were suppressed.

I do now translate tmp_file_prefix from table name to file
name before comparing it with the files in a directory.
This suppresses the intermediate files again.

No test case. The test case looks so that a reasonable big
table is altered while a second thread runs SHOW TABLES.
This in itself would be possible to do, but on slow machines
it would add too much time to the test suite, while on fast
machines the ALTER TABLE might have finished before SHOW
TABLES looks at the directory. Even if there might be a good
balance for todays machines, one day the test would become
void as the intermediate table would not be seen even with
the bug in place. I added a test script to the bug report.
It can easily be changed so that it uses a table size that
is appropriate for the test machine.
parent fe1f04c7
......@@ -438,6 +438,7 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
uint col_access=thd->col_access;
#endif
TABLE_LIST table_list;
char tbbuff[FN_REFLEN];
DBUG_ENTER("mysql_find_files");
if (wild && !wild[0])
......@@ -454,6 +455,8 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
DBUG_RETURN(-1);
}
VOID(tablename_to_filename(tmp_file_prefix, tbbuff, sizeof(tbbuff)));
for (i=0 ; i < (uint) dirp->number_off_files ; i++)
{
char uname[NAME_LEN*3+1]; /* Unencoded name */
......@@ -491,7 +494,7 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
{
// Return only .frm files which aren't temp files.
if (my_strcasecmp(system_charset_info, ext=fn_rext(file->name),reg_ext) ||
is_prefix(file->name,tmp_file_prefix))
is_prefix(file->name,tbbuff))
continue;
*ext=0;
VOID(filename_to_tablename(file->name, uname, sizeof(uname)));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment