gpdb icon indicating copy to clipboard operation
gpdb copied to clipboard

Orca supports propagating predicates from EXISTS/ANY subquery to outer relation

Open gpopt opened this issue 3 years ago • 0 comments

When there are predicates from correlated EXISTS/ANY subquery that we can infer for outer relation, Orca fails to infer that predicates, which may cause bad plan. This patch fixes that bug. But it still has some drawbacks, e.g., Orca still can't infer LIKE predicates or other complex predicates (e.g. function call etc.) due to the limits of Orca's constraints framework.

Before this patch:

explain select * from r where exists (select 1 from s where r2=s2 and s2=9);
                                          QUERY PLAN
---------------------------------------------------------------------------------------------------
Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..862.00 rows=1 width=46)
 ->  Hash Semi Join  (cost=0.00..862.00 rows=1 width=46)
       Hash Cond: (r.r2 = s.s2)
       ->  Seq Scan on r  (cost=0.00..431.00 rows=1 width=46)
       ->  Hash  (cost=431.00..431.00 rows=1 width=4)
             ->  Broadcast Motion 3:3  (slice2; segments: 3)  (cost=0.00..431.00 rows=1 width=4)
                   ->  Seq Scan on s  (cost=0.00..431.00 rows=1 width=4)
                         Filter: (s2 = 9)

After this patch:

explain select * from r where exists (select 1 from s where r2=s2 and s2=9);
                                          QUERY PLAN
---------------------------------------------------------------------------------------------------
Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..862.00 rows=1 width=46)
 ->  Hash Semi Join  (cost=0.00..862.00 rows=1 width=46)
       Hash Cond: (r.r2 = s.s2)
       ->  Seq Scan on r  (cost=0.00..431.00 rows=1 width=46)
             Filter: (r2 = 9)
       ->  Hash  (cost=431.00..431.00 rows=1 width=4)
             ->  Broadcast Motion 3:3  (slice2; segments: 3)  (cost=0.00..431.00 rows=1 width=4)
                   ->  Seq Scan on s  (cost=0.00..431.00 rows=1 width=4)
                         Filter: (s2 = 9)

Ref: GPQP-3

gpopt avatar Sep 09 '22 20:09 gpopt