Skip to content

Commit

Permalink
Fix transactions REST API SQL query performance regression (#7834)
Browse files Browse the repository at this point in the history
- Use distinct on (consensus_timestamp) on crypto_transfer and token_transfer table

Signed-off-by: Xin Li <[email protected]>
  • Loading branch information
xin-hedera authored Mar 1, 2024
1 parent 3169fb3 commit 5b974c3
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions hedera-mirror-rest/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,7 @@ const getTransferDistinctTimestampsQuery = (
const joinClause =
(resultTypeQuery || transactionTypeQuery) &&
`join ${Transaction.tableName} as ${Transaction.tableAlias}
on ${fullTimestampColumn} = ${Transaction.getFullName(Transaction.CONSENSUS_TIMESTAMP)} and
${fullPayerAccountIdColumn} = ${Transaction.getFullName(Transaction.PAYER_ACCOUNT_ID)}`;
using (${Transaction.CONSENSUS_TIMESTAMP}, ${Transaction.PAYER_ACCOUNT_ID})`;
const whereClause = buildWhereClause(
accountQuery,
transferTimestampQuery,
Expand All @@ -390,8 +389,8 @@ const getTransferDistinctTimestampsQuery = (
);

return `
select
distinct ${fullTimestampColumn} as consensus_timestamp,
select distinct on (${fullTimestampColumn})
${fullTimestampColumn} as consensus_timestamp,
${fullPayerAccountIdColumn} as payer_account_id
from ${tableName} as ${tableAlias}
${joinClause}
Expand Down

0 comments on commit 5b974c3

Please sign in to comment.