Rewrite the planner's handling of materialized plan types so that there is
Tom Lane <tgl@sss.pgh.pa.us>
Rewrite the planner's handling of materialized plan types so that there is an explicit model of rescan costs being different from first-time costs. The costing of Material nodes in particular now has some visible relationship to the actual runtime behavior, where before it was essentially fantasy. This also fixes up a couple of places where different materialized plan types were treated differently for no very good reason (probably just oversights). A couple of the regression tests are affected, because the planner now chooses to put the other relation on the inside of a nestloop-with-materialize. So far as I can see both changes are sane, and the planner is now more consistently following the expectation that it should prefer to materialize the smaller of two relations. Per a recent discussion with Robert Haas.
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/executor/execAmi.c | modified | +28 −1 |
| src/backend/optimizer/path/costsize.c | modified | +158 −54 |
| src/backend/optimizer/path/joinpath.c | modified | +5 −12 |
| src/backend/optimizer/plan/createplan.c | modified | +2 −1 |
| src/backend/optimizer/plan/subselect.c | modified | +7 −23 |
| src/backend/optimizer/util/pathnode.c | modified | +4 −2 |
| src/include/executor/executor.h | modified | +2 −1 |
| src/include/optimizer/cost.h | modified | +3 −2 |
| src/test/regress/expected/geometry_1.out | modified | +12 −12 |
| src/test/regress/expected/geometry_2.out | modified | +12 −12 |
| src/test/regress/expected/geometry.out | modified | +12 −12 |
| src/test/regress/expected/join.out | modified | +789 −789 |