1 -- This converts the old hot_rank functions, to columns
2 -- Remove the old compound indexes
3 DROP INDEX idx_post_aggregates_featured_local_newest_comment_time;
5 DROP INDEX idx_post_aggregates_featured_community_newest_comment_time;
7 DROP INDEX idx_post_aggregates_featured_local_comments;
9 DROP INDEX idx_post_aggregates_featured_community_comments;
11 DROP INDEX idx_post_aggregates_featured_local_hot;
13 DROP INDEX idx_post_aggregates_featured_community_hot;
15 DROP INDEX idx_post_aggregates_featured_local_score;
17 DROP INDEX idx_post_aggregates_featured_community_score;
19 DROP INDEX idx_post_aggregates_featured_local_published;
21 DROP INDEX idx_post_aggregates_featured_community_published;
23 DROP INDEX idx_post_aggregates_featured_local_active;
25 DROP INDEX idx_post_aggregates_featured_community_active;
27 DROP INDEX idx_comment_aggregates_hot;
29 DROP INDEX idx_community_aggregates_hot;
31 -- Add the new hot rank columns for post and comment aggregates
32 -- Note: 1728 is the result of the hot_rank function, with a score of 1, posted now
33 -- hot_rank = 10000*log10(1 + 3)/Power(2, 1.8)
34 ALTER TABLE post_aggregates
35 ADD COLUMN hot_rank integer NOT NULL DEFAULT 1728;
37 ALTER TABLE post_aggregates
38 ADD COLUMN hot_rank_active integer NOT NULL DEFAULT 1728;
40 ALTER TABLE comment_aggregates
41 ADD COLUMN hot_rank integer NOT NULL DEFAULT 1728;
43 ALTER TABLE community_aggregates
44 ADD COLUMN hot_rank integer NOT NULL DEFAULT 1728;
46 -- Populate them initially
47 -- Note: After initial population, these are updated in a periodic scheduled job,
48 -- with only the last week being updated.
52 hot_rank_active = hot_rank (score::numeric, newest_comment_time_necro);
57 hot_rank = hot_rank (score::numeric, published);
62 hot_rank = hot_rank (score::numeric, published);
67 hot_rank = hot_rank (subscribers::numeric, published);
69 -- Create single column indexes
70 CREATE INDEX idx_post_aggregates_score ON post_aggregates (score DESC);
72 CREATE INDEX idx_post_aggregates_published ON post_aggregates (published DESC);
74 CREATE INDEX idx_post_aggregates_newest_comment_time ON post_aggregates (newest_comment_time DESC);
76 CREATE INDEX idx_post_aggregates_newest_comment_time_necro ON post_aggregates (newest_comment_time_necro DESC);
78 CREATE INDEX idx_post_aggregates_featured_community ON post_aggregates (featured_community DESC);
80 CREATE INDEX idx_post_aggregates_featured_local ON post_aggregates (featured_local DESC);
82 CREATE INDEX idx_post_aggregates_hot ON post_aggregates (hot_rank DESC);
84 CREATE INDEX idx_post_aggregates_active ON post_aggregates (hot_rank_active DESC);
86 CREATE INDEX idx_comment_aggregates_hot ON comment_aggregates (hot_rank DESC);
88 CREATE INDEX idx_community_aggregates_hot ON community_aggregates (hot_rank DESC);