Reduce memory usage of tsvector type analyze function.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 12 Jul 2017 19:03:38 +0000 (22:03 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 12 Jul 2017 19:03:58 +0000 (22:03 +0300)
commit209970ded835ffe2f354220da77f3df9a7a7dab4
treeee3eb53c0778d79bbe69ce8ac331de3580199eea
parente7213fe2bda8a90b3570e9a41a25a620913b649a
Reduce memory usage of tsvector type analyze function.

compute_tsvector_stats() detoasted and kept in memory every tsvector value
in the sample, but that can be a lot of memory. The original bug report
described a case using over 10 gigabytes, with statistics target of 10000
(the maximum).

To fix, allocate a separate copy of just the lexemes that we keep around,
and free the detoasted tsvector values as we go. This adds some palloc/pfree
overhead, when you have a lot of distinct lexemes in the sample, but it's
better than running out of memory.

Fixes bug #14654 reported by James C. Reviewed by Tom Lane. Backport to
all supported versions.

Discussion: https://www.postgresql.org/message-id/20170514200602.1451.46797@wrigleys.postgresql.org
src/backend/tsearch/ts_typanalyze.c