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

feat(relayer): add indexer for MAX() in MySQL #16077

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

xiaodino
Copy link
Contributor

It's to optimize the query

SELECT `id`, `block_height`, `hash`, `event_name`, `chain_id`
FROM `processed_blocks`
WHERE `block_height` = (
  SELECT MAX(`block_height`)
  FROM `processed_blocks`
  WHERE `chain_id` = ? AND `event_name` = ?
)

The subquery filters rows based on chain_id and event_name and then finds the maximum block_height. An index that includes these three columns can significantly improve the performance of the subquery by allowing MySQL to quickly locate the rows that match the given chain_id and event_name, and then efficiently determine the maximum block_height among those rows.

@xiaodino xiaodino added this pull request to the merge queue Feb 26, 2024
Merged via the queue into main with commit b079ead Feb 26, 2024
8 checks passed
@xiaodino xiaodino deleted the xiaodino/add-indexer-relayer-2 branch February 26, 2024 07:35
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.

None yet

3 participants