diff --git a/hive/db/db_state.py b/hive/db/db_state.py index f3f98834c225b9acd6f72810b3df6544e72b1465..a823d01cc4d825ba6c00230a7c3438bcb704ceb1 100644 --- a/hive/db/db_state.py +++ b/hive/db/db_state.py @@ -99,7 +99,7 @@ class DbState: 'hive_posts_parent_id_idx', 'hive_posts_depth_idx', - 'hive_posts_created_at_author_id_idx', + 'hive_posts_author_id_created_at_idx', 'hive_posts_root_id_id_idx', 'hive_posts_community_id_idx', diff --git a/hive/db/schema.py b/hive/db/schema.py index 1a51eb749d5b34e5e0776880c01746a5fe84779d..f6a1332725aec0b2e0ac54f9277adeb1574cf986 100644 --- a/hive/db/schema.py +++ b/hive/db/schema.py @@ -144,7 +144,7 @@ def build_metadata(): 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_created_at_author_id_idx', 'created_at', 'author_id'), + 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'), diff --git a/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql b/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql index 24fd2d572dd5f56c9233dc076d944c801417234a..149829cc24fb357c7b93af77fe16d48d0bfa1157 100644 --- a/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql +++ b/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql @@ -286,3 +286,10 @@ IF EXISTS (SELECT * FROM pg_constraint WHERE conname='hive_votes_ux1') THEN END IF; END $$ +; + +--- Change definition of index hive_posts_created_at_author_id_idx to hive_posts_author_id_created_at_idx to improve hive_accounts_info_view performance. +DROP INDEX IF EXISTS public.hive_posts_created_at_author_id_idx; + +CREATE INDEX IF NOT EXISTS hive_posts_author_id_created_at_idx ON public.hive_posts ( author_id DESC, created_at DESC); +