Thread: Question about cost-calculation

Question about cost-calculation

From
"A. Kretschmer"
Date:
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

Re: Question about cost-calculation

From
Tom Lane
Date:
"A. Kretschmer" <andreas.kretschmer@schollglas.com> writes:
> i expected for a 1000 row test-table a cost per function of 2.5
> (cpu_operator_cost = 0.0025), but i got 5.

What's the data type of "i"?  I suspect you really have two function
calls in that expression: a type coercion function and cos() itself.

            regards, tom lane

Re: Question about cost-calculation

From
"A. Kretschmer"
Date:
am  Mon, dem 02.06.2008, um  9:57:17 -0400 mailte Tom Lane folgendes:
> "A. Kretschmer" <andreas.kretschmer@schollglas.com> writes:
> > i expected for a 1000 row test-table a cost per function of 2.5
> > (cpu_operator_cost = 0.0025), but i got 5.
>
> What's the data type of "i"?  I suspect you really have two function
> calls in that expression: a type coercion function and cos() itself.

Tom, many thanks for the enlightenment, you are right. Data typ of "i"
was int, if i use real than i got the expected costs. Great ;-)


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