Skip site navigation (1) Skip section navigation (2)

Re: Various performance questions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: Neil Conway <neilc(at)samurai(dot)com>, Dror Matalon <dror(at)zapatec(dot)com>,PostgreSQL Performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Various performance questions
Date: 2003-10-27 19:26:07
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
Greg Stark <gsstark(at)mit(dot)edu> writes:
> I'm still puzzled why the times on these are so different when the latter
> returns fewer records and both are doing sequential scans:

My best guess is that it's simply the per-tuple overhead of cycling
tuples through the two plan nodes.  When you have no actual I/O happening,
the seqscan runtime is going to be all CPU time, something of the form
	cost_per_page * number_of_pages_processed +
	cost_per_tuple_scanned * number_of_tuples_scanned +
	cost_per_tuple_returned * number_of_tuples_returned
I don't have numbers for the relative sizes of those three costs, but
I doubt that any of them are negligible compared to the other two.

Adding a WHERE clause increases cost_per_tuple_scanned but reduces the
number_of_tuples_returned, and so it cuts the contribution from the
third term, evidently by more than the WHERE clause adds to the second

Ny own profiling had suggested that the cost-per-tuple-scanned in the
aggregate node dominated the seqscan CPU costs, but that might be
platform-specific, or possibly have something to do with the fact that
I was profiling an assert-enabled build.

It might be worth pointing out that EXPLAIN ANALYZE adds two kernel
calls (gettimeofday or some such) into each cycle of the plan nodes;
that's probably inflating the cost_per_tuple_returned by a noticeable

			regards, tom lane

In response to

pgsql-performance by date

Next:From: Tom LaneDate: 2003-10-27 20:12:08
Subject: Re: Very Poor Insert Performance
Previous:From: Greg StarkDate: 2003-10-27 19:23:01
Subject: Re: Various performance questions

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group