Tweak ExecIndexEvalRuntimeKeys to forcibly detoast any toasted comparison
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 23 Aug 2009 18:26:08 +0000 (18:26 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 23 Aug 2009 18:26:08 +0000 (18:26 +0000)
commitd44de130b908e0568213fcfb9ccd8cdd35d82e48
treee220e63332bd12f91396f6a05669aaf8092b840b
parent58729462931e6e8ffb2c982c1797d7d423f377af
Tweak ExecIndexEvalRuntimeKeys to forcibly detoast any toasted comparison
values before they get passed to the index access method.  This avoids
repeated detoastings that will otherwise ensue as the comparison value
is examined by various index support functions.  We have seen a couple of
reports of cases where repeated detoastings result in an order-of-magnitude
slowdown, so it seems worth adding a bit of extra logic to prevent this.

I had previously proposed trying to avoid duplicate detoastings in general,
but this fix takes care of what seems the most important case in practice
with very little effort or risk.

Back-patch to 8.4 so that the PostGIS folk won't have to wait a year to
have this fix in a production release.  (The issue exists further back,
of course, but the code's diverged enough to make backpatching further a
higher-risk action.  Also it appears that the possible gains may be limited
in prior releases because of different handling of lossy operators.)
src/backend/executor/nodeIndexscan.c
src/include/nodes/execnodes.h