diff --git a/ddl/migrations/0218_playlist_trending_scores_ordered_idx.sql b/ddl/migrations/0218_playlist_trending_scores_ordered_idx.sql new file mode 100644 index 00000000..b4eef88e --- /dev/null +++ b/ddl/migrations/0218_playlist_trending_scores_ordered_idx.sql @@ -0,0 +1,10 @@ +-- Hot playlist trending callers order by score DESC, playlist_id DESC after +-- filtering on type/version/time_range. Put the ordering columns immediately +-- after the equality predicates so PostgreSQL can satisfy the LIMIT without a +-- parallel scan and sort. + +create index concurrently if not exists idx_playlist_trending_scores_ordered + on playlist_trending_scores (type, version, time_range, score desc, playlist_id desc); + +comment on index idx_playlist_trending_scores_ordered is + 'Covers playlist trending endpoints ordered by score desc, playlist_id desc.';