Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/sqlite_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ static void LoadInternal(ExtensionLoader &loader) {
config.AddExtensionOption("sqlite_debug_show_queries", "DEBUG SETTING: print all queries sent to SQLite to stdout",
LogicalType::BOOLEAN, Value::BOOLEAN(false), SetSqliteDebugQueryPrint);

config.AddExtensionOption("sqlite_disable_multithreaded_scans", "Make all scans over the SQLite DB to be performed using a single worker thread",
LogicalType::BOOLEAN, Value::BOOLEAN(false));

StorageExtension::Register(config, "sqlite_scanner", make_shared_ptr<SQLiteStorageExtension>());
}

Expand Down
20 changes: 12 additions & 8 deletions src/storage/sqlite_table_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,20 @@ TableFunction SQLiteTableEntry::GetScanFunction(ClientContext &context, unique_p
result->rows_per_group = optional_idx();
}

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<idx_t>(BigIntValue::Get(threads_setting.DefaultCastAs(LogicalType::BIGINT)));
if (current_threads <= 1) {
use_global_db = true;
}
int64_t threads = 1;
Value threads_val;
if (context.TryGetCurrentSetting("threads", threads_val)) {
threads = BigIntValue::Get(threads_val);
}

bool disable_multithreaded_scans = false;
Value disable_multithreaded_scans_val;
if (context.TryGetCurrentSetting("sqlite_disable_multithreaded_scans", disable_multithreaded_scans_val)) {
disable_multithreaded_scans = BooleanValue::Get(disable_multithreaded_scans_val);
}

bool use_global_db = !transaction.IsReadOnly() || sqlite_catalog.InMemory() || threads <= 1 || disable_multithreaded_scans;

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
Expand Down
13 changes: 13 additions & 0 deletions test/sql/storage/attach_simple.test
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,16 @@ query I
SELECT * FROM simple.test2
----
84

# check option is supported

statement ok
SET sqlite_disable_multithreaded_scans = TRUE;

query I
SELECT * FROM simple.test2
----
84

statement ok
SET sqlite_disable_multithreaded_scans = FALSE;
Loading