From 2920f04fffbbda310108664bf45deba95cc02f51 Mon Sep 17 00:00:00 2001 From: serxa Date: Wed, 13 Sep 2023 19:34:18 +0000 Subject: [PATCH] do CREATE query async --- src/Interpreters/InterpreterCreateQuery.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Interpreters/InterpreterCreateQuery.cpp b/src/Interpreters/InterpreterCreateQuery.cpp index 5593929f9f2..18788935c3d 100644 --- a/src/Interpreters/InterpreterCreateQuery.cpp +++ b/src/Interpreters/InterpreterCreateQuery.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -324,8 +325,20 @@ BlockIO InterpreterCreateQuery::createDatabase(ASTCreateQuery & create) { /// We use global context here, because storages lifetime is bigger than query context lifetime TablesLoader loader{getContext()->getGlobalContext(), {{database_name, database}}, mode}; - waitLoad(currentPoolOr(AsyncLoaderPoolId::Foreground), loader.loadTablesAsync()); - waitLoad(currentPoolOr(AsyncLoaderPoolId::Foreground), loader.startupTablesAsync()); + auto load_tasks = loader.loadTablesAsync(); + auto startup_tasks = loader.startupTablesAsync(); + if (getContext()->getGlobalContext()->getServerSettings().async_load_databases) + { + scheduleLoad(load_tasks); + scheduleLoad(startup_tasks); + } + else + { + /// First prioritize, schedule and wait all the load table tasks + waitLoad(currentPoolOr(AsyncLoaderPoolId::Foreground), load_tasks); + /// Only then prioritize, schedule and wait all the startup tasks + waitLoad(currentPoolOr(AsyncLoaderPoolId::Foreground), startup_tasks); + } } } catch (...)