Reduce memory usage of tsvector type analyze function.
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: bb98953c5ae6d6977fb15fe0674478d0533342ad@wrigleys.postgresql.org

adam8157/gpdb,50wu/gpdb,50wu/gpdb,ashwinstar/gpdb,adam8157/gpdb,ashwinstar/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,50wu/gpdb,greenplum-db/gpdb,greenplum-db/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,lisakowen/gpdb,lisakowen/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,jmcatamney/gpdb,jmcatamney/gpdb,50wu/gpdb,lisakowen/gpdb,adam8157/gpdb,ashwinstar/gpdb,xinzweb/gpdb,xinzweb/gpdb,ashwinstar/gpdb,ashwinstar/gpdb,adam8157/gpdb,50wu/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,lisakowen/gpdb,adam8157/gpdb,jmcatamney/gpdb,xinzweb/gpdb,xinzweb/gpdb,adam8157/gpdb,adam8157/gpdb,lisakowen/gpdb,xinzweb/gpdb,adam8157/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,50wu/gpdb,lisakowen/gpdb,50wu/gpdb,xinzweb/gpdb,jmcatamney/gpdb,jmcatamney/gpdb,xinzweb/gpdb,lisakowen/gpdb,lisakowen/gpdb,50wu/gpdb,greenplum-db/gpdb,xinzweb/gpdb