Cache the result of makesign() across calls of gtrgm_penalty().
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 1 Oct 2011 03:54:27 +0000 (23:54 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 1 Oct 2011 03:54:27 +0000 (23:54 -0400)
commit0a5d5a49d9965aa092e75ce31a88fbf5f05c5009
treee91e87c7cd89d0506c75fd5a6af9b3e3e5f1ba60
parentd22a09dc70f9830fa78c1cd1a3a453e4e473d354
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.
contrib/pg_trgm/trgm_gist.c