Looking forward to the next installment. That query is so simple that you're not seeing what a real database can do. Let's see something with a JOIN and lots of indices, so the optimizer can do some work.
Looking forward to the next installment. That query is so simple that you're not seeing what a real database can do. Let's see something with a JOIN and lots of indices, so the optimizer can do some work.
Postgres will not necessarily do a full external merge sort for the query plan shown in the article: when there is a LIMIT k clause, the Postgres sorting code has optimizations to only keep the top k values in memory and do an in-memory sort (obviously, a full seqscan of the input is still needed without an index). Search for TSS_BOUNDED and tuplesort_set_bound() here:
https://github.com/postgres/postgres/blob/master/src/backend...
Plus I wasn't interested in comparing one DB vs. another, as much as I was interested in understanding how any DB works.
But I'm hardly a PG expert.
Excellent article in any event, it's really interesting to see how things work under the hood.
These stats are a huge part of cost-based query optimisation, which all major DBMSs do these days.
Details here: http://www.postgresql.org/docs/9.3/static/planner-stats.html