Improve contrib/pg_stat_statements' handling of garbage collection failure.
Improve contrib/pg_stat_statements' handling of garbage collection failure.

If we can't read the query texts file (whether because out-of-memory, or
for some other reason), give up and reset the file to empty, discarding all
stored query texts, though not the statistics per se.  We used to leave
things alone and hope for better luck next time, but the problem is that
the file is only going to get bigger and even harder to slurp into memory.
Better to do something that will get us out of trouble.

Likewise reset the file to empty for any other failure within gc_qtexts().
The previous behavior after a write error was to discard query texts but
not do anything to truncate the file, which is just weird.

Also, increase the maximum supported file size from MaxAllocSize to
MaxAllocHugeSize; this makes it more likely we'll be able to do a garbage
collection successfully.

Also, fix recalculation of mean_query_len within entry_dealloc() to match
the calculation in gc_qtexts().  The previous coding overlooked the
possibility of dropped texts (query_len == -1) and would underestimate the
mean of the remaining entries in such cases, thus possibly causing excess
garbage collection cycles.

In passing, add some errdetail to the log entry that complains about
insufficient memory to read the query texts file, which after all was
Jim Nasby's original complaint.

Back-patch to 9.4 where the current handling of query texts was
introduced.

Peter Geoghegan, rather editorialized upon by me

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