Second try at fixing O(N^2) problem in foreign key references.
Second try at fixing O(N^2) problem in foreign key references.

This replaces ill-fated commit 5ddc72887a012f6a8b85707ef27d85c274faf53d,
which was reverted because it broke active uses of FK cache entries.  In
this patch, we still do nothing more to invalidatable cache entries than
mark them as needing revalidation, so we won't break active uses.  To keep
down the overhead of InvalidateConstraintCacheCallBack(), keep a list of
just the currently-valid cache entries.  (The entries are large enough that
some added space for list links doesn't seem like a big problem.)  This
would still be O(N^2) when there are many valid entries, though, so when
the list gets too long, just force the "sinval reset" behavior to remove
everything from the list.  I set the threshold at 1000 entries, somewhat
arbitrarily.  Possibly that could be fine-tuned later.  Another item for
future study is whether it's worth adding reference counting so that we
could safely remove invalidated entries.  As-is, problem cases are likely
to end up with large and mostly invalid FK caches.

Like the previous attempt, backpatch to 9.3.

Jan Wieck and Tom Lane

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