sql - fetch_catalog needs ORDER BY bump time after all those operations

This commit is contained in:
towards-a-new-leftypol 2023-11-01 20:23:47 -04:00
parent e83df86725
commit 8a10ce4798
3 changed files with 20 additions and 4 deletions

View File

@ -588,7 +588,13 @@ grouped AS (
$$; $$;
SELECT * FROM posts WHERE body_search_index @@ websearch_to_tsquery('english', 'TRUE CHRISTIAN'); SELECT * FROM posts WHERE body_search_index @@ websearch_to_tsquery('english', 'holocaust');
SELECT *,
ts_rank(body_search_index, websearch_to_tsquery('english', 'holocaust')) AS relevance
FROM posts
WHERE body_search_index @@ websearch_to_tsquery('english', 'holocaust')
ORDER BY relevance DESC;
SELECT to_tsvector('english', body) FROM posts WHERE board_post_id = 476524; SELECT to_tsvector('english', body) FROM posts WHERE board_post_id = 476524;
SELECT (setweight(to_tsvector('english', COALESCE(subject, '')), 'A') || SELECT (setweight(to_tsvector('english', COALESCE(subject, '')), 'A') ||
setweight(to_tsvector('english', COALESCE(name, '')), 'B') || setweight(to_tsvector('english', COALESCE(name, '')), 'B') ||

View File

@ -140,7 +140,9 @@ RETURNS TABLE (
post_id bigint, post_id bigint,
board_post_id bigint, board_post_id bigint,
creation_time timestamptz, creation_time timestamptz,
bump_time timestamptz,
body text, body text,
subject text,
thread_id bigint, thread_id bigint,
board_thread_id bigint, board_thread_id bigint,
pathpart text, pathpart text,
@ -158,7 +160,9 @@ RETURNS TABLE (
posts.post_id, posts.post_id,
posts.board_post_id, posts.board_post_id,
posts.creation_time, posts.creation_time,
top.bump_time,
posts.body, posts.body,
posts.subject,
posts.thread_id posts.thread_id
FROM top FROM top
JOIN posts ON top.thread_id = posts.thread_id JOIN posts ON top.thread_id = posts.thread_id
@ -187,12 +191,15 @@ RETURNS TABLE (
JOIN post_counts ON op_posts.thread_id = post_counts.thread_id JOIN post_counts ON op_posts.thread_id = post_counts.thread_id
JOIN threads ON op_posts.thread_id = threads.thread_id JOIN threads ON op_posts.thread_id = threads.thread_id
JOIN boards ON threads.board_id = boards.board_id JOIN boards ON threads.board_id = boards.board_id
JOIN sites ON sites.site_id = boards.site_id; JOIN sites ON sites.site_id = boards.site_id
ORDER BY bump_time DESC;
$$ LANGUAGE sql; $$ LANGUAGE sql;
SELECT * FROM fetch_catalog(NOW() - INTERVAL '1y', 1001); SELECT * FROM fetch_catalog(NOW() - INTERVAL '1y', 1001);
SELECT * FROM fetch_catalog(NOW(), 2000); SELECT * FROM fetch_catalog(NOW(), 1000);
SELECT count(*) FROM posts;
-- CREATE INDEX idx_posts_thread_board ON posts (thread_id, board_post_id); -- CREATE INDEX idx_posts_thread_board ON posts (thread_id, board_post_id);
ANALYZE posts; ANALYZE posts;

View File

@ -211,6 +211,7 @@ RETURNS TABLE (
post_id bigint, post_id bigint,
board_post_id bigint, board_post_id bigint,
creation_time timestamptz, creation_time timestamptz,
bump_time timestamptz,
body text, body text,
subject text, subject text,
thread_id bigint, thread_id bigint,
@ -230,6 +231,7 @@ RETURNS TABLE (
posts.post_id, posts.post_id,
posts.board_post_id, posts.board_post_id,
posts.creation_time, posts.creation_time,
top.bump_time,
posts.body, posts.body,
posts.subject, posts.subject,
posts.thread_id posts.thread_id
@ -260,7 +262,8 @@ RETURNS TABLE (
JOIN post_counts ON op_posts.thread_id = post_counts.thread_id JOIN post_counts ON op_posts.thread_id = post_counts.thread_id
JOIN threads ON op_posts.thread_id = threads.thread_id JOIN threads ON op_posts.thread_id = threads.thread_id
JOIN boards ON threads.board_id = boards.board_id JOIN boards ON threads.board_id = boards.board_id
JOIN sites ON sites.site_id = boards.site_id; JOIN sites ON sites.site_id = boards.site_id
ORDER BY bump_time DESC;
$$ LANGUAGE sql; $$ LANGUAGE sql;