diff --git a/hive/db/db_state.py b/hive/db/db_state.py index 1638a273ef3f86c8b09dc5c82d7a8c1b8cc2d187..b6af6fa0596bcb83d9d8348f62228383eccf0eb3 100644 --- a/hive/db/db_state.py +++ b/hive/db/db_state.py @@ -108,17 +108,17 @@ class DbState: 'hive_posts_root_id_id_idx', 'hive_posts_community_id_idx', - 'hive_posts_category_id_idx', 'hive_posts_payout_at_idx', 'hive_posts_payout_idx', - 'hive_posts_promoted_idx', - 'hive_posts_sc_trend_id_is_paidout_idx', - 'hive_posts_sc_hot_id_is_paidout_idx', + 'hive_posts_promoted_id_idx', + 'hive_posts_sc_trend_id_idx', + 'hive_posts_sc_hot_id_idx', 'hive_posts_block_num_idx', 'hive_posts_block_num_created_idx', 'hive_posts_cashout_time_id_idx', 'hive_posts_updated_at_idx', - 'hive_posts_payout_plus_pending_payout_id_is_paidout_idx', + 'hive_posts_payout_plus_pending_payout_id_idx', + 'hive_posts_category_id_payout_plus_pending_payout_depth_idx', 'hive_posts_api_helper_author_s_permlink_idx', diff --git a/hive/db/schema.py b/hive/db/schema.py index 046aed727c3a4ae9394eca325b4306ad6fe0a05e..a1fc3ec4c3ae6a2e191b52fc8f53a89820311c37 100644 --- a/hive/db/schema.py +++ b/hive/db/schema.py @@ -139,18 +139,18 @@ def build_metadata(): sa.Index('hive_posts_parent_id_idx', 'parent_id'), sa.Index('hive_posts_community_id_idx', 'community_id'), - sa.Index('hive_posts_category_id_idx', 'category_id'), sa.Index('hive_posts_payout_at_idx', 'payout_at'), sa.Index('hive_posts_payout_idx', 'payout'), - sa.Index('hive_posts_promoted_idx', 'promoted'), - sa.Index('hive_posts_sc_trend_id_is_paidout_idx', 'sc_trend', 'id', 'is_paidout'), - sa.Index('hive_posts_sc_hot_id_is_paidout_idx', 'sc_hot', 'id', 'is_paidout'), + 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_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'), sa.Index('hive_posts_updated_at_idx', sa.text('updated_at DESC')), - sa.Index('hive_posts_payout_plus_pending_payout_id_is_paidout_idx', sa.text('(payout+pending_payout), id, is_paidout')) + sa.Index('hive_posts_payout_plus_pending_payout_id_idx', sa.text('(payout+pending_payout), id, is_paidout'), postgresql_where=sql_text("counter_deleted = 0 AND NOT is_paidout")), + sa.Index('hive_posts_category_id_payout_plus_pending_payout_depth_idx', sa.text('category_id, (payout+pending_payout), depth'), postgresql_where=sql_text("NOT is_paidout AND counter_deleted = 0")) ) sa.Table( diff --git a/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql b/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql index 85991ad0915c5d35dff4d4ac0215357ea85b71bf..743dce0c345f78657ad24dfb9ebf7d0fe6bc79ba 100644 --- a/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql +++ b/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql @@ -326,3 +326,34 @@ CREATE INDEX IF NOT EXISTS hive_notification_cache_dst_score_idx ON hive_notific CREATE INDEX IF NOT EXISTS hive_feed_cache_block_num_idx on hive_feed_cache (block_num); CREATE INDEX IF NOT EXISTS hive_feed_cache_created_at_idx on hive_feed_cache (created_at); +--- condenser_get_trending_tags optimizations and slight index improvements. + +DROP INDEX IF EXISTS hive_posts_category_id_idx; + +CREATE INDEX IF NOT EXISTS hive_posts_category_id_payout_plus_pending_payout_depth_idx ON hive_posts (category_id, (payout + pending_payout), depth) + WHERE NOT is_paidout AND counter_deleted = 0; + +DROP INDEX IF EXISTS hive_posts_sc_trend_id_is_paidout_idx; + +CREATE INDEX IF NOT EXISTS hive_posts_sc_trend_id_idx ON hive_posts USING btree (sc_trend, id) + WHERE NOT is_paidout AND counter_deleted = 0 AND depth = 0 +; + +DROP INDEX IF EXISTS hive_posts_sc_hot_id_is_paidout_idx; + +CREATE INDEX IF NOT EXISTS hive_posts_sc_hot_id_idx ON hive_posts (sc_hot, id) + WHERE NOT is_paidout AND counter_deleted = 0 AND depth = 0 + ; + +DROP INDEX IF EXISTS hive_posts_payout_plus_pending_payout_id_is_paidout_idx; + +CREATE INDEX IF NOT EXISTS hive_posts_payout_plus_pending_payout_id_idx ON hive_posts ((payout + pending_payout), id) + WHERE counter_deleted = 0 AND NOT is_paidout +; + +DROP INDEX IF EXISTS hive_posts_promoted_idx; + +CREATE INDEX IF NOT EXISTS hive_posts_promoted_id_idx ON hive_posts (promoted, id) + WHERE NOT is_paidout AND counter_deleted = 0 + ; +