Skip to content

Instantly share code, notes, and snippets.

@wchargin
Created January 11, 2022 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wchargin/dfcd9f6eabe5af236f62edf07b3131d3 to your computer and use it in GitHub Desktop.
Save wchargin/dfcd9f6eabe5af236f62edf07b3131d3 to your computer and use it in GitHub Desktop.
EXPLAIN ANALYZE
SELECT
projects.slug,
token_index,
current_owner
FROM (
SELECT
token_id,
to_address AS current_owner
FROM (
SELECT
token_id,
rank() OVER (PARTITION BY token_id ORDER BY block_number DESC, log_index DESC) AS rank,
to_address
FROM erc_721_transfers
-- Change this part to "WHERE token_id IN (SELECT ...)" for a
-- project-specific query, or drop the "WHERE" clause to check all tokens.
WHERE token_id = (
SELECT token_id FROM tokens JOIN projects USING (project_id)
WHERE slug = 'ringers' AND token_index = 851
)
) AS ranked_transfers
WHERE rank = 1
) AS token_owners
JOIN tokens USING (token_id)
JOIN projects USING (project_id)
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment