Skip to content

Instantly share code, notes, and snippets.

@MaxBittker
Created November 21, 2024 20:19
Show Gist options
  • Select an option

  • Save MaxBittker/c7c181cfa0bb7039b5a408326bd3dcef to your computer and use it in GitHub Desktop.

Select an option

Save MaxBittker/c7c181cfa0bb7039b5a408326bd3dcef to your computer and use it in GitHub Desktop.
slow query
WITH
subset AS(
SELECT
*
FROM
creations AS c,
plainto_tsquery($1) AS q
WHERE
(tsv @@ q)
AND NOT EXISTS(
SELECT
FROM
rulings AS r
WHERE
r.id = c.id
AND r.bad = ? )
ORDER BY
score DESC,
timestamp DESC
LIMIT
? )
SELECT
cs.ID,
MAX(cs.data_id) AS data_id,
MAX(cs.title) AS title,
MAX(cs.timestamp) AS timestamp,
MAX(cs.score) AS score,
MAX(cs.children) AS children,
MAX(cs.parent_id) AS parent_id,
COUNT(RP.id) AS reportcount
FROM
SUBSET cs
LEFT JOIN
reports AS RP
ON
RP.id = cs.ID
GROUP BY
cs.id
ORDER BY
timestamp DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment