Fix performance problem when building a lossy tidbitmap.
Fix performance problem when building a lossy tidbitmap.

As pointed out by Sergey Koposov, repeated invocations of tbm_lossify can
make building a large tidbitmap into an O(N^2) operation.  To fix, make
sure we remove more than the minimum amount of information per call, and
add a fallback path to behave sanely if we're unable to fit the bitmap
within the requested amount of memory.

This has been wrong since the tidbitmap code was written, so back-patch
to all supported branches.

arcivanov/postgres-xl,ashwinstar/gpdb,xinzweb/gpdb,yazun/postgres-xl,tpostgres-projects/tPostgres,tpostgres-projects/tPostgres,lisakowen/gpdb,jmcatamney/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,pavanvd/postgres-xl,jmcatamney/gpdb,kmjungersen/PostgresXL,adam8157/gpdb,arcivanov/postgres-xl,postmind-net/postgres-xl,xinzweb/gpdb,pavanvd/postgres-xl,ovr/postgres-xl,ashwinstar/gpdb,kmjungersen/PostgresXL,Postgres-XL/Postgres-XL,kmjungersen/PostgresXL,greenplum-db/gpdb,ashwinstar/gpdb,yazun/postgres-xl,pavanvd/postgres-xl,tpostgres-projects/tPostgres,techdragon/Postgres-XL,xinzweb/gpdb,ovr/postgres-xl,snaga/postgres-xl,techdragon/Postgres-XL,snaga/postgres-xl,xinzweb/gpdb,jmcatamney/gpdb,zeroae/postgres-xl,kmjungersen/PostgresXL,adam8157/gpdb,ovr/postgres-xl,adam8157/gpdb,lisakowen/gpdb,lisakowen/gpdb,techdragon/Postgres-XL,50wu/gpdb,arcivanov/postgres-xl,ovr/postgres-xl,ashwinstar/gpdb,zeroae/postgres-xl,greenplum-db/gpdb,oberstet/postgres-xl,postmind-net/postgres-xl,oberstet/postgres-xl,zeroae/postgres-xl,yazun/postgres-xl,postmind-net/postgres-xl,lisakowen/gpdb,Postgres-XL/Postgres-XL,jmcatamney/gpdb,kmjungersen/PostgresXL,Postgres-XL/Postgres-XL,greenplum-db/gpdb,pavanvd/postgres-xl,ashwinstar/gpdb,oberstet/postgres-xl,adam8157/gpdb,xinzweb/gpdb,lisakowen/gpdb,oberstet/postgres-xl,Postgres-XL/Postgres-XL,ashwinstar/gpdb,snaga/postgres-xl,adam8157/gpdb,ovr/postgres-xl,50wu/gpdb,yazun/postgres-xl,adam8157/gpdb,postmind-net/postgres-xl,arcivanov/postgres-xl,greenplum-db/gpdb,xinzweb/gpdb,tpostgres-projects/tPostgres,xinzweb/gpdb,greenplum-db/gpdb,zeroae/postgres-xl,50wu/gpdb,arcivanov/postgres-xl,lisakowen/gpdb,jmcatamney/gpdb,ashwinstar/gpdb,snaga/postgres-xl,oberstet/postgres-xl,jmcatamney/gpdb,postmind-net/postgres-xl,lisakowen/gpdb,adam8157/gpdb,50wu/gpdb,jmcatamney/gpdb,50wu/gpdb,xinzweb/gpdb,snaga/postgres-xl,techdragon/Postgres-XL,50wu/gpdb,yazun/postgres-xl,tpostgres-projects/tPostgres,50wu/gpdb,greenplum-db/gpdb,pavanvd/postgres-xl,adam8157/gpdb,Postgres-XL/Postgres-XL,zeroae/postgres-xl,arcivanov/postgres-xl,50wu/gpdb,techdragon/Postgres-XL,lisakowen/gpdb,greenplum-db/gpdb