Avoid possible duplicated materialize node. (#6387)
Avoid possible duplicated materialize node. (#6387)

See the plan example blow (without this patch).

regression=# explain
select a.idv, b.idv from tidv a, tidv b where a.idv = b.idv;
                                                   QUERY PLAN
-----------------------------------------------------------------------------------------------------------------
 Merge Join  (cost=10000000000.33..10000085645.93 rows=2787840 width=64)
   Merge Cond: (a.idv = b.idv)
   ->  Gather Motion 3:1  (slice1; segments: 3)  (cost=0.17..21848.17 rows=52800 width=32)
         Merge Key: a.idv
         ->  Index Only Scan using tidv_idv_idx on tidv a  (cost=0.17..20792.17 rows=17600 width=32)
   ->  Materialize  (cost=0.00..0.00 rows=0 width=0)
         ->  Materialize  (cost=0.00..0.00 rows=0 width=0)
               ->  Gather Motion 3:1  (slice2; segments: 3)  (cost=0.17..21848.17 rows=52800 width=32)
                     Merge Key: b.idv
                     ->  Index Only Scan using tidv_idv_idx on tidv b  (cost=0.17..20792.17 rows=17600 width=32)
 Optimizer: legacy query optimizer
(11 rows)

Reviewed by Richard Guo and Jinbao Chen
xinzweb/gpdb,ashwinstar/gpdb,adam8157/gpdb,jmcatamney/gpdb,adam8157/gpdb,50wu/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,lisakowen/gpdb,50wu/gpdb,ashwinstar/gpdb,greenplum-db/gpdb,adam8157/gpdb,lisakowen/gpdb,lisakowen/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,lisakowen/gpdb,jmcatamney/gpdb,50wu/gpdb,xinzweb/gpdb,lisakowen/gpdb,xinzweb/gpdb,xinzweb/gpdb,50wu/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,xinzweb/gpdb,adam8157/gpdb,ashwinstar/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,50wu/gpdb,ashwinstar/gpdb,ashwinstar/gpdb,xinzweb/gpdb,50wu/gpdb,adam8157/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,50wu/gpdb,50wu/gpdb,ashwinstar/gpdb,adam8157/gpdb,lisakowen/gpdb,adam8157/gpdb,greenplum-db/gpdb,lisakowen/gpdb,jmcatamney/gpdb,xinzweb/gpdb,greenplum-db/gpdb,lisakowen/gpdb,adam8157/gpdb,xinzweb/gpdb