Bug #65519 Temporary tables for ALTER TABLE are not added to thd->temporary_tables
Submitted: 5 Jun 2012 12:55 Modified: 8 Jun 2012 15:10
Reporter: Laurynas Biveinis (OCA) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: DDL Severity:S3 (Non-critical)
Version:5.1 OS:Any
Assigned to: CPU Architecture:Any

[5 Jun 2012 12:55] Laurynas Biveinis
Description:
In mysql_alter_table() the intermediate temporary table new_table is created by

      new_table=open_temporary_table(thd, path, new_db, tmp_name,0);

Note that the last arg 0, that is, the created temp table won't be added to thd->temporary_tables list.

The 5.5 code does add this temp table to thd->temporary_tables.

How to repeat:
Maybe it's possible to construct a test case that relies on the temp table not being present in thd->temporary_tables, but for now this is purely a source code quality bug report.

Suggested fix:
s/0/TRUE
[5 Jun 2012 13:04] Laurynas Biveinis
It seems that 5.5 fixed it by revision 2875.107.1 (backport from 6.0 WL#3726 "DDL locking for all metadata objects")
[5 Jun 2012 15:46] Valeriy Kravchuk
Thank you for the problem report. Verified by code review of current mysql-5.1.
[6 Jun 2012 2:24] Laurynas Biveinis
On further analysis the fix is more involved than s/0/TRUE: care must be taken to close new_table properly too, and the required changes make this doable but  IMHO not worthwhile for 5.1.
[8 Jun 2012 15:10] Dmitry Lenev
Hello Laurynas!

Thank you for bringing up this issue!

I have checked the code in ALTER TABLE implementation in 5.1 and was not able to find any problem caused by this call to open_temporary_tables(). So technically there is no bug. So I am closing this report as such.

The potential issues caused by this "sloppy" code are addressed by changes in 5.5 in any case.