zhouqingqing / qpmodel

A Relational Optimizer and Executor
MIT License
64 stars 18 forks source link

support nestted exist subquery, see TestExistsSubquery #241

Closed 9DemonFox closed 3 years ago

9DemonFox commented 3 years ago

And now it support nest exsitsSubquery like sql below.

select a1 from a where exists (select b.b1 from b where b.b2=a.a1 and exists (select c.c2 from c where c.c1=b.b1))

Whose physic plan likes blow before.

PhysicFilter  (actual rows=0)
    Output: a.a1[0]
    Filter: ({#marker}[0] and {#marker}[0])
    -> PhysicMarkJoin Left (actual rows=0)
        Output: a.a1[0],#marker,#marker
        -> PhysicScanTable a (actual rows=0)
            Output: a.a1[0]
        -> PhysicMarkJoin Left (actual rows=0)
            Output: #marker
            Filter: c.c1[1]=b.b1[0]
            -> PhysicScanTable b (actual rows=0)
                Output: b.b1[0]
                Filter: b.b2[1]=?a.a1[0]
            -> PhysicScanTable c (actual rows=0)
                Output: c.c1[0]

Where there is still a parameter Expr Filter: b.b2[1]=?a.a1[0]。 Now it works well.

PhysicFilter  (actual rows=2)
    Output: a.a1[0]
    Filter: {#marker}[1]
    -> PhysicMarkJoin Left (actual rows=3)
        Output: a.a1[0],#marker
        Filter: b.b2[1]=a.a1[0]
        -> PhysicScanTable a (actual rows=3)
            Output: a.a1[0]
        -> PhysicFilter  (actual rows=3, loops=3)
            Output: b.b2[0]
            Filter: {#marker}[1]
            -> PhysicMarkJoin Left (actual rows=3, loops=3)
                Output: b.b2[0],#marker
                Filter: c.c1[2]=b.b1[1]
                -> PhysicScanTable b (actual rows=3, loops=3)
                    Output: b.b2[1],b.b1[0]
                -> PhysicScanTable c (actual rows=3, loops=9)
                    Output: c.c1[0]
9DemonFox commented 3 years ago

This is helpful to handling IN subquery.