Re:Distinct on: a confusing, unique and useful feature in Po...
by zeroimpl on Friday March 20, 2020 @09:52PM
(#22643560)
In general if you query a table twice, the query planner will visit that table twice. So DISTINCT ON is almost always more efficient.
The main exception I’ve seen is when using it in a view, if you try to filter the results of the view, it usually can’t optimize a DISTINCT ON, but sometimes can for GROUP BY (though that might have improved on newer versions)
The main exception I’ve seen is when using it in a view, if you try to filter the results of the view, it usually can’t optimize a DISTINCT ON, but sometimes can for GROUP BY (though that might have improved on newer versions)