From f68e11f373de8b7b1d19203b8edac1a13a8d406d Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 15 Nov 1999 02:00:15 +0000 Subject: Implement subselects in target lists. Also, relax requirement that subselects can only appear on the righthand side of a binary operator. That's still true for quantified predicates like x = ANY (SELECT ...), but a subselect that delivers a single result can now appear anywhere in an expression. This is implemented by changing EXPR_SUBLINK sublinks to represent just the (SELECT ...) expression, without any 'left hand side' or combining operator --- so they're now more like EXISTS_SUBLINK. To handle the case of '(x, y, z) = (SELECT ...)', I added a new sublink type MULTIEXPR_SUBLINK, which acts just like EXPR_SUBLINK used to. But the grammar will only generate one for a multiple-left-hand-side row expression. --- src/backend/optimizer/plan/planmain.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/backend/optimizer/plan/planmain.c') diff --git a/src/backend/optimizer/plan/planmain.c b/src/backend/optimizer/plan/planmain.c index 3b289fb3d0e..7da2ee4c211 100644 --- a/src/backend/optimizer/plan/planmain.c +++ b/src/backend/optimizer/plan/planmain.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.46 1999/10/07 04:23:06 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.47 1999/11/15 02:00:07 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -87,9 +87,25 @@ query_planner(Query *root, tlist = (List *) SS_replace_correlation_vars((Node *) tlist); qual = (List *) SS_replace_correlation_vars((Node *) qual); } + /* Expand SubLinks to SubPlans */ if (root->hasSubLinks) + { + tlist = (List *) SS_process_sublinks((Node *) tlist); qual = (List *) SS_process_sublinks((Node *) qual); + if (root->groupClause != NIL) + { + /* + * Check for ungrouped variables passed to subplans. + * Note we do NOT do this for subplans in WHERE; it's legal + * there because WHERE is evaluated pre-GROUP. + */ + if (check_subplans_for_ungrouped_vars((Node *) tlist, + root->groupClause, + tlist)) + elog(ERROR, "Sub-SELECT must use only GROUPed attributes from outer SELECT"); + } + } /* * If the query contains no relation references at all, it must be -- cgit v1.2.3