Another try at reducing repeated detoast work for PostGIS

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: Another try at reducing repeated detoast work for PostGIS
Date: 2009-08-17 17:37:20
Message-ID: 4201.1250530640@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

There was recently another go-round on the postgis-devel list about
the same problem Mark Cave-Ayland complained about last year:
http://archives.postgresql.org/pgsql-hackers/2008-06/msg00384.php
Basically, what is happening is a nestloop join where the inner
indexscan gets a comparison argument from the outer table, and that
argument is toasted. Every single call of an index support function
detoasts the argument again :-(, leading to upwards of 90% of the
runtime being spent in detoasting.

I made a proposal to fix it
http://archives.postgresql.org/pgsql-hackers/2008-06/msg00709.php
but that failed due to excessive ambition --- the cost/benefit/risk
tradeoffs just weren't good enough.

Thinking about it again, it seems to me that a much narrower patch
could solve the specific forms of the problem that the PostGIS folk
are seeing. Instead of trying to have a general-purpose method of
preventing repeat de-toasting, we could just prevent it for inner
indexscans by having ExecIndexEvalRuntimeKeys() detoast anything it's
passing to the index AM. The attached patch accomplishes this with
a net addition of about three statements. (It looks bigger, because
I had to move a hunk of code to have the datatype info available when
needed.) Paul Ramsey reports that this fixes the problem for him:
http://postgis.refractions.net/pipermail/postgis-devel/2009-August/006659.html

The only downside I can see offhand is that it will detoast short-header
values that might not actually need to be detoasted. But we don't have
any very good way to know whether a datatype's index support functions
use PG_DETOAST_DATUM or PG_DETOAST_DATUM_PACKED. In the former case we
do need to detoast short-header values. The extra overhead in this case
amounts to only one palloc and a fairly short memcpy, which should be
pretty negligible in comparison to the other setup costs of an
indexscan, so I'm not very concerned about it.

Comments? Better ideas?

regards, tom lane

Attachment Content-Type Size
unknown_filename text/plain 5.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2009-08-17 17:39:38 Re: Alpha 1 release notes
Previous Message Robert Haas 2009-08-17 16:28:15 Re: CommitFest 2009-07: Remaining Patches Moved To CommitFest 2009-09