]> granicus.if.org Git - postgresql/commit
Prevent query-lifespan memory leakage of SP-GiST traversal values.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 20 Mar 2018 03:59:17 +0000 (23:59 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 20 Mar 2018 03:59:17 +0000 (23:59 -0400)
commitd18a88acf2d1591f9332bdb1da918037c90d3aa0
treefef7750c5328a361854b45de3fea72eda06b7a2d
parente17e9055f5644f1b39ecd1bf64ec03d3430dfb46
Prevent query-lifespan memory leakage of SP-GiST traversal values.

The original coding of the SP-GiST scan traversalValue feature (commit
ccd6eb49a) arranged for traversal values to be stored in the query's main
executor context.  That's fine if there's only one index scan per query,
but if there are many, we have a memory leak as successive scans create
new traversal values.  Fix it by creating a separate memory context for
traversal values, which we can reset during spgrescan().  Back-patch
to 9.6 where this code was introduced.

In principle, adding the traversalCxt field to SpGistScanOpaqueData
creates an ABI break in the back branches.  But I (tgl) have little
sympathy for extensions including spgist_private.h, so I'm not very
worried about that.  Alternatively we could stick the new field at the
end of the struct in back branches, but that has its own downsides.

Anton Dignös, reviewed by Alexander Kuzmenkov

Discussion: https://postgr.es/m/CALNdv1jb6y2Te-m8xHLxLX12RsBmZJ1f4hESX7J0HjgyOhA9eA@mail.gmail.com
src/backend/access/spgist/spgscan.c
src/include/access/spgist_private.h