Fix pushing down of quals in subqueries contains window funcs
Previously, if there was a subquery contaning window functions, pushing down of the filters was banned. This commit fixes the issue, by pushing downs filters which are not on the columns projected using window functions. Adding relevant tests. Test case: After porting the fix to gpdb master, in the below case the filter `b = 1` is pushed down on ``` explain select b from (select b, row_number() over (partition by b) from foo) f where b = 1; QUERY PLAN ---------------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice2; segments: 3) (cost=0.00..1.05 rows=1 width=4) -> Subquery Scan on f (cost=0.00..1.05 rows=1 width=4) -> WindowAgg (cost=0.00..1.04 rows=1 width=4) -> Redistribute Motion 3:3 (slice1; segments: 3) (cost=0.00..1.03 rows=1 width=4) Hash Key: foo.b -> Seq Scan on foo (cost=0.00..1.01 rows=1 width=4) Filter: b = 1 Optimizer: legacy query optimizer ``` Currently on master the plan is as below where the filter is not pushed down. ``` explain select b from (select b, row_number() over (partition by b) from foo) f where b = 1; QUERY PLAN ---------------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice2; segments: 3) (cost=1.04..1.07 rows=1 width=4) -> Subquery Scan on f (cost=1.04..1.07 rows=1 width=4) Filter: f.b = 1 -> WindowAgg (cost=1.04..1.06 rows=1 width=4) Partition By: foo.b -> Sort (cost=1.04..1.04 rows=1 width=4) Sort Key: foo.b -> Redistribute Motion 3:3 (slice1; segments: 3) (cost=0.00..1.03 rows=1 width=4) Hash Key: foo.b -> Seq Scan on foo (cost=0.00..1.01 rows=1 width=4) Optimizer: legacy query optimizer
Showing
想要评论请 注册 或 登录