Wrong assumption in IsCorrelatedOpExpr()
Wrong assumption in IsCorrelatedOpExpr()

Considering following repro with correlated subquery:

```
-- foo.c is a text
select * from foo where not exists (select * from bar where foo.c = foo.c || 'a');
```

This query will crash because referring param across slices. Here is the plan:

```
xzhang=#  explain select * from foo where not exists (select * from bar where foo.c = foo.c || 'a');
                                             QUERY PLAN
-----------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice3; segments: 3)  (cost=1.06..2.13 rows=4 width=3)
   ->  Hash Left Anti Semi Join  (cost=1.06..2.13 rows=2 width=3)
         Hash Cond: foo.c::text = "Expr_SUBQUERY".csq_c0
         ->  Redistribute Motion 3:3  (slice1; segments: 3)  (cost=0.00..1.03 rows=1 width=3)
               Hash Key: foo.c::text
               ->  Seq Scan on foo  (cost=0.00..1.01 rows=1 width=3)
         ->  Hash  (cost=1.05..1.05 rows=1 width=32)
               ->  Redistribute Motion 3:3  (slice2; segments: 3)  (cost=0.01..1.05 rows=1 width=32)
                     Hash Key: "Expr_SUBQUERY".csq_c0
                     ->  Result  (cost=0.01..1.02 rows=1 width=0)
                           One-Time Filter: ($0::text || 'a'::text) IS NOT NULL
                           ->  Seq Scan on bar  (cost=0.01..1.01 rows=1 width=0)
 Optimizer status: legacy query optimizer
(13 rows)
```

IsCorrelatedOpExpr() is checking an opexpr in format of:

```
foo(outer.var) OP bar(inner.var)
```

Then, extract the bar(inner.var) as innerExpr.

It assumes one side of the operator must be an inner
variable, and one side of the operator must be an outer variable.

However, there are cases where both of `opexp->args` are referring
to outer variables. Then, it mistakenly pick one side as inner variable.

Add a check to fail to extract `innerExpr` if both sides of opexr are outer variables
and return false.

Then, the subquery cannot be decorrelated, and hence remain as subplan. The correct query
plan is:

```
gpadmin=# explain select * from foo where not exists (select * from bar where foo.c = foo.c || 'a');
                                                      QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice2; segments: 3)  (cost=0.00..1474.89 rows=26400 width=32)
   ->  Seq Scan on foo  (cost=0.00..1474.89 rows=8800 width=32)
         Filter: NOT ((subplan))
         SubPlan 1
           ->  Result  (cost=0.01..1062.01 rows=32067 width=4)
                 One-Time Filter: $0 = ($0 || 'a'::text)
                 ->  Result  (cost=1158.21..2120.20 rows=32067 width=4)
                       ->  Materialize  (cost=1158.21..2120.20 rows=32067 width=4)
                             ->  Broadcast Motion 3:3  (slice1; segments: 3)  (cost=0.01..1062.01 rows=32067 width=4)
                                   ->  Seq Scan on bar  (cost=0.01..1062.01 rows=32067 width=4)
 Optimizer status: legacy query optimizer
(11 rows)
```

[#135636211]

Signed-off-by: HaiSheng Yuan <d24d5fc9e8498fe12c79f514db1a69a6d06b8a3c@pivotal.io>

xinzweb/gpdb,ashwinstar/gpdb,lintzc/gpdb,cjcjameson/gpdb,cjcjameson/gpdb,yuanzhao/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,Quikling/gpdb,Chibin/gpdb,jmcatamney/gpdb,ashwinstar/gpdb,lisakowen/gpdb,rvs/gpdb,kaknikhil/gpdb,greenplum-db/gpdb,cjcjameson/gpdb,50wu/gpdb,lisakowen/gpdb,edespino/gpdb,cjcjameson/gpdb,Chibin/gpdb,ashwinstar/gpdb,lisakowen/gpdb,cjcjameson/gpdb,lisakowen/gpdb,jmcatamney/gpdb,ashwinstar/gpdb,Chibin/gpdb,janebeckman/gpdb,jmcatamney/gpdb,adam8157/gpdb,Quikling/gpdb,greenplum-db/gpdb,edespino/gpdb,edespino/gpdb,edespino/gpdb,Quikling/gpdb,cjcjameson/gpdb,kaknikhil/gpdb,ashwinstar/gpdb,edespino/gpdb,cjcjameson/gpdb,adam8157/gpdb,yuanzhao/gpdb,greenplum-db/gpdb,janebeckman/gpdb,lisakowen/gpdb,lisakowen/gpdb,greenplum-db/gpdb,rvs/gpdb,Quikling/gpdb,yuanzhao/gpdb,50wu/gpdb,adam8157/gpdb,rvs/gpdb,kaknikhil/gpdb,kaknikhil/gpdb,Chibin/gpdb,lintzc/gpdb,Quikling/gpdb,adam8157/gpdb,lintzc/gpdb,jmcatamney/gpdb,lintzc/gpdb,jmcatamney/gpdb,50wu/gpdb,janebeckman/gpdb,yuanzhao/gpdb,50wu/gpdb,greenplum-db/gpdb,adam8157/gpdb,kaknikhil/gpdb,lintzc/gpdb,jmcatamney/gpdb,Quikling/gpdb,rvs/gpdb,cjcjameson/gpdb,kaknikhil/gpdb,lintzc/gpdb,Quikling/gpdb,Chibin/gpdb,lintzc/gpdb,Quikling/gpdb,edespino/gpdb,janebeckman/gpdb,rvs/gpdb,50wu/gpdb,yuanzhao/gpdb,rvs/gpdb,yuanzhao/gpdb,lintzc/gpdb,janebeckman/gpdb,50wu/gpdb,kaknikhil/gpdb,xinzweb/gpdb,lisakowen/gpdb,Chibin/gpdb,xinzweb/gpdb,adam8157/gpdb,janebeckman/gpdb,ashwinstar/gpdb,yuanzhao/gpdb,rvs/gpdb,edespino/gpdb,janebeckman/gpdb,50wu/gpdb,Quikling/gpdb,adam8157/gpdb,janebeckman/gpdb,ashwinstar/gpdb,yuanzhao/gpdb,kaknikhil/gpdb,Quikling/gpdb,greenplum-db/gpdb,xinzweb/gpdb,Chibin/gpdb,cjcjameson/gpdb,janebeckman/gpdb,edespino/gpdb,kaknikhil/gpdb,yuanzhao/gpdb,Chibin/gpdb,Chibin/gpdb,edespino/gpdb,lintzc/gpdb,xinzweb/gpdb,greenplum-db/gpdb,rvs/gpdb,adam8157/gpdb,cjcjameson/gpdb,xinzweb/gpdb,xinzweb/gpdb,rvs/gpdb,edespino/gpdb,Chibin/gpdb,50wu/gpdb,janebeckman/gpdb,yuanzhao/gpdb,kaknikhil/gpdb,ashwinstar/gpdb,lisakowen/gpdb,xinzweb/gpdb,jmcatamney/gpdb,rvs/gpdb