From 948d6ec90fd35d6e1a59d0b1af8d6efd8442f0ad Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 31 Mar 2009 22:12:48 +0000 Subject: Modify the relcache to record the temp status of both local and nonlocal temp relations; this is no more expensive than before, now that we have pg_class.relistemp. Insert tests into bufmgr.c to prevent attempting to fetch pages from nonlocal temp relations. This provides a low-level defense against bugs-of-omission allowing temp pages to be loaded into shared buffers, as in the contrib/pgstattuple problem reported by Stuart Bishop. While at it, tweak a bunch of places to use new relcache tests (instead of expensive probes into pg_namespace) to detect local or nonlocal temp tables. --- src/backend/optimizer/prep/prepunion.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/backend/optimizer/prep/prepunion.c') diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c index 43aa515ae5e..06f920561a2 100644 --- a/src/backend/optimizer/prep/prepunion.c +++ b/src/backend/optimizer/prep/prepunion.c @@ -22,7 +22,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.167 2009/03/05 17:30:29 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.168 2009/03/31 22:12:48 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1258,21 +1258,23 @@ expand_inherited_rtentry(PlannerInfo *root, RangeTblEntry *rte, Index rti) Index childRTindex; AppendRelInfo *appinfo; + /* Open rel, acquire the appropriate lock type */ + if (childOID != parentOID) + newrelation = heap_open(childOID, lockmode); + else + newrelation = oldrelation; + /* * It is possible that the parent table has children that are temp * tables of other backends. We cannot safely access such tables * (because of buffering issues), and the best thing to do seems to be * to silently ignore them. */ - if (childOID != parentOID && - isOtherTempNamespace(get_rel_namespace(childOID))) + if (childOID != parentOID && RELATION_IS_OTHER_TEMP(newrelation)) + { + heap_close(newrelation, lockmode); continue; - - /* Open rel, acquire the appropriate lock type */ - if (childOID != parentOID) - newrelation = heap_open(childOID, lockmode); - else - newrelation = oldrelation; + } /* * Build an RTE for the child, and attach to query's rangetable list. -- cgit v1.2.3