Fix O(N^2) behavior in pg_dump when many objects are in dependency loops.
Fix O(N^2) behavior in pg_dump when many objects are in dependency loops.

Combining the loop workspace with the record of already-processed objects
might have been a cute trick, but it behaves horridly if there are many
dependency loops to repair: the time spent in the first step of findLoop()
grows as O(N^2).  Instead use a separate flag array indexed by dump ID,
which we can check in constant time.  The length of the workspace array
is now never more than the actual length of a dependency chain, which
should be reasonably short in all cases of practical interest.  The code
is noticeably easier to understand this way, too.

Per gripe from Mike Roest.  Since this is a longstanding performance bug,
backpatch to all supported versions.

ahachete/gpdb,0x0FFF/gpdb,adam8157/gpdb,xuegang/gpdb,janebeckman/gpdb,chrishajas/gpdb,Quikling/gpdb,xinzweb/gpdb,lintzc/gpdb,Chibin/gpdb,50wu/gpdb,cjcjameson/gpdb,cjcjameson/gpdb,0x0FFF/gpdb,rvs/gpdb,0x0FFF/gpdb,CraigHarris/gpdb,50wu/gpdb,janebeckman/gpdb,lisakowen/gpdb,CraigHarris/gpdb,yuanzhao/gpdb,kaknikhil/gpdb,janebeckman/gpdb,rvs/gpdb,Chibin/gpdb,chrishajas/gpdb,kaknikhil/gpdb,janebeckman/gpdb,yuanzhao/gpdb,lintzc/gpdb,0x0FFF/gpdb,lisakowen/gpdb,adam8157/gpdb,50wu/gpdb,royc1/gpdb,xuegang/gpdb,kaknikhil/gpdb,CraigHarris/gpdb,Quikling/gpdb,lintzc/gpdb,Chibin/gpdb,jmcatamney/gpdb,xuegang/gpdb,kaknikhil/gpdb,chrishajas/gpdb,edespino/gpdb,ashwinstar/gpdb,xuegang/gpdb,yuanzhao/gpdb,janebeckman/gpdb,xinzweb/gpdb,lintzc/gpdb,lintzc/gpdb,xinzweb/gpdb,cjcjameson/gpdb,yuanzhao/gpdb,xuegang/gpdb,zaksoup/gpdb,0x0FFF/gpdb,ashwinstar/gpdb,ahachete/gpdb,greenplum-db/gpdb,edespino/gpdb,CraigHarris/gpdb,xinzweb/gpdb,ahachete/gpdb,janebeckman/gpdb,cjcjameson/gpdb,adam8157/gpdb,0x0FFF/gpdb,Chibin/gpdb,royc1/gpdb,adam8157/gpdb,lisakowen/gpdb,Quikling/gpdb,jmcatamney/gpdb,CraigHarris/gpdb,chrishajas/gpdb,royc1/gpdb,adam8157/gpdb,royc1/gpdb,janebeckman/gpdb,CraigHarris/gpdb,rvs/gpdb,cjcjameson/gpdb,kaknikhil/gpdb,Quikling/gpdb,edespino/gpdb,lisakowen/gpdb,greenplum-db/gpdb,yuanzhao/gpdb,ahachete/gpdb,50wu/gpdb,0x0FFF/gpdb,rvs/gpdb,ahachete/gpdb,jmcatamney/gpdb,xuegang/gpdb,lintzc/gpdb,yuanzhao/gpdb,50wu/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,xuegang/gpdb,0x0FFF/gpdb,cjcjameson/gpdb,cjcjameson/gpdb,ashwinstar/gpdb,kaknikhil/gpdb,rvs/gpdb,50wu/gpdb,royc1/gpdb,CraigHarris/gpdb,royc1/gpdb,kaknikhil/gpdb,edespino/gpdb,ahachete/gpdb,lisakowen/gpdb,jmcatamney/gpdb,Quikling/gpdb,edespino/gpdb,janebeckman/gpdb,janebeckman/gpdb,50wu/gpdb,kaknikhil/gpdb,adam8157/gpdb,kaknikhil/gpdb,Quikling/gpdb,ashwinstar/gpdb,greenplum-db/gpdb,Chibin/gpdb,Chibin/gpdb,xuegang/gpdb,jmcatamney/gpdb,zaksoup/gpdb,adam8157/gpdb,chrishajas/gpdb,Quikling/gpdb,zaksoup/gpdb,cjcjameson/gpdb,lintzc/gpdb,Chibin/gpdb,Chibin/gpdb,kaknikhil/gpdb,rvs/gpdb,royc1/gpdb,zaksoup/gpdb,chrishajas/gpdb,rvs/gpdb,lintzc/gpdb,yuanzhao/gpdb,jmcatamney/gpdb,ahachete/gpdb,chrishajas/gpdb,zaksoup/gpdb,jmcatamney/gpdb,rvs/gpdb,50wu/gpdb,xinzweb/gpdb,chrishajas/gpdb,CraigHarris/gpdb,adam8157/gpdb,ashwinstar/gpdb,edespino/gpdb,rvs/gpdb,lisakowen/gpdb,CraigHarris/gpdb,jmcatamney/gpdb,zaksoup/gpdb,lintzc/gpdb,Quikling/gpdb,royc1/gpdb,xinzweb/gpdb,cjcjameson/gpdb,ashwinstar/gpdb,edespino/gpdb,lisakowen/gpdb,Chibin/gpdb,greenplum-db/gpdb,greenplum-db/gpdb,zaksoup/gpdb,edespino/gpdb,janebeckman/gpdb,xuegang/gpdb,Quikling/gpdb,Quikling/gpdb,greenplum-db/gpdb,zaksoup/gpdb,ahachete/gpdb,xinzweb/gpdb,yuanzhao/gpdb,yuanzhao/gpdb,Chibin/gpdb,cjcjameson/gpdb,edespino/gpdb,lisakowen/gpdb,xinzweb/gpdb,yuanzhao/gpdb,ashwinstar/gpdb,edespino/gpdb,greenplum-db/gpdb,rvs/gpdb