mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Prevent planner from including temp tables of other backends when expanding
an inheritance tree. Per recent discussions.
This commit is contained in:
@ -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 @@
|
|||||||
|
|
||||||
|
|
||||||
#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)
|
|||||||
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)
|
|||||||
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
|
||||||
|
Reference in New Issue
Block a user