aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/execUtils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/executor/execUtils.c')
-rw-r--r--src/backend/executor/execUtils.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c
index 5b3eaec80bc..e91a6ebddd5 100644
--- a/src/backend/executor/execUtils.c
+++ b/src/backend/executor/execUtils.c
@@ -45,6 +45,7 @@
#include "access/relscan.h"
#include "access/transam.h"
#include "executor/executor.h"
+#include "executor/execPartition.h"
#include "jit/jit.h"
#include "mb/pg_wchar.h"
#include "nodes/nodeFuncs.h"
@@ -1068,3 +1069,66 @@ ExecCleanTargetListLength(List *targetlist)
}
return len;
}
+
+/* Return a bitmap representing columns being inserted */
+Bitmapset *
+ExecGetInsertedCols(ResultRelInfo *relinfo, EState *estate)
+{
+ /*
+ * The columns are stored in the range table entry. If this ResultRelInfo
+ * doesn't have an entry in the range table (i.e. if it represents a
+ * partition routing target), fetch the parent's RTE and map the columns
+ * to the order they are in the partition.
+ */
+ if (relinfo->ri_RangeTableIndex != 0)
+ {
+ RangeTblEntry *rte = rt_fetch(relinfo->ri_RangeTableIndex,
+ estate->es_range_table);
+
+ return rte->insertedCols;
+ }
+ else
+ {
+ ResultRelInfo *rootRelInfo = relinfo->ri_RootResultRelInfo;
+ RangeTblEntry *rte = rt_fetch(rootRelInfo->ri_RangeTableIndex,
+ estate->es_range_table);
+ TupleConversionMap *map;
+
+ map = convert_tuples_by_name(RelationGetDescr(rootRelInfo->ri_RelationDesc),
+ RelationGetDescr(relinfo->ri_RelationDesc),
+ gettext_noop("could not convert row type"));
+ if (map != NULL)
+ return execute_attr_map_cols(rte->insertedCols, map);
+ else
+ return rte->insertedCols;
+ }
+}
+
+/* Return a bitmap representing columns being updated */
+Bitmapset *
+ExecGetUpdatedCols(ResultRelInfo *relinfo, EState *estate)
+{
+ /* see ExecGetInsertedCols() */
+ if (relinfo->ri_RangeTableIndex != 0)
+ {
+ RangeTblEntry *rte = rt_fetch(relinfo->ri_RangeTableIndex,
+ estate->es_range_table);
+
+ return rte->updatedCols;
+ }
+ else
+ {
+ ResultRelInfo *rootRelInfo = relinfo->ri_RootResultRelInfo;
+ RangeTblEntry *rte = rt_fetch(rootRelInfo->ri_RangeTableIndex,
+ estate->es_range_table);
+ TupleConversionMap *map;
+
+ map = convert_tuples_by_name(RelationGetDescr(rootRelInfo->ri_RelationDesc),
+ RelationGetDescr(relinfo->ri_RelationDesc),
+ gettext_noop("could not convert row type"));
+ if (map != NULL)
+ return execute_attr_map_cols(rte->updatedCols, map);
+ else
+ return rte->updatedCols;
+ }
+}