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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2025-11-20 12:07:17 +10:30
parent b4f17508b1
commit 47ab467bc1

View File

@@ -144,7 +144,6 @@ bool db_query_prepared_canfail(struct db_stmt *stmt)
assert(stmt->query->readonly); assert(stmt->query->readonly);
trace_span_start("db_query_prepared", stmt); trace_span_start("db_query_prepared", stmt);
trace_span_tag(stmt, "query", stmt->query->query); trace_span_tag(stmt, "query", stmt->query->query);
db_need_transaction(stmt->db, stmt->query->query);
ret = stmt->db->config->query_fn(stmt); ret = stmt->db->config->query_fn(stmt);
stmt->executed = true; stmt->executed = true;
list_del_from(&stmt->db->pending_statements, &stmt->list); list_del_from(&stmt->db->pending_statements, &stmt->list);