Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize queries for account_tx to work around SQLite query planner #2312

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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