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

fix: index on principal_stx_txs table for faster /v1/address/{addr}/transactions lookups #2059

Merged
merged 2 commits into from
Aug 21, 2024

Conversation

zone117x
Copy link
Member

This index speeds up the sql query for the /v1/address/{addr}/transactions endpoint.

Testing this query against a mainnet dev cluster db:

      WITH stx_txs AS (
        SELECT tx_id, index_block_hash, microblock_hash, (COUNT(*) OVER())::INTEGER AS count
        FROM principal_stx_txs
        WHERE principal = 'SP3D6PV2ACBPEKYJTCMH7HEN02KP87QSP8KTEH335.megapont-robot-component-nft'
          AND block_height <= 162751
          AND canonical = TRUE
          AND microblock_canonical = TRUE
        ORDER BY block_height DESC, microblock_sequence DESC, tx_index DESC
        LIMIT 50
        OFFSET 0
      )
      SELECT *,
        count
      FROM stx_txs
      INNER JOIN txs USING (tx_id, index_block_hash, microblock_hash)

With this index it takes 200ms, without it was taking over 2 minutes.

Copy link

codecov bot commented Aug 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Copy link

github-actions bot commented Aug 21, 2024

Vercel deployment URL: https://stacks-blockchain-4awo199i0-hirosystems.vercel.app 🚀

Copy link
Collaborator

@rafaelcr rafaelcr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch 👌🏻

@zone117x zone117x merged commit ab64ab7 into master Aug 21, 2024
29 checks passed
@zone117x zone117x deleted the fix/principal-stx-txs-idx branch August 21, 2024 15:17
blockstack-devops pushed a commit that referenced this pull request Aug 21, 2024
## [7.14.1](v7.14.0...v7.14.1) (2024-08-21)

### Bug Fixes

* index on `principal_stx_txs` table for faster `/v1/address/{addr}/transactions` lookups ([#2059](#2059)) ([ab64ab7](ab64ab7))
@blockstack-devops
Copy link

🎉 This PR is included in version 7.14.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

blockstack-devops pushed a commit that referenced this pull request Aug 27, 2024
## [8.0.0-beta.6](v8.0.0-beta.5...v8.0.0-beta.6) (2024-08-27)

### ⚠ BREAKING CHANGES

* refactor from express to fastify (#2045)

### Features

* cursor-based pagination on blocks endpoint ([#2060](#2060)) ([bfdcce1](bfdcce1))
* export events tsv directly to postgres instance ([#2048](#2048)) ([f401a0f](f401a0f))
* export events tsv directly to postgres instance ([#2048](#2048)) ([#2058](#2058)) ([a1f5b12](a1f5b12))
* refactor from express to fastify ([#2045](#2045)) ([bd65fcf](bd65fcf)), closes [#2042](#2042)

### Bug Fixes

* index on `principal_stx_txs` table for faster `/v1/address/{addr}/transactions` lookups ([#2059](#2059)) ([ab64ab7](ab64ab7))
@blockstack-devops
Copy link

🎉 This PR is included in version 8.0.0-beta.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants