Skip to content
Snippets Groups Projects
Commit 221dd70b authored by Dan Notestein's avatar Dan Notestein
Browse files

Merge branch 'dn_new_indexes' into 'develop'

Added/modified indexes for hive_posts and hive_feed_cache to speed up queries

See merge request !452
parents 0ca3cd16 edb2a351
No related branches found
Tags v1.24-RC
2 merge requests!456Release candidate v1 24,!452Added/modified indexes for hive_posts and hive_feed_cache to speed up queries
......@@ -96,15 +96,15 @@ class DbState:
'hive_feed_cache_block_num_idx',
'hive_feed_cache_created_at_idx',
'hive_feed_cache_post_id_idx',
'hive_follows_ix5a', # (following, state, created_at, follower)
'hive_follows_ix5b', # (follower, state, created_at, following)
'hive_follows_block_num_idx',
'hive_follows_created_at_idx',
'hive_posts_parent_id_idx',
'hive_posts_parent_id_counter_deleted_id_idx',
'hive_posts_depth_idx',
'hive_posts_author_id_created_at_idx',
'hive_posts_root_id_id_idx',
'hive_posts_community_id_id_idx',
......@@ -120,6 +120,9 @@ class DbState:
'hive_posts_payout_plus_pending_payout_id_idx',
'hive_posts_category_id_payout_plus_pending_payout_depth_idx',
'hive_posts_tags_ids_idx',
'hive_posts_author_id_created_at_id_idx',
'hive_posts_author_id_id_idx',
'hive_posts_api_helper_author_s_permlink_idx',
......
......@@ -139,7 +139,7 @@ def build_metadata():
sa.Index('hive_posts_root_id_id_idx', 'root_id','id'),
sa.Index('hive_posts_parent_id_idx', 'parent_id'),
sa.Index('hive_posts_parent_id_counter_deleted_id_idx', 'parent_id', 'counter_deleted', 'id'),
sa.Index('hive_posts_community_id_id_idx', 'community_id', sa.text('id DESC')),
sa.Index('hive_posts_payout_at_idx', 'payout_at'),
......@@ -147,7 +147,8 @@ def build_metadata():
sa.Index('hive_posts_promoted_id_idx', 'promoted', 'id', postgresql_where=sql_text("NOT is_paidout AND counter_deleted = 0")),
sa.Index('hive_posts_sc_trend_id_idx', 'sc_trend', 'id', postgresql_where=sql_text("NOT is_paidout AND counter_deleted = 0 AND depth = 0")),
sa.Index('hive_posts_sc_hot_id_idx', 'sc_hot', 'id', postgresql_where=sql_text("NOT is_paidout AND counter_deleted = 0 AND depth = 0")),
sa.Index('hive_posts_author_id_created_at_idx', sa.text('author_id DESC, created_at DESC')),
sa.Index('hive_posts_author_id_created_at_id_idx', sa.text('author_id DESC, created_at DESC, id')),
sa.Index('hive_posts_author_id_id_idx', 'author_id', 'id', postgresql_where=sql_text('depth = 0')),
sa.Index('hive_posts_block_num_idx', 'block_num'),
sa.Index('hive_posts_block_num_created_idx', 'block_num_created'),
sa.Index('hive_posts_cashout_time_id_idx', 'cashout_time', 'id'),
......@@ -283,7 +284,8 @@ def build_metadata():
sa.ForeignKeyConstraint(['block_num'], ['hive_blocks.num'], name='hive_feed_cache_fk1'),
sa.Index('hive_feed_cache_block_num_idx', 'block_num'),
sa.Index('hive_feed_cache_created_at_idx', 'created_at')
sa.Index('hive_feed_cache_created_at_idx', 'created_at'),
sa.Index('hive_feed_cache_post_id_idx', 'post_id')
)
sa.Table(
......
......@@ -12,10 +12,12 @@ BEGIN
__post_id = find_comment_id( _author, _permlink, True );
RETURN QUERY SELECT
name
ha.name
FROM hive_accounts ha
JOIN hive_feed_cache hfc ON ha.id = hfc.account_id
WHERE hfc.post_id = __post_id;
WHERE hfc.post_id = __post_id
ORDER BY ha.name
;
END
$function$
......
......@@ -223,7 +223,7 @@ values
,(now(), 'a80c7642a1f3b08997af7e8a9915c13d34b7f0e0') -- Notification IDs https://gitlab.syncad.com/hive/hivemind/-/merge_requests/445
,(now(), 'b100db27f37dda3c869c2756d99ab2856f7da9f9') -- hive_notification_cache table supplement https://gitlab.syncad.com/hive/hivemind/-/merge_requests/447
,(now(), 'bd83414409b7624e2413b97a62fa7d97d83edd86') -- follow notification time is taken from block affecting it https://gitlab.syncad.com/hive/hivemind/-/merge_requests/449
,(now(), 'd64c73792175b12684ec74691297782cf67a2093') -- https://gitlab.syncad.com/hive/hivemind/-/merge_requests/452
) ds (patch_date, patch_revision)
where not exists (select null from hive_db_patch_level hpl where hpl.patched_to_revision = ds.patch_revision);
......
......@@ -442,3 +442,20 @@ CREATE SEQUENCE IF NOT EXISTS hive_notification_cache_id_seq
ALTER TABLE hive_notification_cache
ALTER COLUMN id SET DEFAULT nextval('hive_notification_cache_id_seq'::regclass);
-- Changes done in https://gitlab.syncad.com/hive/hivemind/-/merge_requests/452
DROP INDEX IF EXISTS hive_posts_parent_id_idx;
CREATE INDEX IF NOT EXISTS hive_posts_parent_id_counter_deleted_id_idx ON hive_posts (parent_id, counter_deleted, id);
DROP INDEX IF EXISTS hive_posts_author_id_created_at_idx;
CREATE INDEX IF NOT EXISTS hive_posts_author_id_created_at_id_idx ON hive_posts (author_id DESC, created_at DESC, id);
DROP INDEX IF EXISTS hive_posts_author_posts_idx;
CREATE INDEX IF NOT EXISTS hive_posts_author_id_id_idx ON hive_posts (author_id, id)
WHERE depth = 0;
CREATE INDEX IF NOT EXISTS hive_feed_cache_post_id_idx ON hive_feed_cache (post_id);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment