Ensure Material nodes generated by Orca always materialize
In cases where Orca generates a NLJ with a parameter on the inner side, the executor will not pass the EXEC_FLAG_REWIND flag down, as it assumed the inner side will always need to be rescanned. The material node will therefore not have its rewind flag set and can act as a no-op. This is not always correct. While the executor will set EXEC_FLAG_REWIND if the Materialize is directly above a motion, it does not recognize the case where the Materialize is on the inner side with other nodes between it and the motion, even though the Materialize serves to prevent a rescan of the underlying Motion node. This causes the execution to fail with: `Illegal rescan of motion node: invalid plan (nodeMotion.c:1623)` as it would attempt to rescan a motion. Since Orca only produces Materialize when necessary, either for performance reasons or to prevent rescan of an underlying Motion, EXEC_FLAG_REWIND should be set for any Materialize generated by Orca. Below is a valid plan generated by Orca: ``` Result (cost=0.00..3448.01 rows=1 width=4) -> Nested Loop (cost=0.00..3448.01 rows=1 width=1) Join Filter: true -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..431.00 rows=2 width=4) -> Seq Scan on foo1 (cost=0.00..431.00 rows=1 width=4) -> Result (cost=0.00..431.00 rows=1 width=1) Filter: (foo1.a = foo2.a) -> Materialize (cost=0.00..431.00 rows=1 width=4) -> Hash Semi Join (cost=0.00..431.00 rows=1 width=4) Hash Cond: (foo2.b = foo3.b) -> Gather Motion 3:1 (slice2; segments: 3) (cost=0.00..0.00 rows=1 width=8) -> Bitmap Heap Scan on foo2 (cost=0.00..0.00 rows=1 width=8) Recheck Cond: (c = 3) -> Bitmap Index Scan on f2c (cost=0.00..0.00 rows=0 width=0) Index Cond: (c = 3) -> Hash (cost=431.00..431.00 rows=1 width=4) -> Gather Motion 3:1 (slice3; segments: 3) (cost=0.00..431.00 rows=2 width=4) -> Seq Scan on foo3 (cost=0.00..431.00 rows=1 width=4) Optimizer: Pivotal Optimizer (GPORCA) ``` Co-authored-by: NChris Hajas <chajas@pivotal.io> Co-authored-by: NShreedhar Hardikar <shardikar@pivotal.io>
Showing
想要评论请 注册 或 登录