From e2314d3a96c4c7231669271889095bfdfa2c30c5 Mon Sep 17 00:00:00 2001 From: taniabogatsch <44262898+taniabogatsch@users.noreply.github.com> Date: Fri, 19 Sep 2025 16:11:29 +0200 Subject: [PATCH] move the profiler up --- src/main/client_context.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/client_context.cpp b/src/main/client_context.cpp index b8dcb336a6c0..f52fbabdda5f 100644 --- a/src/main/client_context.cpp +++ b/src/main/client_context.cpp @@ -217,15 +217,15 @@ void ClientContext::BeginQueryInternal(ClientContextLock &lock, const string &qu state->QueryBegin(*this); } - // Flush the old Logger + // Flush the old logger. logger->Flush(); - // Refresh the logger to ensure we are in sync with global log settings - LoggingContext context(LogContextScope::CONNECTION); - context.connection_id = connection_id; - context.transaction_id = transaction.ActiveTransaction().global_transaction_id; - context.query_id = transaction.GetActiveQuery(); - logger = db->GetLogManager().CreateLogger(context, true); + // Refresh the logger to ensure we are in sync with the global log settings. + LoggingContext logging_context(LogContextScope::CONNECTION); + logging_context.connection_id = connection_id; + logging_context.transaction_id = transaction.ActiveTransaction().global_transaction_id; + logging_context.query_id = transaction.GetActiveQuery(); + logger = db->GetLogManager().CreateLogger(logging_context, true); DUCKDB_LOG(*this, QueryLogType, query); } @@ -889,6 +889,10 @@ unique_ptr ClientContext::PendingStatementOrPreparedStatemen shared_ptr &prepared, const PendingQueryParameters ¶meters) { unique_ptr pending; + // Start the profiler. + auto &profiler = QueryProfiler::Get(*this); + profiler.StartQuery(query, IsExplainAnalyze(statement ? statement.get() : prepared->unbound_statement.get())); + try { BeginQueryInternal(lock, query); } catch (std::exception &ex) { @@ -900,9 +904,6 @@ unique_ptr ClientContext::PendingStatementOrPreparedStatemen } return ErrorResult(std::move(error), query); } - // start the profiler - auto &profiler = QueryProfiler::Get(*this); - profiler.StartQuery(query, IsExplainAnalyze(statement ? statement.get() : prepared->unbound_statement.get())); bool invalidate_query = true; try {