Add additional database indexes for better query performance
- Add covering index for SELECT id queries (avoids table lookups) - Add stats index for COUNT queries on live_routes - Add index on asns.number for ASN lookups - Add index on bgp_peers.peer_ip for peer lookups These indexes should further reduce query times, especially: - The covering index includes the id column, eliminating the need to access the table after index lookup - The stats index helps with COUNT(*) queries - The asns.number index speeds up ASN lookups in transactions
This commit is contained in:
parent
4a3d71d307
commit
6f0f217379
@ -94,9 +94,23 @@ CREATE INDEX IF NOT EXISTS idx_live_routes_withdraw
|
||||
ON live_routes(prefix_id, peer_asn)
|
||||
WHERE withdrawn_at IS NULL;
|
||||
|
||||
-- Covering index for SELECT id queries (includes id in index)
|
||||
CREATE INDEX IF NOT EXISTS idx_live_routes_covering
|
||||
ON live_routes(prefix_id, origin_asn_id, peer_asn, id)
|
||||
WHERE withdrawn_at IS NULL;
|
||||
|
||||
-- Index for stats queries
|
||||
CREATE INDEX IF NOT EXISTS idx_live_routes_stats
|
||||
ON live_routes(withdrawn_at)
|
||||
WHERE withdrawn_at IS NULL;
|
||||
|
||||
-- Additional indexes for prefixes table
|
||||
CREATE INDEX IF NOT EXISTS idx_prefixes_prefix ON prefixes(prefix);
|
||||
|
||||
-- Indexes for asns table
|
||||
CREATE INDEX IF NOT EXISTS idx_asns_number ON asns(number);
|
||||
|
||||
-- Indexes for bgp_peers table
|
||||
CREATE INDEX IF NOT EXISTS idx_bgp_peers_asn ON bgp_peers(peer_asn);
|
||||
CREATE INDEX IF NOT EXISTS idx_bgp_peers_last_seen ON bgp_peers(last_seen);
|
||||
CREATE INDEX IF NOT EXISTS idx_bgp_peers_last_seen ON bgp_peers(last_seen);
|
||||
CREATE INDEX IF NOT EXISTS idx_bgp_peers_ip ON bgp_peers(peer_ip);
|
Loading…
Reference in New Issue
Block a user