From fa317e96e8b411b5326ba8357bb9ba859a054723 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Fri, 12 Nov 2021 22:13:09 +0300 Subject: [PATCH] Do not try to resolve temporary tables from global context --- src/Interpreters/Context.cpp | 7 ++++--- .../02111_global_context_temporary_tables.reference | 5 +++++ .../0_stateless/02111_global_context_temporary_tables.sql | 5 +++++ 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 tests/queries/0_stateless/02111_global_context_temporary_tables.reference create mode 100644 tests/queries/0_stateless/02111_global_context_temporary_tables.sql diff --git a/src/Interpreters/Context.cpp b/src/Interpreters/Context.cpp index 304a50f841f..032f9305f73 100644 --- a/src/Interpreters/Context.cpp +++ b/src/Interpreters/Context.cpp @@ -2821,6 +2821,10 @@ StorageID Context::resolveStorageIDImpl(StorageID storage_id, StorageNamespace w } bool look_for_external_table = where & StorageNamespace::ResolveExternal; + /// Global context should not contain temporary tables + if (isGlobalContext() && getApplicationType() != ApplicationType::LOCAL) + look_for_external_table = false; + bool in_current_database = where & StorageNamespace::ResolveCurrentDatabase; bool in_specified_database = where & StorageNamespace::ResolveGlobal; @@ -2838,9 +2842,6 @@ StorageID Context::resolveStorageIDImpl(StorageID storage_id, StorageNamespace w if (look_for_external_table) { - /// Global context should not contain temporary tables - assert(!isGlobalContext() || getApplicationType() == ApplicationType::LOCAL); - auto resolved_id = StorageID::createEmpty(); auto try_resolve = [&](ContextPtr context) -> bool { diff --git a/tests/queries/0_stateless/02111_global_context_temporary_tables.reference b/tests/queries/0_stateless/02111_global_context_temporary_tables.reference new file mode 100644 index 00000000000..96651f9c959 --- /dev/null +++ b/tests/queries/0_stateless/02111_global_context_temporary_tables.reference @@ -0,0 +1,5 @@ +-- { echo } +SELECT * FROM remote('127.1', system.one, 1 IN id); -- { serverError UNKNOWN_TABLE } +SELECT * FROM remote('127.1', system.one, 1 IN dummy); -- { serverError UNKNOWN_TABLE } +SELECT * FROM remote('127.1', view(SELECT * FROM system.one), 1 IN id); -- { serverError UNKNOWN_TABLE } +SELECT * FROM remote('127.1', view(SELECT number AS id FROM numbers(2)), 1 IN id); -- { serverError UNKNOWN_TABLE } diff --git a/tests/queries/0_stateless/02111_global_context_temporary_tables.sql b/tests/queries/0_stateless/02111_global_context_temporary_tables.sql new file mode 100644 index 00000000000..96651f9c959 --- /dev/null +++ b/tests/queries/0_stateless/02111_global_context_temporary_tables.sql @@ -0,0 +1,5 @@ +-- { echo } +SELECT * FROM remote('127.1', system.one, 1 IN id); -- { serverError UNKNOWN_TABLE } +SELECT * FROM remote('127.1', system.one, 1 IN dummy); -- { serverError UNKNOWN_TABLE } +SELECT * FROM remote('127.1', view(SELECT * FROM system.one), 1 IN id); -- { serverError UNKNOWN_TABLE } +SELECT * FROM remote('127.1', view(SELECT number AS id FROM numbers(2)), 1 IN id); -- { serverError UNKNOWN_TABLE }