Skip to content

Commit d2945de

Browse files
committed
Fix Assert failure in PushOverrideSearchPath when trying to restore a search
path that specifies useTemp, but there is no active temp schema in the current session. (This can happen if the path was saved during a transaction that created a temp schema and was later rolled back.) For existing callers it's sufficient to ignore the useTemp flag in this case, though we might later want to offer an option to create a fresh temp schema. So far as I can tell this is just an Assert failure: in a non-assert build, the code would push a zero onto the new search path, which is useless but not very harmful. Per bug report from Heikki. Back-patch to 8.3; prior versions don't have this code.
1 parent 361cadb commit d2945de

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/backend/catalog/namespace.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.125 2010/02/26 02:00:36 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.125.4.1 2010/08/13 16:27:18 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -2666,6 +2666,17 @@ GetOverrideSearchPath(MemoryContext context)
26662666
*
26672667
* We allow nested overrides, hence the push/pop terminology. The GUC
26682668
* search_path variable is ignored while an override is active.
2669+
*
2670+
* It's possible that newpath->useTemp is set but there is no longer any
2671+
* active temp namespace, if the path was saved during a transaction that
2672+
* created a temp namespace and was later rolled back. In that case we just
2673+
* ignore useTemp. A plausible alternative would be to create a new temp
2674+
* namespace, but for existing callers that's not necessary because an empty
2675+
* temp namespace wouldn't affect their results anyway.
2676+
*
2677+
* It's also worth noting that other schemas listed in newpath might not
2678+
* exist anymore either. We don't worry about this because OIDs that match
2679+
* no existing namespace will simply not produce any hits during searches.
26692680
*/
26702681
void
26712682
PushOverrideSearchPath(OverrideSearchPath *newpath)
@@ -2699,11 +2710,8 @@ PushOverrideSearchPath(OverrideSearchPath *newpath)
26992710
if (newpath->addCatalog)
27002711
oidlist = lcons_oid(PG_CATALOG_NAMESPACE, oidlist);
27012712

2702-
if (newpath->addTemp)
2703-
{
2704-
Assert(OidIsValid(myTempNamespace));
2713+
if (newpath->addTemp && OidIsValid(myTempNamespace))
27052714
oidlist = lcons_oid(myTempNamespace, oidlist);
2706-
}
27072715

27082716
/*
27092717
* Build the new stack entry, then insert it at the head of the list.

src/backend/utils/cache/plancache.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* Portions Copyright (c) 1994, Regents of the University of California
3636
*
3737
* IDENTIFICATION
38-
* $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.35 2010/02/26 02:01:11 momjian Exp $
38+
* $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.35.4.1 2010/08/13 16:27:18 tgl Exp $
3939
*
4040
*-------------------------------------------------------------------------
4141
*/
@@ -513,6 +513,8 @@ RevalidateCachedPlan(CachedPlanSource *plansource, bool useResOwner)
513513

514514
/*
515515
* Restore the search_path that was in use when the plan was made.
516+
* See comments for PushOverrideSearchPath about limitations of this.
517+
*
516518
* (XXX is there anything else we really need to restore?)
517519
*/
518520
PushOverrideSearchPath(plansource->search_path);

0 commit comments

Comments
 (0)