summaryrefslogtreecommitdiff
path: root/src/backend/nodes/nodeFuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-01-28 17:54:10 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2019-01-28 17:54:23 -0500
commit4be058fe9ec5e630239b656af21fc083371f30ed (patch)
tree1e422ec3af7f08b7a1cdd7c57b71cd3215cec152 /src/backend/nodes/nodeFuncs.c
parent5c1186751214416fdf88f33a89c3dc88391d2d60 (diff)
downloadpostgresql-4be058fe9ec5e630239b656af21fc083371f30ed.tar.gz
In the planner, replace an empty FROM clause with a dummy RTE.
The fact that "SELECT expression" has no base relations has long been a thorn in the side of the planner. It makes it hard to flatten a sub-query that looks like that, or is a trivial VALUES() item, because the planner generally uses relid sets to identify sub-relations, and such a sub-query would have an empty relid set if we flattened it. prepjointree.c contains some baroque logic that works around this in certain special cases --- but there is a much better answer. We can replace an empty FROM clause with a dummy RTE that acts like a table of one row and no columns, and then there are no such corner cases to worry about. Instead we need some logic to get rid of useless dummy RTEs, but that's simpler and covers more cases than what was there before. For really trivial cases, where the query is just "SELECT expression" and nothing else, there's a hazard that adding the extra RTE makes for a noticeable slowdown; even though it's not much processing, there's not that much for the planner to do overall. However testing says that the penalty is very small, close to the noise level. In more complex queries, this is able to find optimizations that we could not find before. The new RTE type is called RTE_RESULT, since the "scan" plan type it gives rise to is a Result node (the same plan we produced for a "SELECT expression" query before). To avoid confusion, rename the old ResultPath path type to GroupResultPath, reflecting that it's only used in degenerate grouping cases where we know the query produces just one grouped row. (It wouldn't work to unify the two cases, because there are different rules about where the associated quals live during query_planner.) Note: although this touches readfuncs.c, I don't think a catversion bump is required, because the added case can't occur in stored rules, only plans. Patch by me, reviewed by David Rowley and Mark Dilger Discussion: https://postgr.es/m/15944.1521127664@sss.pgh.pa.us
Diffstat (limited to 'src/backend/nodes/nodeFuncs.c')
-rw-r--r--src/backend/nodes/nodeFuncs.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c
index a806d51edc..ecb9abd7fe 100644
--- a/src/backend/nodes/nodeFuncs.c
+++ b/src/backend/nodes/nodeFuncs.c
@@ -2329,10 +2329,6 @@ range_table_walker(List *rtable,
if (walker(rte->tablesample, context))
return true;
break;
- case RTE_CTE:
- case RTE_NAMEDTUPLESTORE:
- /* nothing to do */
- break;
case RTE_SUBQUERY:
if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
if (walker(rte->subquery, context))
@@ -2355,6 +2351,11 @@ range_table_walker(List *rtable,
if (walker(rte->values_lists, context))
return true;
break;
+ case RTE_CTE:
+ case RTE_NAMEDTUPLESTORE:
+ case RTE_RESULT:
+ /* nothing to do */
+ break;
}
if (walker(rte->securityQuals, context))
@@ -3164,10 +3165,6 @@ range_table_mutator(List *rtable,
TableSampleClause *);
/* we don't bother to copy eref, aliases, etc; OK? */
break;
- case RTE_CTE:
- case RTE_NAMEDTUPLESTORE:
- /* nothing to do */
- break;
case RTE_SUBQUERY:
if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
{
@@ -3198,6 +3195,11 @@ range_table_mutator(List *rtable,
case RTE_VALUES:
MUTATE(newrte->values_lists, rte->values_lists, List *);
break;
+ case RTE_CTE:
+ case RTE_NAMEDTUPLESTORE:
+ case RTE_RESULT:
+ /* nothing to do */
+ break;
}
MUTATE(newrte->securityQuals, rte->securityQuals, List *);
newrt = lappend(newrt, newrte);