Created
November 21, 2024 20:19
-
-
Save MaxBittker/c7c181cfa0bb7039b5a408326bd3dcef to your computer and use it in GitHub Desktop.
slow query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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