3 ms·
Hmm, it seems like the subquery is getting re-run on every single row of the task queue table, which seems like a performance issue in addition to correctness.
by clhodapp 1y ago
Hmm, it seems like the subquery is getting re-run on every single row of the task queue table, which seems like a performance issue in addition to correctness.
Personally, if I were going to put any part of that query in a CTE, it would have been (just) the select, as I generally prefer CTE's to subqueries.
I'm really not sure what motivated the author to create the CTE in the first place, as the final select seems to be essentially the identity function.
- McGlockenshire 1y ago> it seems like the subquery is getting re-run on every single row of the task queue table Y'all might find the term "correlated subquery" helpful here. When I want them, I always get them. Sometimes I get them when I don't want them. Sometimes it's even my fault, not the result of the query planner looking at me sideways.
- Normal_gaussian 1y ago"I'm really not sure what motivated the author to create the CTE in the first place, as the final select seems to be essentially the identity function." We're likely seeing a simplified example. All queries should be able to be embedded in a CTE without integrity loss.
- zokier 1y agoI think CTE is red herring here, the problem is in the sub-query regardless if it's in CTE or not
- Normal_gaussian 1y agoYes, it is a red herring for sure; using a limit without a sort in a sub-query is always an issue.