aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/indexcmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-08-10 11:35:33 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-08-10 11:36:15 -0400
commiteaccfded98a9c677d3a2e849c1747ec90e8596a6 (patch)
treec341448f69a2e67484de7a0a43e12848c20eb414 /src/backend/commands/indexcmds.c
parentb3055ab4fb5839a872bfe354b2b5ac31e6903ed6 (diff)
downloadpostgresql-eaccfded98a9c677d3a2e849c1747ec90e8596a6.tar.gz
postgresql-eaccfded98a9c677d3a2e849c1747ec90e8596a6.zip
Centralize the logic for detecting misplaced aggregates, window funcs, etc.
Formerly we relied on checking after-the-fact to see if an expression contained aggregates, window functions, or sub-selects when it shouldn't. This is grotty, easily forgotten (indeed, we had forgotten to teach DefineIndex about rejecting window functions), and none too efficient since it requires extra traversals of the parse tree. To improve matters, define an enum type that classifies all SQL sub-expressions, store it in ParseState to show what kind of expression we are currently parsing, and make transformAggregateCall, transformWindowFuncCall, and transformSubLink check the expression type and throw error if the type indicates the construct is disallowed. This allows removal of a large number of ad-hoc checks scattered around the code base. The enum type is sufficiently fine-grained that we can still produce error messages of at least the same specificity as before. Bringing these error checks together revealed that we'd been none too consistent about phrasing of the error messages, so standardize the wording a bit. Also, rewrite checking of aggregate arguments so that it requires only one traversal of the arguments, rather than up to three as before. In passing, clean up some more comments left over from add_missing_from support, and annotate some tests that I think are dead code now that that's gone. (I didn't risk actually removing said dead code, though.)
Diffstat (limited to 'src/backend/commands/indexcmds.c')
-rw-r--r--src/backend/commands/indexcmds.c26
1 files changed, 5 insertions, 21 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index a0840d1bf06..f6772686091 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -941,17 +941,9 @@ static void
CheckPredicate(Expr *predicate)
{
/*
- * We don't currently support generation of an actual query plan for a
- * predicate, only simple scalar expressions; hence these restrictions.
+ * transformExpr() should have already rejected subqueries, aggregates,
+ * and window functions, based on the EXPR_KIND_ for a predicate.
*/
- if (contain_subplans((Node *) predicate))
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("cannot use subquery in index predicate")));
- if (contain_agg_clause((Node *) predicate))
- ereport(ERROR,
- (errcode(ERRCODE_GROUPING_ERROR),
- errmsg("cannot use aggregate in index predicate")));
/*
* A predicate using mutable functions is probably wrong, for the same
@@ -1072,18 +1064,10 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
expr);
/*
- * We don't currently support generation of an actual query
- * plan for an index expression, only simple scalar
- * expressions; hence these restrictions.
+ * transformExpr() should have already rejected subqueries,
+ * aggregates, and window functions, based on the EXPR_KIND_
+ * for an index expression.
*/
- if (contain_subplans(expr))
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("cannot use subquery in index expression")));
- if (contain_agg_clause(expr))
- ereport(ERROR,
- (errcode(ERRCODE_GROUPING_ERROR),
- errmsg("cannot use aggregate function in index expression")));
/*
* A expression using mutable functions is probably wrong,