From 2a5660b3bca78b8f49f5c57ea3ed7083efdfc423 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 19 Sep 2022 10:19:52 +0930 Subject: [PATCH] lightningd: index to speed up sendpay / listsendpays contrib/giantnode.py shows we're spending a lot of time looking up payments by payment_hash: sendpays does it to see if we've already paid, and bookkeeper does it in listsendpays: ``` - 94.52% 0.00% lightningd lightningd [.] read_json - 94.52% read_json - 94.48% parse_request - 94.46% plugin_hook_call_rpc_command - plugin_hook_call_ - rpc_command_hook_final - 94.46% command_exec - 49.08% json_sendpay - 49.01% send_payment - 48.86% send_payment_core - 48.84% wallet_payment_list - 48.80% db_step + db_sqlite3_step - 45.38% json_listsendpays - 45.36% wallet_payment_list - 45.30% db_step + 45.30% db_sqlite3_step ``` This doesn't actually make much of a difference, so see next patch. Signed-off-by: Rusty Russell --- wallet/db.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wallet/db.c b/wallet/db.c index 88cd1ed10..51a507543 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -885,7 +885,8 @@ static struct migration dbmigrations[] = { {SQL("ALTER TABLE channels ADD alias_remote BIGINT DEFAULT NULL"), NULL}, /* Cheeky immediate completion as best effort approximation of real completion time */ {SQL("ALTER TABLE payments ADD completed_at INTEGER DEFAULT NULL;"), NULL}, - {SQL("UPDATE payments SET completed_at = timestamp WHERE status != 0;"), NULL} + {SQL("UPDATE payments SET completed_at = timestamp WHERE status != 0;"), NULL}, + {SQL("CREATE INDEX payments_idx ON payments (payment_hash)"), NULL}, }; /* Released versions are of form v{num}[.{num}]* */