[MDEV-16253] Dropping temporary table and actual table with same name Created: 2018-05-22  Updated: 2023-04-27

Status: Open
Project: MariaDB Server
Component/s: Authentication and Privilege System, Data Definition - Alter Table, Data Definition - Temporary
Affects Version/s: None
Fix Version/s: 10.4

Type: Bug Priority: Major
Reporter: Vicențiu Ciorbaru Assignee: Vicențiu Ciorbaru
Resolution: Unresolved Votes: 0
Labels: None


 Description   

This code works.

create temporary table t1 (a int);
create table t1 (b int);
-- This drops the temporary table. Temporary tables hide the regular one with the same name.
drop table t1;
create temporary table t1 (a int);
-- First table dropped should be the temporary table, then the second one should be the regular table.
-- This currently fails with an error.
drop table t1, t1;

Make
drop table t1, t1 succeed and also carry out correct privilege checks according to which table it's looking at (temporary vs non-temporary).

Note, this should be fixed in the earliest release where it makes sense.



 Comments   
Comment by Michael Widenius [ 2018-05-22 ]

Hint for fixing:

Remove this line from sql_parse.cc (it's just wrong):
sql_command_flags[SQLCOM_DROP_TABLE]|= CF_PREOPEN_TMP_TABLES;

This doesn't work as it will assume that in "drop table t1,t1' that both t1 are temporary tables, and grant checking
will not work (as we need to check grant for the real table t1)

I did something similar in 10.0 for RENAME TABLE with temporary tables.
This code is in bb-10.0-monty, soon to be pushed into 10.0

Comment by Anel Husakovic [ 2018-06-12 ]

Hi Michel, Vicentiu,
I worked on this issue and here is a working patch:
https://github.com/an3l/server/commits/drop_temp_base_same_name_10.3_v2
In a gist, I looped through table list. Temporary tables are checked first and when we find the second same name we set to null table->table instance-similar trick was done for dropping the sequence. I hope the approach could pass ?
Patch has 4 commits :
First one is commit which enables same names and regarding this commit is question 1.
Second commit is also referencing question 1. problem which happens in test main.drop and is product of partial testing where error 1066 occurs.
Third commit is product of learning curve of starting point (Monty's patch da71c1bad79ee11009b3b28) of SQLCOM_RENAME_TABLE debugging. It seems that we could use sqlcom flag CF_HA_CLOSE in case of SQLCOM_RENAME_TABLE command right ? - *Question 2*
And here I'm stucked...
Question 1. Although is stated in commit message of a patch, regarding the base table lock mode - What should happen if we run following ?:

>>create table t(t int);  
>>lock table t write; 
>> drop table t,t;  # (returns error 1066, this is OK), but
>> create temporary table t(t int); 
>> drop table t,t;  

After the last line server crashes because the line sql_table.cc:2127 (In comment of this file is written that is not expected to have the same name of temp/base tables). _What should we do in this case _? What should be a starting point to solve this ?
Regards

Comment by Anel Husakovic [ 2020-08-25 ]

julien.fritsch it wasn't assigned to me for review. I'm author of the patch PR #796.

Generated at Thu Feb 08 08:27:31 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.