-
Notifications
You must be signed in to change notification settings - Fork 121
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
tapdb: fix performance of aggregate stats #1310
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- This file is empty on purpose. There is nothing to roll back for this | ||
-- migration. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
DROP VIEW universe_stats; | ||
|
||
CREATE VIEW universe_stats AS | ||
WITH sync_counts AS ( | ||
SELECT universe_root_id, COUNT(*) AS count | ||
FROM universe_events | ||
WHERE event_type = 'SYNC' | ||
GROUP BY universe_root_id | ||
), proof_counts AS ( | ||
SELECT universe_root_id, event_type, COUNT(*) AS count | ||
FROM universe_events | ||
WHERE event_type = 'NEW_PROOF' | ||
GROUP BY universe_root_id, event_type | ||
), aggregated AS ( | ||
SELECT COALESCE(SUM(count), 0) as total_asset_syncs, | ||
0 AS total_asset_proofs, | ||
universe_root_id | ||
FROM sync_counts | ||
GROUP BY universe_root_id | ||
UNION ALL | ||
SELECT 0 AS total_asset_syncs, | ||
COALESCE(SUM(count), 0) as total_asset_proofs, | ||
universe_root_id | ||
FROM proof_counts | ||
GROUP BY universe_root_id | ||
) | ||
SELECT | ||
SUM(ag.total_asset_syncs) AS total_asset_syncs, | ||
SUM(ag.total_asset_proofs) AS total_asset_proofs, | ||
roots.asset_id, | ||
roots.group_key, | ||
roots.proof_type | ||
FROM aggregated ag | ||
JOIN universe_roots roots | ||
ON ag.universe_root_id = roots.id | ||
GROUP BY roots.asset_id, roots.group_key, roots.proof_type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we not tweak the index here like in the test?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same with |
||
ORDER BY roots.asset_id, roots.group_key, roots.proof_type; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ package tapdb | |
const longTestScale = 5 | ||
|
||
var ( | ||
numAssets = 100 * longTestScale | ||
numLeavesPerTree = 300 * longTestScale | ||
numQueries = 100 * longTestScale | ||
numAssets = 100 * longTestScale | ||
numLeavesPerTree = 300 * longTestScale | ||
numQueries = 100 * longTestScale | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the test timeout be a bit longer for the |
||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not want to restore the old
universe_view
in this rollback?