Class IntersectToDistinctRule

All Implemented Interfaces:
TransformationRule

@Enclosing public class IntersectToDistinctRule extends RelRule<IntersectToDistinctRule.Config> implements TransformationRule
Planner rule that translates a distinct Intersect (all = false) into a group of operators composed of Union, Aggregate, etc.

Example

Original query:


 SELECT job FROM "scott".emp WHERE deptno = 10
 INTERSECT
 SELECT job FROM "scott".emp WHERE deptno = 20
 

Query after conversion:


 SELECT job
 FROM (
   SELECT job, 0 AS i FROM "scott".emp WHERE deptno = 10
   UNION ALL
   SELECT job, 1 AS i FROM "scott".emp WHERE deptno = 20
 )
 GROUP BY job
 HAVING COUNT(*) FILTER (WHERE i = 0) > 0
    AND COUNT(*) FILTER (WHERE i = 1) > 0
 
See Also: