From 9ab544f3f5ff4505b5502f3d3bf65987d0cb3390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Rafael?= Date: Mon, 16 Mar 2026 14:38:26 +0000 Subject: [PATCH] Force global DB when using a single thread anyway --- src/storage/sqlite_table_entry.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/storage/sqlite_table_entry.cpp b/src/storage/sqlite_table_entry.cpp index fd17c2d..512f78f 100644 --- a/src/storage/sqlite_table_entry.cpp +++ b/src/storage/sqlite_table_entry.cpp @@ -37,7 +37,18 @@ TableFunction SQLiteTableEntry::GetScanFunction(ClientContext &context, unique_p if (!db.GetRowIdInfo(name, result->row_id_info)) { result->rows_per_group = optional_idx(); } - if (!transaction.IsReadOnly() || sqlite_catalog.InMemory()) { + + bool use_global_db = !transaction.IsReadOnly() || sqlite_catalog.InMemory(); + + Value threads_setting; + if (!use_global_db && context.TryGetCurrentSetting("threads", threads_setting) && !threads_setting.IsNull()) { + auto current_threads = NumericCast(BigIntValue::Get(threads_setting.DefaultCastAs(LogicalType::BIGINT))); + if (current_threads <= 1) { + use_global_db = true; + } + } + + if (use_global_db) { // for in-memory databases or if we have transaction-local changes we can // only do a single-threaded scan set up the transaction's connection object // as the global db