diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2017-07-14 15:25:43 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2017-07-14 15:25:43 -0400 |
commit | decb08ebdf07f2fea4b6bb43380366ef5defbafb (patch) | |
tree | 8df1e4ed94f556acbf1cdf99a7344f8dda474f27 /src/backend/optimizer/util/clauses.c | |
parent | c95275fc202c231e867d2f0a00e8d18621b67f0d (diff) | |
download | postgresql-decb08ebdf07f2fea4b6bb43380366ef5defbafb.tar.gz postgresql-decb08ebdf07f2fea4b6bb43380366ef5defbafb.zip |
Code review for NextValueExpr expression node type.
Add missing infrastructure for this node type, notably in ruleutils.c where
its lack could demonstrably cause EXPLAIN to fail. Add outfuncs/readfuncs
support. (outfuncs support is useful today for debugging purposes. The
readfuncs support may never be needed, since at present it would only
matter for parallel query and NextValueExpr should never appear in a
parallelizable query; but it seems like a bad idea to have a primnode type
that isn't fully supported here.) Teach planner infrastructure that
NextValueExpr is a volatile, parallel-unsafe, non-leaky expression node
with cost cpu_operator_cost. Given its limited scope of usage, there
*might* be no live bug today from the lack of that knowledge, but it's
certainly going to bite us on the rear someday. Teach pg_stat_statements
about the new node type, too.
While at it, also teach cost_qual_eval() that MinMaxExpr, SQLValueFunction,
XmlExpr, and CoerceToDomain should be charged as cpu_operator_cost.
Failing to do this for SQLValueFunction was an oversight in my commit
0bb51aa96. The others are longer-standing oversights, but no time like the
present to fix them. (In principle, CoerceToDomain could have cost much
higher than this, but it doesn't presently seem worth trying to examine the
domain's constraints here.)
Modify execExprInterp.c to execute NextValueExpr as an out-of-line
function; it seems quite unlikely to me that it's worth insisting that
it be inlined in all expression eval methods. Besides, providing the
out-of-line function doesn't stop anyone from inlining if they want to.
Adjust some places where NextValueExpr support had been inserted with the
aid of a dartboard rather than keeping it in the same order as elsewhere.
Discussion: https://postgr.es/m/23862.1499981661@sss.pgh.pa.us
Diffstat (limited to 'src/backend/optimizer/util/clauses.c')
-rw-r--r-- | src/backend/optimizer/util/clauses.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index 8961ed88a81..8b4425dcf90 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -902,6 +902,12 @@ contain_mutable_functions_walker(Node *node, void *context) return true; } + if (IsA(node, NextValueExpr)) + { + /* NextValueExpr is volatile */ + return true; + } + /* * It should be safe to treat MinMaxExpr as immutable, because it will * depend on a non-cross-type btree comparison function, and those should @@ -969,6 +975,12 @@ contain_volatile_functions_walker(Node *node, void *context) context)) return true; + if (IsA(node, NextValueExpr)) + { + /* NextValueExpr is volatile */ + return true; + } + /* * See notes in contain_mutable_functions_walker about why we treat * MinMaxExpr, XmlExpr, and CoerceToDomain as immutable, while @@ -1019,6 +1031,8 @@ contain_volatile_functions_not_nextval_walker(Node *node, void *context) * See notes in contain_mutable_functions_walker about why we treat * MinMaxExpr, XmlExpr, and CoerceToDomain as immutable, while * SQLValueFunction is stable. Hence, none of them are of interest here. + * Also, since we're intentionally ignoring nextval(), presumably we + * should ignore NextValueExpr. */ /* Recurse to check arguments */ @@ -1146,7 +1160,7 @@ max_parallel_hazard_walker(Node *node, max_parallel_hazard_context *context) * contain a parallel-unsafe function; but useful constraints probably * never would have such, and assuming they do would cripple use of * parallel query in the presence of domain types.) SQLValueFunction - * should be safe in all cases. + * should be safe in all cases. NextValueExpr is parallel-unsafe. */ if (IsA(node, CoerceToDomain)) { @@ -1154,6 +1168,12 @@ max_parallel_hazard_walker(Node *node, max_parallel_hazard_context *context) return true; } + if (IsA(node, NextValueExpr)) + { + if (max_parallel_hazard_test(PROPARALLEL_UNSAFE, context)) + return true; + } + /* * As a notational convenience for callers, look through RestrictInfo. */ @@ -1495,6 +1515,7 @@ contain_leaked_vars_walker(Node *node, void *context) case T_SQLValueFunction: case T_NullTest: case T_BooleanTest: + case T_NextValueExpr: case T_List: /* |