Discussion:
Question About Costing
(too old to reply)
Greg Knox
2011-03-31 19:35:30 UTC
Permalink
Hi,

For costing, I currently have this being outputted from print_plan:

SeqScan(1) rows=7 cost=0.00..1.25
pathkeys: ((emp.dno))
SeqScan(1) rows=7 cost=0.00..1.25

cheapest startup path:
SeqScan(1) rows=7 cost=0.00..1.25
pathkeys: ((emp.dno))

cheapest total path:
SeqScan(1) rows=7 cost=0.00..1.25
pathkeys: ((emp.dno))

And this is part of what is returned from my explain command:
-> Sort (cost=1.35..1.37 rows=7 width=14)
Sort Key: dno
-> Seq Scan on emp (cost=0.00..1.25 rows=7 width=14)

For the print_path part, should the cost outputted at that point be the
cost of the seqscan + sort? So, 1.35..2.62? Or should it just be the
cost of the seqscan with the sort cost being separate?

Thanks!
Greg
Earl Oliver
2011-03-31 21:16:53 UTC
Permalink
Hello,
It appears that you are not properly costing your paths. Yes, the cost
of the sort should include the seqscan and the sort.

Earl
Post by Greg Knox
Hi,
SeqScan(1) rows=7 cost=0.00..1.25
pathkeys: ((emp.dno))
SeqScan(1) rows=7 cost=0.00..1.25
SeqScan(1) rows=7 cost=0.00..1.25
pathkeys: ((emp.dno))
SeqScan(1) rows=7 cost=0.00..1.25
pathkeys: ((emp.dno))
-> Sort (cost=1.35..1.37 rows=7 width=14)
Sort Key: dno
-> Seq Scan on emp (cost=0.00..1.25 rows=7 width=14)
For the print_path part, should the cost outputted at that point be the
cost of the seqscan + sort? So, 1.35..2.62? Or should it just be the
cost of the seqscan with the sort cost being separate?
Thanks!
Greg
Ken Salem
2011-04-01 16:09:44 UTC
Permalink
There are two cumulative costs, a startup cost
(estimated cost to produce the first output tuple) and
a total cost (estimated cost to produce all output tuples),
at each point in a Postgres path/plan.

For the sorted sequential scan paths that you are producing,
the startup cost for the plan should be at least as
large as the total cost of the corresponding unsorted
sequential scan path. That's because the sort must consume
all of its input (from the sequential scan) before it can
produce its first output.

-KMS
Post by Earl Oliver
Hello,
It appears that you are not properly costing your paths. Yes, the cost
of the sort should include the seqscan and the sort.
Earl
Post by Greg Knox
Hi,
SeqScan(1) rows=7 cost=0.00..1.25
pathkeys: ((emp.dno))
SeqScan(1) rows=7 cost=0.00..1.25
SeqScan(1) rows=7 cost=0.00..1.25
pathkeys: ((emp.dno))
SeqScan(1) rows=7 cost=0.00..1.25
pathkeys: ((emp.dno))
-> Sort (cost=1.35..1.37 rows=7 width=14)
Sort Key: dno
-> Seq Scan on emp (cost=0.00..1.25 rows=7 width=14)
For the print_path part, should the cost outputted at that point be the
cost of the seqscan + sort? So, 1.35..2.62? Or should it just be the
cost of the seqscan with the sort cost being separate?
Thanks!
Greg
Loading...