14
14
*
15
15
*
16
16
* IDENTIFICATION
17
- * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.125 2005/07/28 22 :27:00 tgl Exp $
17
+ * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.126 2005/08/02 20 :27:45 tgl Exp $
18
18
*
19
19
*-------------------------------------------------------------------------
20
20
*/
21
21
#include "postgres.h"
22
22
23
23
24
24
#include "access/heapam.h"
25
+ #include "catalog/namespace.h"
25
26
#include "catalog/pg_type.h"
26
27
#include "nodes/makefuncs.h"
27
28
#include "optimizer/clauses.h"
@@ -807,6 +808,16 @@ expand_inherited_rtentry(PlannerInfo *root, Index rti)
807
808
RangeTblEntry * childrte ;
808
809
Index childRTindex ;
809
810
811
+ /*
812
+ * It is possible that the parent table has children that are
813
+ * temp tables of other backends. We cannot safely access such
814
+ * tables (because of buffering issues), and the best thing to do
815
+ * seems to be to silently ignore them.
816
+ */
817
+ if (childOID != parentOID &&
818
+ isOtherTempNamespace (get_rel_namespace (childOID )))
819
+ continue ;
820
+
810
821
/*
811
822
* Build an RTE for the child, and attach to query's rangetable
812
823
* list. We copy most fields of the parent's RTE, but replace
@@ -820,6 +831,17 @@ expand_inherited_rtentry(PlannerInfo *root, Index rti)
820
831
inhRTIs = lappend_int (inhRTIs , childRTindex );
821
832
}
822
833
834
+ /*
835
+ * If all the children were temp tables, pretend it's a non-inheritance
836
+ * situation. The duplicate RTE we added for the parent table is harmless.
837
+ */
838
+ if (list_length (inhRTIs ) < 2 )
839
+ {
840
+ /* Clear flag to save repeated tests if called again */
841
+ rte -> inh = false;
842
+ return NIL ;
843
+ }
844
+
823
845
/*
824
846
* The executor will check the parent table's access permissions when
825
847
* it examines the parent's inheritlist entry. There's no need to
0 commit comments