3 ms·
My reading of the cost statements is that the sort doesn't matter at all: the sequential scan is what took up virtually all of the time. But I'm hardly a PG ex
by davidw 12y ago
My reading of the cost statements is that the sort doesn't matter at all: the sequential scan is what took up virtually all of the time.
But I'm hardly a PG expert.
Excellent article in any event, it's really interesting to see how things work under the hood.
- Animats 12y agoDepends on the contents of the database. The query optimizer doesn't know, at optimization time, how many hits such a statement will produce. Given a database with only a few entries with the same name, the sort cost is tiny. If there are a lot of hits, it's expensive.
- yangyang 12y agoIt can estimate though, using per-column statistics. ANALYZE (and the autoanalyze background process) update these in PostgreSQL. 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 http://www.postgresql.org/docs/9.3/static/planner-stats.html
- yangyang 12y agoIndeed: it's estimating that a single row will be returned from the seq scan. That will clearly take no time to sort!