Skip to content

Commit

Permalink
Add requestkey indexes on events and transactions
Browse files Browse the repository at this point in the history
As identified by @blazesal in
#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.
  • Loading branch information
enobayram committed Nov 29, 2022
1 parent 70669e0 commit d3705a2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions exec/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d3705a2

Please sign in to comment.