gporca icon indicating copy to clipboard operation
gporca copied to clipboard

Orca failed to generate plan for correlated scalar subquery

Open hsyuan opened this issue 7 years ago • 1 comments

Repro:

create table foo(a int, b int);
create table bar(a int, b int);
explain select * from bar left join foo on foo.a = (
select foo.a from foo where foo.b = bar.b order by 1 limit 1);

Output:

+--CLogicalLeftOuterJoin
   |--CLogicalGet "bar" ("bar"), Columns: ["a" (0), "b" (1), "ctid" (2), "xmin" (3), "cmin" (4), "xmax" (5), "cmax" (6), "tableoid" (7), "gp_segment_id" (8)] Key sets: {[0], [2,8]}
   |--CLogicalGet "foo" ("foo"), Columns: ["a" (9), "b" (10), "ctid" (11), "xmin" (12), "cmin" (13), "xmax" (14), "cmax" (15), "tableoid" (16), "gp_segment_id" (17)] Key sets: {[0], [2,8]}
   +--CScalarCmp (=)
      |--CScalarIdent "a" (9)
      +--CScalarSubquery["a" (18)]
         +--CLogicalLimit ( (521,1.0), "a" (18), NULLsFirst )  global
            |--CLogicalSelect
            |  |--CLogicalGet "foo" ("foo"), Columns: ["a" (18), "b" (19), "ctid" (20), "xmin" (21), "cmin" (22), "xmax" (23), "cmax" (24), "tableoid" (25), "gp_segment_id" (26)] Key sets: {[0], [2,8]}
            |  +--CScalarCmp (=)
            |     |--CScalarIdent "b" (19)
            |     +--CScalarIdent "b" (1)
            |--CScalarConst (0)
            +--CScalarConst (1)
",
2018-01-05 09:53:15:401111 CST,THD000,ERROR,"No plan has been computed for required properties",
2018-01-05 09:53:15:406242 CST,THD000,ERROR,"No plan has been computed for required properties",
LOG:  Planner produced plan :1
                                                              QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice3; segments: 3)  (cost=1.01..2.59 rows=4 width=16)
   ->  Hash Left Join  (cost=1.01..2.59 rows=2 width=16)
         Hash Cond: ((SubPlan 1)) = public.foo.a
         ->  Redistribute Motion 3:3  (slice2; segments: 3)  (cost=0.00..1.02 rows=1 width=8)
               Hash Key: ((SubPlan 1))
               ->  Seq Scan on bar  (cost=0.00..1.00 rows=1 width=8)
                     SubPlan 1
                       ->  Limit  (cost=1.01..1.03 rows=1 width=4)
                             ->  Limit  (cost=1.01..1.01 rows=1 width=4)
                                   ->  Sort  (cost=1.01..1.01 rows=1 width=4)
                                         Sort Key: public.foo.a
                                         ->  Result  (cost=1.00..1.01 rows=1 width=4)
                                               Filter: public.foo.b = $0
                                               ->  Materialize  (cost=1.00..1.01 rows=1 width=4)
                                                     ->  Broadcast Motion 3:3  (slice1; segments: 3)  (cost=0.00..1.00 rows=1 width=4)
                                                           ->  Seq Scan on foo  (cost=0.00..1.00 rows=1 width=4)
         ->  Hash  (cost=1.00..1.00 rows=1 width=8)
               ->  Seq Scan on foo  (cost=0.00..1.00 rows=1 width=8)
 Settings:  optimizer=on
 Optimizer status: legacy query optimizer
(20 rows)

BTW, why would the error message be output twice?

hsyuan avatar Jan 05 '18 15:01 hsyuan

And why are there 2 limit node in planner's subplan?

hsyuan avatar Jan 05 '18 16:01 hsyuan