Question about cost-calculation - Mailing list pgsql-general

From A. Kretschmer
Subject Question about cost-calculation
Date
Msg-id 20080602100529.GD25294@a-kretschmer.de
Whole thread Raw
Responses Re: Question about cost-calculation  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi,

according the doc
(http://www.postgresql.org/docs/8.3/interactive/runtime-config-query.html#GUC-CPU-OPERATOR-COST),

Quote:
Sets the planner's estimate of the cost of processing each operator or function executed during a query.


i expected for a 1000 row test-table a cost per function of 2.5
(cpu_operator_cost = 0.0025), but i got 5.



First, a full table scan:

test=*# explain analyse select i from s_test;
                                              QUERY PLAN
-------------------------------------------------------------------------------------------------------
 Seq Scan on s_test  (cost=0.00..15.00 rows=1000 width=4) (actual time=0.013..2.315 rows=1000 loops=1)
 Total runtime: 4.232 ms
(2 rows)


cost=15.

Now, the same query but with one or two functions on a particular column:


test=*# explain analyse select i, cos(i) from s_test;
                                              QUERY PLAN
-------------------------------------------------------------------------------------------------------
 Seq Scan on s_test  (cost=0.00..20.00 rows=1000 width=4) (actual time=0.026..3.043 rows=1000 loops=1)
 Total runtime: 5.017 ms
(2 rows)

test=*# explain analyse select i, cos(i), md5(i) from s_test;
                                              QUERY PLAN
-------------------------------------------------------------------------------------------------------
 Seq Scan on s_test  (cost=0.00..25.00 rows=1000 width=4) (actual time=0.040..5.414 rows=1000 loops=1)
 Total runtime: 7.444 ms
(2 rows)

cost increased by 5 per function-call, why, why not 2.5?


Version: 8.1


Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

pgsql-general by date:

Previous
From: "Andrej Ricnik-Bay"
Date:
Subject: Re: Bottom Posting
Next
From: "Brian A. Seklecki"
Date:
Subject: Re: [Xen-users] SNMP AgentX subagent for Xen