exec_simple_check_plan() must not allow a plan having initPlans or

subPlans to be considered 'simple'.  This fixes reported problem with
'return exists (select 1 from foo);' in plpgsql function.
This commit is contained in:
Tom Lane 2000-03-11 06:19:00 +00:00
parent f3a9d75ebd
commit 73f5b0847b
1 changed files with 16 additions and 13 deletions

View File

@ -3,7 +3,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.18 2000/02/07 03:39:13 inoue Exp $ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.19 2000/03/11 06:19:00 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
@ -2510,30 +2510,35 @@ exec_simple_check_plan(PLpgSQL_expr * expr)
if (plan == NULL) /* utility statement produces this */ if (plan == NULL) /* utility statement produces this */
return; return;
if (nodeTag(plan) != T_Result) if (! IsA(plan, Result))
return; return;
/* ---------- /* ----------
* 3. The plan must have a single attribute as result * 3. Can't have any subplan or qual clause, either
* ----------
*/
if (plan->lefttree != NULL ||
plan->righttree != NULL ||
plan->initPlan != NULL ||
plan->subPlan != NULL ||
plan->qual != NULL ||
((Result *) plan)->resconstantqual != NULL)
return;
/* ----------
* 4. The plan must have a single attribute as result
* ---------- * ----------
*/ */
if (length(plan->targetlist) != 1) if (length(plan->targetlist) != 1)
return; return;
/* ---------- tle = (TargetEntry *) lfirst(plan->targetlist);
* 4. Don't know if all these can break us, so let SPI handle
* those plans
* ----------
*/
if (plan->qual != NULL || plan->lefttree != NULL || plan->righttree != NULL)
return;
/* ---------- /* ----------
* 5. Check that all the nodes in the expression are one of * 5. Check that all the nodes in the expression are one of
* Expr, Param or Const. * Expr, Param or Const.
* ---------- * ----------
*/ */
tle = (TargetEntry *) lfirst(plan->targetlist);
if (!exec_simple_check_node(tle->expr)) if (!exec_simple_check_node(tle->expr))
return; return;
@ -2563,8 +2568,6 @@ exec_simple_check_plan(PLpgSQL_expr * expr)
default: default:
expr->plan_simple_type = InvalidOid; expr->plan_simple_type = InvalidOid;
} }
return;
} }