Skip to content

Commit ff7da2f

Browse files
committed
Make planner safe for recursive calls --- needed for cases where
eval_const_expressions tries to simplify an SQL function.
1 parent faa4171 commit ff7da2f

File tree

3 files changed

+32
-54
lines changed

3 files changed

+32
-54
lines changed

src/backend/optimizer/path/indxpath.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.89 2000/07/26 23:46:22 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.90 2000/07/27 23:15:56 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -1153,7 +1153,7 @@ one_pred_clause_test(Expr *predicate, Node *clause)
11531153
* this test should always be considered false.
11541154
*/
11551155

1156-
static StrategyNumber
1156+
static const StrategyNumber
11571157
BT_implic_table[BTMaxStrategyNumber][BTMaxStrategyNumber] = {
11581158
{2, 2, 0, 0, 0},
11591159
{1, 2, 0, 0, 0},

src/backend/optimizer/plan/planner.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.85 2000/06/20 04:22:21 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.86 2000/07/27 23:15:57 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -50,6 +50,22 @@ Plan *
5050
planner(Query *parse)
5151
{
5252
Plan *result_plan;
53+
Index save_PlannerQueryLevel;
54+
List *save_PlannerInitPlan;
55+
List *save_PlannerParamVar;
56+
int save_PlannerPlanId;
57+
58+
/*
59+
* The planner can be called recursively (an example is when
60+
* eval_const_expressions tries to simplify an SQL function).
61+
* So, global state variables must be saved and restored.
62+
*
63+
* (Perhaps these should be moved into the Query structure instead?)
64+
*/
65+
save_PlannerQueryLevel = PlannerQueryLevel;
66+
save_PlannerInitPlan = PlannerInitPlan;
67+
save_PlannerParamVar = PlannerParamVar;
68+
save_PlannerPlanId = PlannerPlanId;
5369

5470
/* Initialize state for subselects */
5571
PlannerQueryLevel = 1;
@@ -78,6 +94,12 @@ planner(Query *parse)
7894
/* final cleanup of the plan */
7995
set_plan_references(result_plan);
8096

97+
/* restore state for outer planner, if any */
98+
PlannerQueryLevel = save_PlannerQueryLevel;
99+
PlannerInitPlan = save_PlannerInitPlan;
100+
PlannerParamVar = save_PlannerParamVar;
101+
PlannerPlanId = save_PlannerPlanId;
102+
81103
return result_plan;
82104
}
83105

src/backend/optimizer/util/plancat.c

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.59 2000/07/05 23:11:26 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.60 2000/07/27 23:16:04 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -272,15 +272,12 @@ join_selectivity(Oid functionObjectId,
272272
List *
273273
find_inheritance_children(Oid inhparent)
274274
{
275-
static ScanKeyData key[1] = {
276-
{0, Anum_pg_inherits_inhparent, F_OIDEQ}
277-
};
278-
279275
List *list = NIL;
280276
Relation relation;
281277
HeapScanDesc scan;
282278
HeapTuple inheritsTuple;
283279
Oid inhrelid;
280+
ScanKeyData key[1];
284281

285282
/*
286283
* Can skip the scan if pg_class shows the relation has never had
@@ -289,10 +286,11 @@ find_inheritance_children(Oid inhparent)
289286
if (! has_subclass(inhparent))
290287
return NIL;
291288

292-
fmgr_info(F_OIDEQ, &key[0].sk_func);
293-
key[0].sk_nargs = key[0].sk_func.fn_nargs;
294-
key[0].sk_argument = ObjectIdGetDatum(inhparent);
295-
289+
ScanKeyEntryInitialize(&key[0],
290+
(bits16) 0x0,
291+
(AttrNumber) Anum_pg_inherits_inhparent,
292+
(RegProcedure) F_OIDEQ,
293+
ObjectIdGetDatum(inhparent));
296294
relation = heap_openr(InheritsRelationName, AccessShareLock);
297295
scan = heap_beginscan(relation, 0, SnapshotNow, 1, key);
298296
while (HeapTupleIsValid(inheritsTuple = heap_getnext(scan, 0)))
@@ -330,45 +328,3 @@ has_subclass(Oid relationId)
330328
relationId);
331329
return ((Form_pg_class) GETSTRUCT(tuple))->relhassubclass;
332330
}
333-
334-
#ifdef NOT_USED
335-
/*
336-
* VersionGetParents
337-
*
338-
* Returns a LISP list containing the OIDs of all relations which are
339-
* base relations of the relation with OID 'verrelid'.
340-
*/
341-
List *
342-
VersionGetParents(Oid verrelid)
343-
{
344-
static ScanKeyData key[1] = {
345-
{0, Anum_pg_version_verrelid, F_OIDEQ}
346-
};
347-
348-
HeapTuple versionTuple;
349-
Relation relation;
350-
HeapScanDesc scan;
351-
Oid verbaseid;
352-
List *list = NIL;
353-
354-
fmgr_info(F_OIDEQ, &key[0].sk_func);
355-
key[0].sk_nargs = key[0].sk_func.fn_nargs;
356-
key[0].sk_argument = ObjectIdGetDatum(verrelid);
357-
relation = heap_openr(VersionRelationName, AccessShareLock);
358-
scan = heap_beginscan(relation, 0, SnapshotNow, 1, key);
359-
while (HeapTupleIsValid(versionTuple = heap_getnext(scan, 0)))
360-
{
361-
verbaseid = ((Form_pg_version)
362-
GETSTRUCT(versionTuple))->verbaseid;
363-
364-
list = lconsi(verbaseid, list);
365-
366-
key[0].sk_argument = ObjectIdGetDatum(verbaseid);
367-
heap_rescan(scan, 0, key);
368-
}
369-
heap_endscan(scan);
370-
heap_close(relation, AccessShareLock);
371-
return list;
372-
}
373-
374-
#endif

0 commit comments

Comments
 (0)