提交 f0292f99 编写于 作者: A Alexey Milovidov

Merge branch 'amosbird-master'

......@@ -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)
......
======Before Truncate======
0
======After Truncate And Empty======
======After Truncate And Insert Data======
0
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;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册