GitHub user zuyu opened a pull request:
https://github.com/apache/incubator-quickstep/pull/268
Skip predicate pushdown if the node's input is a base relation.
Assigned to @jianqiao.
This small PR fixed the bug in PR #174 that we may have two identical
`Selection`s due to the predicate pushdown. The fix avoids such case by
skipping the pushdown if and only if a node's input is a base table.
For the following test query in `Partition.test`:
```
SELECT fact.id, test.char_col
FROM test JOIN fact ON test.int_col = fact.id
WHERE test.int_col > 0 OR test.int_col < 0;
```
Previously to this PR, we would generate a bad plan with two same
`Selection`s.
```
9: I0708 15:31:29.931959 3661849536 PhysicalGenerator.cpp:192] After
applying rule PruneColumns:
9: TopLevelPlan
9: +-plan=HashJoin
9: | +-left=Selection
9: | | +-input=TableReference[relation=Test,alias=test]
9: | | | +-AttributeReference[id=0,name=int_col,relation=test,type=Int NULL]
9: | | | +-AttributeReference[id=1,name=long_col,relation=test,type=Long]
9: | | | +-AttributeReference[id=2,name=float_col,relation=test,type=Float]
9: | | |
+-AttributeReference[id=3,name=double_col,relation=test,type=Double NULL]
9: | | |
+-AttributeReference[id=4,name=char_col,relation=test,type=Char(20)]
9: | | +-filter_predicate=Or
9: | | | +-Greater
9: | | | | +-AttributeReference[id=0,name=int_col,relation=test,type=Int
NULL]
9: | | | | +-Literal[value=0,type=Int]
9: | | | +-Less
9: | | | +-AttributeReference[id=0,name=int_col,relation=test,type=Int
NULL]
9: | | | +-Literal[value=0,type=Int]
9: | | +-project_expressions=
9: | | +-AttributeReference[id=0,name=int_col,relation=test,type=Int NULL]
9: | |
+-AttributeReference[id=4,name=char_col,relation=test,type=Char(20)]
9: | +-right=TableReference[relation=fact,
9: | | output_partition_scheme_header=PARTITION BY HASH ( { 5 } )
PARTITIONS 4]
9: | | +-AttributeReference[id=5,name=id,relation=fact,type=Int NULL]
9: | | +-AttributeReference[id=6,name=score,relation=fact,type=Double NULL]
9: | +-project_expressions=
9: | | +-AttributeReference[id=5,name=id,relation=fact,type=Int NULL]
9: | | +-AttributeReference[id=4,name=char_col,relation=test,type=Char(20)]
9: | +-left_join_attributes=
9: | | +-AttributeReference[id=0,name=int_col,relation=test,type=Int NULL]
9: | +-right_join_attributes=
9: | +-AttributeReference[id=5,name=id,relation=fact,type=Int NULL]
9: +-output_attributes=
9: +-AttributeReference[id=5,name=id,relation=fact,type=Int NULL]
9: +-AttributeReference[id=4,name=char_col,relation=test,type=Char(20)]
9: I0708 15:31:29.932862 3661849536 PhysicalGenerator.cpp:192] After
applying rule PushDownLowCostDisjunctivePredicate:
9: TopLevelPlan
9: +-plan=HashJoin
9: | +-left=Selection
9: | | +-input=Selection
9: | | | +-input=TableReference[relation=Test,alias=test]
9: | | | | +-AttributeReference[id=0,name=int_col,relation=test,type=Int
NULL]
9: | | | | +-AttributeReference[id=1,name=long_col,relation=test,type=Long]
9: | | | |
+-AttributeReference[id=2,name=float_col,relation=test,type=Float]
9: | | | |
+-AttributeReference[id=3,name=double_col,relation=test,type=Double NULL]
9: | | | |
+-AttributeReference[id=4,name=char_col,relation=test,type=Char(20)]
9: | | | +-filter_predicate=Or
9: | | | | +-Greater
9: | | | | | +-AttributeReference[id=0,name=int_col,relation=test,type=Int
NULL]
9: | | | | | +-Literal[value=0,type=Int]
9: | | | | +-Less
9: | | | | +-AttributeReference[id=0,name=int_col,relation=test,type=Int
NULL]
9: | | | | +-Literal[value=0,type=Int]
9: | | | +-project_expressions=
9: | | | +-AttributeReference[id=0,name=int_col,relation=test,type=Int
NULL]
9: | | | +-AttributeReference[id=1,name=long_col,relation=test,type=Long]
9: | | |
+-AttributeReference[id=2,name=float_col,relation=test,type=Float]
9: | | |
+-AttributeReference[id=3,name=double_col,relation=test,type=Double NULL]
9: | | |
+-AttributeReference[id=4,name=char_col,relation=test,type=Char(20)]
9: | | +-filter_predicate=Or
9: | | | +-Greater
9: | | | | +-AttributeReference[id=0,name=int_col,relation=test,type=Int
NULL]
9: | | | | +-Literal[value=0,type=Int]
9: | | | +-Less
9: | | | +-AttributeReference[id=0,name=int_col,relation=test,type=Int
NULL]
9: | | | +-Literal[value=0,type=Int]
9: | | +-project_expressions=
9: | | +-AttributeReference[id=0,name=int_col,relation=test,type=Int NULL]
9: | |
+-AttributeReference[id=4,name=char_col,relation=test,type=Char(20)]
9: | +-right=TableReference[relation=fact,
9: | | output_partition_scheme_header=PARTITION BY HASH ( { 5 } )
PARTITIONS 4]
9: | | +-AttributeReference[id=5,name=id,relation=fact,typ