Skip to content
This repository was archived by the owner on Feb 21, 2025. It is now read-only.

Rewrite cluster status query to only get unique hosts #18

Merged
merged 2 commits into from
Jan 7, 2025

Conversation

nothingface0
Copy link
Contributor

@nothingface0 nothingface0 commented Jan 7, 2025

Previously it was grouping by the is_up column too, returning duplicate host entries.

The query was rewritten to work as intended:

SELECT h.name, t.is_up, t.message, t.created_at
FROM hoststatuses t
JOIN (
    SELECT host_id, MAX(created_at) AS max_created_at
    FROM hoststatuses
    GROUP BY host_id
) sub ON t.host_id = sub.host_id AND t.created_at = sub.max_created_at
JOIN hostnames h ON t.host_id = h.id;

A multicolumn index on host_id and created_at was created for the hoststatuses table to increase performance.

Queries now take ~150 ms (compare to the ~220 ms it took before).

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Previously it was grouping by the is_up column too,
returning duplicate host entries.
This should make the queries noticeably faster.
@nothingface0 nothingface0 merged commit d8367ca into dev Jan 7, 2025
2 checks passed
@nothingface0 nothingface0 deleted the fix_status_query branch January 7, 2025 13:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant