Fix an O(N^2) problem in foreign key references.
Fix an O(N^2) problem in foreign key references.

Commit 45ba424f improved foreign key lookups during bulk updates
when the FK value does not change.  When restoring a schema dump
from a database with many (say 100,000) foreign keys, this cache
would grow very big and every ALTER TABLE command was causing an
InvalidateConstraintCacheCallBack(), which uses a sequential hash
table scan.  This could cause a severe performance regression in
restoring a schema dump (including during pg_upgrade).

The patch uses a heuristic method of detecting when the hash table
should be destroyed and recreated.
InvalidateConstraintCacheCallBack() adds the current size of the
hash table to a counter.  When that sum reaches 1,000,000, the hash
table is flushed.  This fixes the regression without noticeable
harm to the bulk update use case.

Jan Wieck
Backpatch to 9.3 where the performance regression was introduced.

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