Fix partitionrank query for external partitions
Fix partitionrank query for external partitions

When dumping a partitioning hierarchy with external members, pg_dump
will create the external table separately and EXCHANGE it into the
hierarchy since CREATE TABLE .. PARTITION BY cannot express external
tables. The query for finding the rank at which to EXCHANGE the table
into had a bug which made the external partition end up at a different
place in the hiearchy on restoring.

	create table t (i integer, j integer)
		distributed by (i)
		partition by range (j) (start(1) end(3) every(1));
	create readable external table tt_external (i int, j int)
		location ('gpfdist://host.invalid:8000/file') format 'text';
	alter table t exchange partition
		for (rank(2)) with table tt_external without validation;

This yielded the following DDL in the dump (edited only for line
width):

	CREATE TABLE t (
	    i integer,
	    j integer
	) DISTRIBUTED BY (i) PARTITION BY RANGE(j)
	          (
	          START (1) END (2) EVERY (1) WITH (tablename='t_1_prt_1',
			  									appendonly=false ),
	          START (2) END (3) EVERY (1) WITH (tablename='t_1_prt_2',
			  									appendonly=false )
	          );
	ALTER TABLE t EXCHANGE PARTITION
		FOR (RANK(1)) WITH TABLE t_1_prt_2_external_partition__
		WITHOUT VALIDATION;

This effectively reverts 2ea6aec39cffca1d9028ebacaf50e7eea5664854
which attempted to optimize the partitionrank query, but fell a
brick shy of the intended load it seems. Going back to the original
query which is known to work, with optimizing the case left for
another patch to tackle.

Backpatch to 5.X

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