Commit ff7da2f4 authored by Tom Lane's avatar Tom Lane

Make planner safe for recursive calls --- needed for cases where

eval_const_expressions tries to simplify an SQL function.
parent faa41717
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.89 2000/07/26 23:46:22 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.90 2000/07/27 23:15:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1153,7 +1153,7 @@ one_pred_clause_test(Expr *predicate, Node *clause) ...@@ -1153,7 +1153,7 @@ one_pred_clause_test(Expr *predicate, Node *clause)
* this test should always be considered false. * this test should always be considered false.
*/ */
static StrategyNumber static const StrategyNumber
BT_implic_table[BTMaxStrategyNumber][BTMaxStrategyNumber] = { BT_implic_table[BTMaxStrategyNumber][BTMaxStrategyNumber] = {
{2, 2, 0, 0, 0}, {2, 2, 0, 0, 0},
{1, 2, 0, 0, 0}, {1, 2, 0, 0, 0},
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.85 2000/06/20 04:22:21 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.86 2000/07/27 23:15:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -50,6 +50,22 @@ Plan * ...@@ -50,6 +50,22 @@ Plan *
planner(Query *parse) planner(Query *parse)
{ {
Plan *result_plan; Plan *result_plan;
Index save_PlannerQueryLevel;
List *save_PlannerInitPlan;
List *save_PlannerParamVar;
int save_PlannerPlanId;
/*
* The planner can be called recursively (an example is when
* eval_const_expressions tries to simplify an SQL function).
* So, global state variables must be saved and restored.
*
* (Perhaps these should be moved into the Query structure instead?)
*/
save_PlannerQueryLevel = PlannerQueryLevel;
save_PlannerInitPlan = PlannerInitPlan;
save_PlannerParamVar = PlannerParamVar;
save_PlannerPlanId = PlannerPlanId;
/* Initialize state for subselects */ /* Initialize state for subselects */
PlannerQueryLevel = 1; PlannerQueryLevel = 1;
...@@ -78,6 +94,12 @@ planner(Query *parse) ...@@ -78,6 +94,12 @@ planner(Query *parse)
/* final cleanup of the plan */ /* final cleanup of the plan */
set_plan_references(result_plan); set_plan_references(result_plan);
/* restore state for outer planner, if any */
PlannerQueryLevel = save_PlannerQueryLevel;
PlannerInitPlan = save_PlannerInitPlan;
PlannerParamVar = save_PlannerParamVar;
PlannerPlanId = save_PlannerPlanId;
return result_plan; return result_plan;
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.59 2000/07/05 23:11:26 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.60 2000/07/27 23:16:04 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -272,15 +272,12 @@ join_selectivity(Oid functionObjectId, ...@@ -272,15 +272,12 @@ join_selectivity(Oid functionObjectId,
List * List *
find_inheritance_children(Oid inhparent) find_inheritance_children(Oid inhparent)
{ {
static ScanKeyData key[1] = {
{0, Anum_pg_inherits_inhparent, F_OIDEQ}
};
List *list = NIL; List *list = NIL;
Relation relation; Relation relation;
HeapScanDesc scan; HeapScanDesc scan;
HeapTuple inheritsTuple; HeapTuple inheritsTuple;
Oid inhrelid; Oid inhrelid;
ScanKeyData key[1];
/* /*
* Can skip the scan if pg_class shows the relation has never had * Can skip the scan if pg_class shows the relation has never had
...@@ -289,10 +286,11 @@ find_inheritance_children(Oid inhparent) ...@@ -289,10 +286,11 @@ find_inheritance_children(Oid inhparent)
if (! has_subclass(inhparent)) if (! has_subclass(inhparent))
return NIL; return NIL;
fmgr_info(F_OIDEQ, &key[0].sk_func); ScanKeyEntryInitialize(&key[0],
key[0].sk_nargs = key[0].sk_func.fn_nargs; (bits16) 0x0,
key[0].sk_argument = ObjectIdGetDatum(inhparent); (AttrNumber) Anum_pg_inherits_inhparent,
(RegProcedure) F_OIDEQ,
ObjectIdGetDatum(inhparent));
relation = heap_openr(InheritsRelationName, AccessShareLock); relation = heap_openr(InheritsRelationName, AccessShareLock);
scan = heap_beginscan(relation, 0, SnapshotNow, 1, key); scan = heap_beginscan(relation, 0, SnapshotNow, 1, key);
while (HeapTupleIsValid(inheritsTuple = heap_getnext(scan, 0))) while (HeapTupleIsValid(inheritsTuple = heap_getnext(scan, 0)))
...@@ -330,45 +328,3 @@ has_subclass(Oid relationId) ...@@ -330,45 +328,3 @@ has_subclass(Oid relationId)
relationId); relationId);
return ((Form_pg_class) GETSTRUCT(tuple))->relhassubclass; return ((Form_pg_class) GETSTRUCT(tuple))->relhassubclass;
} }
#ifdef NOT_USED
/*
* VersionGetParents
*
* Returns a LISP list containing the OIDs of all relations which are
* base relations of the relation with OID 'verrelid'.
*/
List *
VersionGetParents(Oid verrelid)
{
static ScanKeyData key[1] = {
{0, Anum_pg_version_verrelid, F_OIDEQ}
};
HeapTuple versionTuple;
Relation relation;
HeapScanDesc scan;
Oid verbaseid;
List *list = NIL;
fmgr_info(F_OIDEQ, &key[0].sk_func);
key[0].sk_nargs = key[0].sk_func.fn_nargs;
key[0].sk_argument = ObjectIdGetDatum(verrelid);
relation = heap_openr(VersionRelationName, AccessShareLock);
scan = heap_beginscan(relation, 0, SnapshotNow, 1, key);
while (HeapTupleIsValid(versionTuple = heap_getnext(scan, 0)))
{
verbaseid = ((Form_pg_version)
GETSTRUCT(versionTuple))->verbaseid;
list = lconsi(verbaseid, list);
key[0].sk_argument = ObjectIdGetDatum(verbaseid);
heap_rescan(scan, 0, key);
}
heap_endscan(scan);
heap_close(relation, AccessShareLock);
return list;
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment