Class ImplementExceptAll

java.lang.Object
io.trino.sql.planner.iterative.rule.ImplementExceptAll
All Implemented Interfaces:
Rule<ExceptNode>

public class ImplementExceptAll extends Object implements Rule<ExceptNode>
Implement EXCEPT ALL using union, window and filter.

Transforms:


 - Except all
   output: a, b
     - Source1 (a1, b1)
     - Source2 (a2, b2)
     - Source3 (a3, b3)
 
Into:

 - Project (prune helper symbols)
   output: a, b
     - Filter (row_number <= greatest(greatest(count1 - count2, 0) - count3, 0))
         - Window (partition by a, b)
           count1 <- count(marker1)
           count2 <- count(marker2)
           count3 <- count(marker3)
           row_number <- row_number()
               - Union
                 output: a, b, marker1, marker2, marker3
                   - Project (marker1 <- true, marker2 <- null, marker3 <- null)
                       - Source1 (a1, b1)
                   - Project (marker1 <- null, marker2 <- true, marker3 <- null)
                       - Source2 (a2, b2)
                   - Project (marker1 <- null, marker2 <- null, marker3 <- true)
                       - Source3 (a3, b3)