Re: Understanding EXPLAIN

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Understanding EXPLAIN
Date: 2012-02-03 08:22:47
Message-ID: 20120203082247.GA12820@tux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Robert Lichtenberger <r(dot)lichtenberger(at)synedra(dot)com> wrote:

> I am trying to fully understand, how costs for queries are computed.
> Taking the following example:
>
> CREATE TABLE test (name varchar(250) primary key) ;
> INSERT INTO test (name) VALUES(generate_series(1, 1000)::text) ;
> ANALYZE test ;
> EXPLAIN SELECT * FROM test WHERE name = '4' ;
>
> I am getting the output:
> Index Scan using test_pkey on test (cost=0.00..8.27 rows=1 width=3)
> Index Cond: ((name)::text = '4'::text)
>
> The server has default cost parameters
>
> The value I want to understand is 8.27. From reading the book
> "PostgreSQL 9.0 High Performance" I know, that we have one index page
> read (random page read, cost=4.0) and one database row read (random page
> read, cost=4.0) which comes up to a total of 8.0. But where are the
> missing 0.27 from?
>
> If I modify the example to insert 10,000 rows, the cost stays the same.
> Only if I go for 100,000 rows will the computed cost increase to 8.29.
>
> Can anybody enlighten me, please ;-).

There are some other costs, in your case cpu_tuple_cost and
cpu_index_tuple_cost.

Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

In response to

Browse pgsql-general by date

  From Date Subject
Next Message garry 2012-02-03 08:26:23 last entry per person
Previous Message Tom Lane 2012-02-03 08:20:50 Re: Understanding EXPLAIN