pgsql: Cache the result of makesign() across calls of gtrgm_penalty().

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Cache the result of makesign() across calls of gtrgm_penalty().
Date: 2011-10-01 03:55:10
Message-ID: E1R9qfO-0001A6-UP@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Cache the result of makesign() across calls of gtrgm_penalty().

Since gtrgm_penalty() is usually called many times in a row with the same
"newval" (to determine which item on an index page newval fits into best),
the makesign() calculation is repetitious. It's expensive enough to make
it worth caching the result, so do so. On my machine this is good for
more than a 40% savings in the time needed to build a trigram index on
/usr/share/dict/words. This is all per a suggestion of Heikki's.

In passing, make some mostly-cosmetic improvements in the caching logic in
the other functions in this file that rely on caching info in fn_extra.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/0a5d5a49d9965aa092e75ce31a88fbf5f05c5009

Modified Files
--------------
contrib/pg_trgm/trgm_gist.c | 134 +++++++++++++++++++++++++++++--------------
1 files changed, 90 insertions(+), 44 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Bruce Momjian 2011-10-01 14:02:56 pgsql: In pg_upgrade, remove unnecessary local variable.
Previous Message Tom Lane 2011-09-30 23:49:11 pgsql: Support GiST index support functions that want to cache data acr