Skip to content

Further optimize allUrns query#220

Merged
paytonrules merged 1 commit intostagingfrom
vdb-1411-replace-distinct-with-group-by-in-all-urns
Jul 2, 2020
Merged

Further optimize allUrns query#220
paytonrules merged 1 commit intostagingfrom
vdb-1411-replace-distinct-with-group-by-in-all-urns

Conversation

@paytonrules
Copy link
Copy Markdown
Contributor

@paytonrules paytonrules commented Jul 1, 2020

Replace DISTINCT with GROUP BY and inner join which reduces the time for me locally against staging.

For the original query a recent run gives me:

WITH distinct_urn_snapshots AS (
    SELECT DISTINCT ON (urn_identifier, ilk_identifier)
        urn_identifier, ilk_identifier, block_height, ink, coalesce(art, 0), created, updated
        FROM api.urn_snapshot
        WHERE block_height <= api.max_block()
        ORDER BY urn_identifier, ilk_identifier, updated DESC)
SELECT *
    FROM distinct_urn_snapshots
    LIMIT NULL::integer
    OFFSET 0
Successfully run. Total query runtime: 895 msec.
8057 rows affected.

The new version:

-- My database has been migrated
SELECT * from api.all_urns();
Successfully run. Total query runtime: 321 msec.
8057 rows affected.

Copy link
Copy Markdown
Contributor

@rmulhol rmulhol left a comment

Choose a reason for hiding this comment

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

LGTM!

Could be cool to drop the benchmarks/query plans in the PR description for additional context - I wouldn't have expected a significant difference between these implementations

Replace DISTINCT with GROUP BY and inner join which reduces the time for
me locally against staging from about 900ms to 300ms. Give or take.
@paytonrules paytonrules force-pushed the vdb-1411-replace-distinct-with-group-by-in-all-urns branch from 1ccac79 to 8134b72 Compare July 2, 2020 15:29
@paytonrules paytonrules merged commit 69044f3 into staging Jul 2, 2020
@paytonrules paytonrules deleted the vdb-1411-replace-distinct-with-group-by-in-all-urns branch August 26, 2020 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants