From e20781de72779272e15360e009982ee6b47bf8ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enis=20Bayramo=C4=9Flu?= Date: Wed, 30 Nov 2022 14:22:39 +0100 Subject: [PATCH] Add requestkey indexes on events and transactions (#98) As identified by @blazesal in https://github.com/kadena-io/chainweb-data/issues/79, our `/txs/tx` endpoint requires a requestkey index on the events and transactions tables, otherwise each request results in a table scan. I've just tried creating these indexes manually and checking their sizes; As of now, the requestkey index on the transactions table takes up 603MB of space while the one on events takes up 879MB. For comparison, these total space occupied by these two tables is ~46GB. --- exec/Main.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/exec/Main.hs b/exec/Main.hs index 9b0d9651..79c0cab4 100644 --- a/exec/Main.hs +++ b/exec/Main.hs @@ -69,6 +69,8 @@ main = do addEventsHeightNameParamsIndex logg conn addFromAccountsIndex logg conn addToAccountsIndex logg conn + addTransactionsRequestKeyIndex logg conn + addEventsRequestKeyIndex logg conn logg Info "DB Tables Initialized" let mgrSettings = mkManagerSettings (TLSSettingsSimple True False False) Nothing m <- newManager mgrSettings @@ -170,6 +172,24 @@ addToAccountsIndex = , statement = "CREATE INDEX IF NOT EXISTS transfers_to_acct_height_idx_idx ON transfers (to_acct, height desc, idx);" } +addTransactionsRequestKeyIndex :: LogFunctionIO Text -> Connection -> IO () +addTransactionsRequestKeyIndex = + addIndex + IndexCreationInfo + { + message = "Adding \"(requestkey)\" index on transactions table" + , statement = "CREATE INDEX IF NOT EXISTS transactions_requestkey_idx ON transactions (requestkey);" + } + +addEventsRequestKeyIndex :: LogFunctionIO Text -> Connection -> IO () +addEventsRequestKeyIndex = + addIndex + IndexCreationInfo + { + message = "Adding \"(requestkey)\" index on events table" + , statement = "CREATE INDEX IF NOT EXISTS events_requestkey_idx ON events (requestkey);" + } + {- λ> :main single --chain 2 --height 1487570 --service-host api.chainweb.com --p2p-host us-e3.chainweb.com --dbname chainweb-data --service-port 443 --service-https λ> :main single --chain 0 --height 1494311 --service-host api.chainweb.com --p2p-host us-e3.chainweb.com --dbname chainweb-data --service-port 443 --service-https