Q about heap_getattr

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: Q about heap_getattr
Date: 1999-01-24 17:53:58
Message-ID: 7593.917200438@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I've been doing some more backend profiling, and observe that in a large
SELECT from a table with lots of columns, nocachegetattr (the guts of
heap_getattr) is at the top of the list, accounting for about 15% of
runtime.

The percentage would be lower in a table with fewer columns or no null
columns, but it still seems worth working on. (Besides, this case right
here is a real-world case for me.)

What's drawing my eye is that printtup() is calling heap_getattr twice
for each attribute of each tuple --- once in the first scan that
prepares the null-fields bitmap, and then again to actually output the
field value. So, what I want to do is call heap_getattr only once per
attribute and save the returned value for use in the second loop.
That should halve the time spent in nocachegetattr and thus knock
7 or so percent off the runtime of SELECT.

The question for the list: how long is the Datum value returned by
heap_getattr valid? In particular, could it be invalidated by calling
heap_getattr for another field of the same tuple? If there are any
cases like that, then this optimization won't work. I don't know the
backend well enough to guess whether this is safe.

regards, tom lane

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Vadim Mikheev 1999-01-24 18:09:13 Re: [HACKERS] Q about heap_getattr
Previous Message D'Arcy J.M. Cain 1999-01-24 14:22:18 Re: [HACKERS] Adding some const keywords to external interfaces