Skip to content

Commit

Permalink
Optimize queries for account_tx to work around SQLite query planner.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrippled committed Jan 1, 2018
1 parent dc9e9f4 commit 9a3bc88
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions src/ripple/app/misc/impl/AccountTxPaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,27 @@ accountTxPage (
}
else if (forward && (findLedger != 0))
{
auto b58acct = idCache.toBase58(account);
sql = boost::str (boost::format(
prefix +
(R"(
AccountTransactions.LedgerSeq BETWEEN '%u' AND '%u' OR
( AccountTransactions.LedgerSeq = '%u' AND
AccountTransactions.TxnSeq >= '%u' )
(R"(SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,
Status,RawTxn,TxnMeta
FROM AccountTransactions, Transactions WHERE
(AccountTransactions.TransID = Transactions.TransID AND
AccountTransactions.Account = '%s' AND
AccountTransactions.LedgerSeq BETWEEN '%u' AND '%u')
OR
(AccountTransactions.TransID = Transactions.TransID AND
AccountTransactions.Account = '%s' AND
AccountTransactions.LedgerSeq = '%u' AND
AccountTransactions.TxnSeq >= '%u')
ORDER BY AccountTransactions.LedgerSeq ASC,
AccountTransactions.TxnSeq ASC
LIMIT %u;
)"))
% idCache.toBase58(account)
% b58acct
% (findLedger + 1)
% maxLedger
% b58acct
% findLedger
% findSeq
% queryLimit);
Expand All @@ -174,17 +182,27 @@ accountTxPage (
}
else if (!forward && (findLedger != 0))
{
auto b58acct = idCache.toBase58(account);
sql = boost::str (boost::format(
prefix +
(R"(AccountTransactions.LedgerSeq BETWEEN '%u' AND '%u' OR
(AccountTransactions.LedgerSeq = '%u' AND
AccountTransactions.TxnSeq <= '%u')
ORDER BY AccountTransactions.LedgerSeq DESC,
AccountTransactions.TxnSeq DESC
LIMIT %u;)"))
% idCache.toBase58(account)
(R"(SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,
Status,RawTxn,TxnMeta
FROM AccountTransactions, Transactions WHERE
(AccountTransactions.TransID = Transactions.TransID AND
AccountTransactions.Account = '%s' AND
AccountTransactions.LedgerSeq BETWEEN '%u' AND '%u')
OR
(AccountTransactions.TransID = Transactions.TransID AND
AccountTransactions.Account = '%s' AND
AccountTransactions.LedgerSeq = '%u' AND
AccountTransactions.TxnSeq <= '%u')
ORDER BY AccountTransactions.LedgerSeq DESC,
AccountTransactions.TxnSeq DESC
LIMIT %u;
)"))
% b58acct
% minLedger
% (findLedger - 1)
% b58acct
% findLedger
% findSeq
% queryLimit);
Expand Down

0 comments on commit 9a3bc88

Please sign in to comment.