3 ms·
Careful with DISTINCT ON, it can be extremely slow, like 100x slower than a verbose and less readable alternative. But it might not matter in your use case.
by freeest-will 5y ago
Careful with DISTINCT ON, it can be extremely slow, like 100x slower than a verbose and less readable alternative. But it might not matter in your use case.
- CabSauce 5y agoI don't belive this is correct for postgres. It's true for other RDBMS, I believe. <https://medium.com/@smitagudale712/distinct-vs-group-by-in-sql-server-b62527285f9c https://medium.com/@smitagudale712/distinct-vs-group-by-in-s...>
- freeest-will 5y agoI encountered this problem in Postgres 13. https://blog.timescale.com/blog/how-we-made-distinct-queries-up-to-8000x-faster-on-postgresql/ https://blog.timescale.com/blog/how-we-made-distinct-queries...
- 1500100900 5y agoA hand-written loose index scan sometimes helps in a case like this. I think it's not built-in yet.