CodeChain-io / codechain-indexer

A blockchain data indexing tool for CodeChain
Apache License 2.0
21 stars 15 forks source link

Use an index to find rows in the next page in the BalanceHistory query #353

Closed majecty closed 5 years ago

majecty commented 5 years ago

The indexer was using SQL's skip for the pagination. The DB should scan the number of skipped rows, to get the page result. For the performance enhancement, we concluded that change the pagination method. Finding a particular row using an index and get the following n rows is much faster than using skip.

This commit uses firstEvaluatedKey and lastEvaluatedKey for the pagination in the BalanceHistory query. The BalanceHistory query will find a row using firstEvaluatedKey or lastEvaluatedKey and returns next n rows.

joojis commented 5 years ago

I've merged it manually because of the conflicts.

https://github.com/CodeChain-io/codechain-indexer/commit/43e7a0f949f3b46d22549884e1351f631e9a845a