mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-19 14:11:58 +00:00
Merge branch 'master' into background-processing-pool-backoff
This commit is contained in:
commit
9611198568
@ -121,18 +121,29 @@ BlockIO InterpreterDropQuery::executeToTemporaryTable(String & table_name, ASTDr
|
||||
{
|
||||
if (kind == ASTDropQuery::Kind::Detach)
|
||||
throw Exception("Unable to detach temporary table.", ErrorCodes::SYNTAX_ERROR);
|
||||
else if (kind == ASTDropQuery::Kind::Drop)
|
||||
else
|
||||
{
|
||||
StoragePtr table = (context.hasSessionContext() ? context.getSessionContext() : context).tryRemoveExternalTable(table_name);
|
||||
auto & context_handle = context.hasSessionContext() ? context.getSessionContext() : context;
|
||||
StoragePtr table = context_handle.tryGetExternalTable(table_name);
|
||||
if (table)
|
||||
{
|
||||
table->shutdown();
|
||||
/// If table was already dropped by anyone, an exception will be thrown
|
||||
auto table_lock = table->lockForAlter(__PRETTY_FUNCTION__);
|
||||
/// Delete table data
|
||||
table->drop();
|
||||
table->is_dropped = true;
|
||||
return {};
|
||||
if (kind == ASTDropQuery::Kind::Truncate)
|
||||
{
|
||||
/// If table was already dropped by anyone, an exception will be thrown
|
||||
auto table_lock = table->lockDataForAlter(__PRETTY_FUNCTION__);
|
||||
/// Drop table data, don't touch metadata
|
||||
table->truncate(query_ptr);
|
||||
}
|
||||
else if (kind == ASTDropQuery::Kind::Drop)
|
||||
{
|
||||
context_handle.tryRemoveExternalTable(table_name);
|
||||
table->shutdown();
|
||||
/// If table was already dropped by anyone, an exception will be thrown
|
||||
auto table_lock = table->lockForAlter(__PRETTY_FUNCTION__);
|
||||
/// Delete table data
|
||||
table->drop();
|
||||
table->is_dropped = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,9 @@ void ASTDropQuery::formatQueryImpl(const FormatSettings & settings, FormatState
|
||||
else
|
||||
throw Exception("Not supported kind of drop query.", ErrorCodes::SYNTAX_ERROR);
|
||||
|
||||
if (temporary)
|
||||
settings.ostr << "TEMPORARY ";
|
||||
|
||||
settings.ostr << ((table.empty() && !database.empty()) ? "DATABASE " : "TABLE ");
|
||||
|
||||
if (if_exists)
|
||||
|
@ -0,0 +1,5 @@
|
||||
======Before Truncate======
|
||||
0
|
||||
======After Truncate And Empty======
|
||||
======After Truncate And Insert Data======
|
||||
0
|
@ -0,0 +1,16 @@
|
||||
drop temporary table if exists test;
|
||||
create temporary table test(id int);
|
||||
|
||||
select '======Before Truncate======';
|
||||
insert into test values(0);
|
||||
select * from test;
|
||||
|
||||
select '======After Truncate And Empty======';
|
||||
truncate temporary table test;
|
||||
select * from test;
|
||||
|
||||
select '======After Truncate And Insert Data======';
|
||||
insert into test values(0);
|
||||
select * from test;
|
||||
|
||||
drop temporary table test;
|
Loading…
Reference in New Issue
Block a user