pgsql: Add an explicit representation of the output targetlist to Paths - Mailing list pgsql-committers
From | Tom Lane |
---|---|
Subject | pgsql: Add an explicit representation of the output targetlist to Paths |
Date | |
Msg-id | E1aWZSg-0003H7-8A@gemulon.postgresql.org Whole thread Raw |
List | pgsql-committers |
Add an explicit representation of the output targetlist to Paths. Up to now, there's been an assumption that all Paths for a given relation compute the same output column set (targetlist). However, there are good reasons to remove that assumption. For example, an indexscan on an expression index might be able to return the value of an expensive function "for free". While we have the ability to generate such a plan today in simple cases, we don't have a way to model that it's cheaper than a plan that computes the function from scratch, nor a way to create such a plan in join cases (where the function computation would normally happen at the topmost join node). Also, we need this so that we can have Paths representing post-scan/join steps, where the targetlist may well change from one step to the next. Therefore, invent a "struct PathTarget" representing the columns we expect a plan step to emit. It's convenient to include the output tuple width and tlist evaluation cost in this struct, and there will likely be additional fields in future. While Path nodes that actually do have custom outputs will need their own PathTargets, it will still be true that most Paths for a given relation will compute the same tlist. To reduce the overhead added by this patch, keep a "default PathTarget" in RelOptInfo, and allow Paths that compute that column set to just point to their parent RelOptInfo's reltarget. (In the patch as committed, actually every Path is like that, since we do not yet have any cases of custom PathTargets.) I took this opportunity to provide some more-honest costing of PlaceHolderVar evaluation. Up to now, the assumption that "scan/join reltargetlists have cost zero" was applied not only to Vars, where it's reasonable, but also PlaceHolderVars where it isn't. Now, we add the eval cost of a PlaceHolderVar's expression to the first plan level where it can be computed, by including it in the PathTarget cost field and adding that to the cost estimates for Paths. This isn't perfect yet but it's much better than before, and there is a way forward to improve it more. This costing change affects the join order chosen for a couple of the regression tests, changing expected row ordering. Branch ------ master Details ------- http://git.postgresql.org/pg/commitdiff/19a541143a09c067ec8cac77ec6a64eb5b1b662b Modified Files -------------- contrib/file_fdw/file_fdw.c | 4 +- contrib/postgres_fdw/deparse.c | 4 +- contrib/postgres_fdw/postgres_fdw.c | 11 ++-- doc/src/sgml/fdwhandler.sgml | 2 +- src/backend/nodes/outfuncs.c | 19 ++++-- src/backend/optimizer/path/allpaths.c | 37 +++++------ src/backend/optimizer/path/costsize.c | 106 +++++++++++++++++++++++++++---- src/backend/optimizer/path/indxpath.c | 7 +- src/backend/optimizer/plan/createplan.c | 15 ++--- src/backend/optimizer/plan/initsplan.c | 7 +- src/backend/optimizer/plan/planner.c | 67 +++++++++++-------- src/backend/optimizer/util/clauses.c | 2 +- src/backend/optimizer/util/pathnode.c | 37 +++++++++-- src/backend/optimizer/util/placeholder.c | 40 +++++++++--- src/backend/optimizer/util/relnode.c | 24 ++++--- src/include/nodes/relation.h | 47 +++++++++++--- src/include/optimizer/placeholder.h | 4 +- src/test/regress/expected/join.out | 36 +++++------ 18 files changed, 326 insertions(+), 143 deletions(-)
pgsql-committers by date: