pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Steve Crawford <scrawford@pinpointresearch.com>
Cc: pgsql-performance@postgreSQL.org
Cc: pgsql-hackers@postgreSQL.org
Subject: Re: Terrible performance on wide selects
Date: Wed, 22 Jan 2003 18:14:30 -0500
Message-ID: <25182.1043277270@sss.pgh.pa.us> (raw)
In-Reply-To: <20030122224814.ECF47103E6@polaris.pinpointresearch.com>
References: <20030117193726.1CFCB103E5@polaris.pinpointresearch.com>
	<20030122212901.EDF00103E6@polaris.pinpointresearch.com>
	<24808.1043274411@sss.pgh.pa.us>
	<20030122224814.ECF47103E6@polaris.pinpointresearch.com>

Steve Crawford sent me some profiling results for queries involving wide
tuples (hundreds of columns).

> Done, results attached. nocachegetattr seems to be the likely suspect.

Yipes, you can say that again.

  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 93.38     26.81    26.81   885688     0.03     0.03  nocachegetattr

                0.00    0.00       1/885688      heapgettup [159]
                0.00    0.00       1/885688      CatalogCacheComputeTupleHashValue [248]
                0.00    0.00       5/885688      SearchCatCache [22]
               13.40    0.00  442840/885688      ExecEvalVar [20]
               13.40    0.00  442841/885688      printtup [12]
[11]    93.4   26.81    0.00  885688         nocachegetattr [11]


Half of the calls are coming from printtup(), which seems relatively easy
to fix.

	/*
	 * send the attributes of this tuple
	 */
	for (i = 0; i < natts; ++i)
	{
		...
		origattr = heap_getattr(tuple, i + 1, typeinfo, &isnull);
		...
	}

The trouble here is that in the presence of variable-width fields,
heap_getattr requires a linear scan over the tuple --- and so the total
time spent in it is O(N^2) in the number of fields.

What we could do is reinstitute heap_deformtuple() as the inverse of
heap_formtuple() --- but make it extract Datums for all the columns in
a single pass over the tuple.  This would reduce the time in printtup()
from O(N^2) to O(N), which would pretty much wipe out that part of the
problem.

The other half of the calls are coming from ExecEvalVar, which is a
harder problem to solve, since those calls are scattered all over the
place.  It's harder to see how to get them to share work.  Any ideas
out there?

			regards, tom lane



view thread (22+ messages)  latest in thread

Message-ID: <25182.1043277270@sss.pgh.pa.us>
Permalink:  ../25182.1043277270@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/25182.1043277270@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, scrawford@pinpointresearch.com, pgsql-hackers@postgreSQL.org
  Subject: Re: Terrible performance on wide selects
  In-Reply-To: <25182.1043277270@sss.pgh.pa.us>
  References: <20030117193726.1CFCB103E5@polaris.pinpointresearch.com> <20030122212901.EDF00103E6@polaris.pinpointresearch.com> <24808.1043274411@sss.pgh.pa.us> <20030122224814.ECF47103E6@polaris.pinpointresearch.com> <25182.1043277270@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox