4 ms·
Query optimizers are already black boxes of magic I guess one has to stop somewhere. A top level distinct to a query like this is a huge red flag. Even in a su
by gigatexal 3y ago
Query optimizers are already black boxes of magic I guess one has to stop somewhere.
A top level distinct to a query like this is a huge red flag. Even in a sub select or a join clause id rather have a group by than a distinct.
- Sesse__ 3y agoThere's no good reason why you couldn't rewrite DISTINCT to GROUP BY, but remember that it wouldn't work in all cases; you could have both. E.g. SELECT DISTINCT COUNT(*) FROM t1 GROUP BY a;. Similarly, HAVING and window functions happen after GROUP BY but before DISTINCT, so a simple move won't always be correct and you'd have to account for that.
- _a_a_a_ 3y ago> There's no good reason why you couldn't rewrite DISTINCT to GROUP BY Exactly. People post a lot of things about SQL optimisation without knowing anything about it. Frankly, I'm getting really fed up with it on HN.