From 47ab467bc1f6490633f6cc4d4835755e16c94405 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 20 Nov 2025 12:07:17 +1030 Subject: [PATCH] db: don't actually create an explicit transaction for read commands. Since we are the only writer, we don't need one. Name (time in s) Min Max Mean StdDev Median sqlite: test_spam_listcommands (before) 2.1193 2.4524 2.2343 0.1341 2.2229 sqlite: test_spam_listcommands (after) 2.0140 2.2349 2.1001 0.0893 2.0644 Postgres: test_spam_listcommands (before) 6.5572 6.8440 6.7067 0.1032 6.6967 Postgres: test_spam_listcommands (after) 4.4237 5.0024 4.6495 0.2278 4.6717 A nice 31% speedup! Changelog-Changed: Postgres: significant speedup on read-only operations (e.g. 30% on empty SELECTs) Signed-off-by: Rusty Russell --- db/utils.c | 1 - 1 file changed, 1 deletion(-) diff --git a/db/utils.c b/db/utils.c index 8c4781890..d6234179d 100644 --- a/db/utils.c +++ b/db/utils.c @@ -144,7 +144,6 @@ bool db_query_prepared_canfail(struct db_stmt *stmt) assert(stmt->query->readonly); trace_span_start("db_query_prepared", stmt); trace_span_tag(stmt, "query", stmt->query->query); - db_need_transaction(stmt->db, stmt->query->query); ret = stmt->db->config->query_fn(stmt); stmt->executed = true; list_del_from(&stmt->db->pending_statements, &stmt->list);