Skip to content
Snippets Groups Projects
Commit 688784f6 authored by Tom Lane's avatar Tom Lane
Browse files

Prevent planner from including temp tables of other backends when expanding

an inheritance tree.  Per recent discussions.
parent 558730ac
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.125 2005/07/28 22:27:00 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.126 2005/08/02 20:27:45 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "access/heapam.h" #include "access/heapam.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
...@@ -807,6 +808,16 @@ expand_inherited_rtentry(PlannerInfo *root, Index rti) ...@@ -807,6 +808,16 @@ expand_inherited_rtentry(PlannerInfo *root, Index rti)
RangeTblEntry *childrte; RangeTblEntry *childrte;
Index childRTindex; Index childRTindex;
/*
* 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)))
continue;
/* /*
* Build an RTE for the child, and attach to query's rangetable * Build an RTE for the child, and attach to query's rangetable
* list. We copy most fields of the parent's RTE, but replace * list. We copy most fields of the parent's RTE, but replace
...@@ -820,6 +831,17 @@ expand_inherited_rtentry(PlannerInfo *root, Index rti) ...@@ -820,6 +831,17 @@ expand_inherited_rtentry(PlannerInfo *root, Index rti)
inhRTIs = lappend_int(inhRTIs, childRTindex); inhRTIs = lappend_int(inhRTIs, childRTindex);
} }
/*
* If all the children were temp tables, pretend it's a non-inheritance
* situation. The duplicate RTE we added for the parent table is harmless.
*/
if (list_length(inhRTIs) < 2)
{
/* Clear flag to save repeated tests if called again */
rte->inh = false;
return NIL;
}
/* /*
* The executor will check the parent table's access permissions when * The executor will check the parent table's access permissions when
* it examines the parent's inheritlist entry. There's no need to * it examines the parent's inheritlist entry. There's no need to
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment