-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
629 additions
and
386 deletions.
There are no files selected for viewing
41 changes: 22 additions & 19 deletions
41
tapdb/sqlc/migrations/000024_universe_optimization_indexes_queries.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
-- Drop indices on universe_roots | ||
DROP INDEX IF EXISTS idx_universe_roots_asset_group_proof; | ||
DROP INDEX IF EXISTS idx_universe_roots_proof_type_issuance; | ||
|
||
-- Drop in reverse order of dependencies | ||
DROP INDEX IF EXISTS idx_multiverse_leaves_composite; | ||
DROP INDEX IF EXISTS idx_federation_sync_composite; | ||
DROP INDEX IF EXISTS idx_universe_events_root_type; | ||
DROP INDEX IF EXISTS idx_universe_events_stats; | ||
DROP INDEX IF EXISTS idx_mssmt_nodes_key_lookup; | ||
DROP INDEX IF EXISTS idx_mssmt_nodes_namespace; | ||
DROP INDEX IF EXISTS idx_universe_leaves_sort; | ||
DROP INDEX IF EXISTS idx_universe_leaves_lookup; | ||
DROP INDEX IF EXISTS idx_universe_roots_issuance; | ||
DROP INDEX IF EXISTS idx_universe_roots_namespace; | ||
-- Drop indices on universe_events | ||
DROP INDEX IF EXISTS idx_universe_events_type_counts; | ||
DROP INDEX IF EXISTS idx_universe_events_universe_root_id; | ||
DROP INDEX IF EXISTS idx_universe_events_sync; | ||
|
||
-- Update statistics | ||
ANALYZE universe_roots; | ||
ANALYZE universe_leaves; | ||
ANALYZE mssmt_nodes; | ||
ANALYZE universe_events; | ||
ANALYZE federation_proof_sync_log; | ||
ANALYZE multiverse_leaves; | ||
ANALYZE multiverse_roots; | ||
-- Drop indices on tables underlying key_group_info_view | ||
DROP INDEX IF EXISTS idx_asset_group_witnesses_gen_asset_id; | ||
|
||
-- Drop indices on mssmt_roots | ||
DROP INDEX IF EXISTS idx_mssmt_roots_hash_namespace; | ||
|
||
-- Drop indices on genesis_assets | ||
DROP INDEX IF EXISTS idx_genesis_assets_asset_id; | ||
DROP INDEX IF EXISTS idx_genesis_assets_asset_tag; | ||
DROP INDEX IF EXISTS idx_genesis_assets_asset_type; | ||
|
||
-- Drop indices on universe_leaves | ||
DROP INDEX IF EXISTS idx_universe_leaves_universe_root_id; | ||
DROP INDEX IF EXISTS idx_universe_leaves_asset_genesis_id; | ||
DROP INDEX IF EXISTS idx_universe_leaves_leaf_node_key_namespace; |
96 changes: 43 additions & 53 deletions
96
tapdb/sqlc/migrations/000024_universe_optimization_indexes_queries.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,43 @@ | ||
-- Core universe_roots indexes | ||
CREATE INDEX IF NOT EXISTS idx_universe_roots_namespace | ||
ON universe_roots(namespace_root, id, asset_id, group_key, proof_type); | ||
|
||
CREATE INDEX IF NOT EXISTS idx_universe_roots_issuance | ||
ON universe_roots(proof_type, group_key, id, asset_id, namespace_root); | ||
|
||
-- Universe leaves optimization | ||
CREATE INDEX IF NOT EXISTS idx_universe_leaves_lookup | ||
ON universe_leaves( | ||
leaf_node_namespace, minting_point, script_key_bytes, | ||
id, leaf_node_key, universe_root_id, asset_genesis_id | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS idx_universe_leaves_sort | ||
ON universe_leaves(leaf_node_namespace, id, minting_point, script_key_bytes); | ||
|
||
-- MSSMT nodes optimization | ||
CREATE INDEX IF NOT EXISTS idx_mssmt_nodes_namespace | ||
ON mssmt_nodes(namespace, hash_key, key, value, sum); | ||
|
||
CREATE INDEX IF NOT EXISTS idx_mssmt_nodes_key_lookup | ||
ON mssmt_nodes(key, namespace, hash_key, value, sum); | ||
|
||
-- Universe events optimization | ||
CREATE INDEX IF NOT EXISTS idx_universe_events_stats | ||
ON universe_events(event_type, event_timestamp); | ||
|
||
CREATE INDEX IF NOT EXISTS idx_universe_events_root_type | ||
ON universe_events(universe_root_id, event_type); | ||
|
||
-- Federation sync log optimization | ||
CREATE INDEX IF NOT EXISTS idx_federation_sync_composite | ||
ON federation_proof_sync_log( | ||
sync_direction, proof_leaf_id, universe_root_id, servers_id, | ||
id, status, timestamp, attempt_counter | ||
); | ||
|
||
-- Multiverse optimization | ||
CREATE INDEX IF NOT EXISTS idx_multiverse_leaves_composite | ||
ON multiverse_leaves( | ||
multiverse_root_id, leaf_node_namespace, | ||
asset_id, group_key, leaf_node_key | ||
); | ||
|
||
-- Analyze existing tables | ||
ANALYZE universe_roots; | ||
ANALYZE universe_leaves; | ||
ANALYZE mssmt_nodes; | ||
ANALYZE universe_events; | ||
ANALYZE federation_proof_sync_log; | ||
ANALYZE multiverse_leaves; | ||
ANALYZE multiverse_roots; | ||
-- Composite index supporting joins and GROUP BY | ||
CREATE INDEX IF NOT EXISTS idx_universe_roots_asset_group_proof | ||
ON universe_roots (asset_id, group_key, proof_type); | ||
|
||
-- Partial index for proof_type = 'issuance' | ||
CREATE INDEX IF NOT EXISTS idx_universe_roots_proof_type_issuance | ||
ON universe_roots (proof_type); | ||
|
||
-- Composite index supporting event_type and universe_root_id | ||
CREATE INDEX IF NOT EXISTS idx_universe_events_type_counts | ||
ON universe_events (event_type, universe_root_id); | ||
|
||
-- Separate index on universe_root_id | ||
CREATE INDEX IF NOT EXISTS idx_universe_events_universe_root_id | ||
ON universe_events (universe_root_id); | ||
|
||
-- Partial index for event_type = 'SYNC' | ||
CREATE INDEX IF NOT EXISTS idx_universe_events_sync | ||
ON universe_events (event_type); | ||
|
||
-- Indices on tables underlying key_group_info_view | ||
CREATE INDEX IF NOT EXISTS idx_asset_group_witnesses_gen_asset_id | ||
ON asset_group_witnesses (gen_asset_id); | ||
|
||
-- Indices on mssmt_roots | ||
CREATE INDEX IF NOT EXISTS idx_mssmt_roots_hash_namespace | ||
ON mssmt_roots (root_hash, namespace); | ||
|
||
-- Indices on genesis_assets | ||
CREATE INDEX IF NOT EXISTS idx_genesis_assets_asset_id | ||
ON genesis_assets (asset_id); | ||
CREATE INDEX IF NOT EXISTS idx_genesis_assets_asset_tag | ||
ON genesis_assets (asset_tag); | ||
CREATE INDEX IF NOT EXISTS idx_genesis_assets_asset_type | ||
ON genesis_assets (asset_type); | ||
|
||
-- Indices on universe_leaves | ||
CREATE INDEX IF NOT EXISTS idx_universe_leaves_universe_root_id | ||
ON universe_leaves (universe_root_id); | ||
CREATE INDEX IF NOT EXISTS idx_universe_leaves_asset_genesis_id | ||
ON universe_leaves (asset_genesis_id); | ||
CREATE INDEX IF NOT EXISTS idx_universe_leaves_leaf_node_key_namespace | ||
ON universe_leaves (leaf_node_key, leaf_node_namespace); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.