Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions hive/db/db_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,21 @@ def _check_migrations(cls):
log.info("[HIVE] Slow query optimization indexes created")
cls._set_ver(27)

if cls._ver == 27:
# Performance: index for hive_notifs sync hot-path
# The indexer's notify-account-votes query (SELECT 1 FROM hive_notifs
# WHERE dst_id = :dst_id AND post_id = :post_id AND type_id = 16)
# was doing a full table scan (~2s per query on 97M rows), causing
# sync to stall. This index reduces it to <1ms.
log.info("[HIVE] Creating hive_notifs_dst_post_type_idx index...")
cls.db().query("""
CREATE INDEX CONCURRENTLY IF NOT EXISTS hive_notifs_dst_post_type_idx
ON hive_notifs (dst_id, post_id, type_id)
""")
cls.db().query("ANALYZE hive_notifs")
log.info("[HIVE] hive_notifs_dst_post_type_idx index created")
cls._set_ver(28)

reset_autovac(cls.db())

log.info("[HIVE] db version: %d", cls._ver)
Expand Down
2 changes: 1 addition & 1 deletion hive/db/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#pylint: disable=line-too-long, too-many-lines, bad-whitespace

DB_VERSION = 27
DB_VERSION = 28

def build_metadata():
"""Build schema def with SqlAlchemy"""
Expand Down
Loading