> Last question... What's the purpose of such a big sort? If somebody gets
> 40M of sorted records in a result of some query, what would he do with
> it? Is he going to spent next years on reading this lecture? I mean,
> isn't it worth to query the database for necessary informations only and
> then sort it?
Not all query results are for human eyes. I'd venture to say that more
queries are fed into report generators for formatting than are looked at
directly from psql.
A sort is required in some cases where not explicitly requested.
For example, a GROUP BY clause. You _could_ get the data back ungrouped,
but then you'd have to pipe it to another application or script to do the
sorting and then the grouping (or perhaps group on the fly). But then
perhaps that app/script will eat all the memory or disk space and you'd
be in the same pickle as before.
darrenk