Shawn, > I can also change the schema to a certain extent, so would it be worthwhile > to put indices on the queried tables (or refactor them) hoping the distinct > does an index scan instead of sort... would the query planner take > advantage of that?
Use the GROUP BY, with an index on the grouped columns and lots of work_mem (sort_mem in 7.4). This will give the planner the option of a hashaggregate which could be significantly faster than the other methods. -- Josh Berkus Aglio Database Solutions San Francisco ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster