]> granicus.if.org Git - postgresql/commit
Repair memory leakage while ANALYZE-ing complex index expressions.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 9 Nov 2010 16:28:18 +0000 (11:28 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 9 Nov 2010 16:56:51 +0000 (11:56 -0500)
commit55425d37214328bd3b45de99290dd8aa885c1a60
tree7605ff9031bdc8994a40848268dff701fd7e00dd
parent6d2697ab1fe066ebf634c6a998d2b03fff210249
Repair memory leakage while ANALYZE-ing complex index expressions.

The general design of memory management in Postgres is that intermediate
results computed by an expression are not freed until the end of the tuple
cycle.  For expression indexes, ANALYZE has to re-evaluate each expression
for each of its sample rows, and it wasn't bothering to free intermediate
results until the end of processing of that index.  This could lead to very
substantial leakage if the intermediate results were large, as in a recent
example from Jakub Ouhrabka.  Fix by doing ResetExprContext for each sample
row.  This necessitates adding a datumCopy step to ensure that the final
expression value isn't recycled too.  Some quick testing suggests that this
change adds at worst about 10% to the time needed to analyze a table with
an expression index; which is annoying, but seems a tolerable price to pay
to avoid unexpected out-of-memory problems.

Back-patch to all supported branches.
src/backend/commands/analyze.c