summaryrefslogtreecommitdiff
path: root/src/backend/access/common/tupconvert.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/access/common/tupconvert.c')
-rw-r--r--src/backend/access/common/tupconvert.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/backend/access/common/tupconvert.c b/src/backend/access/common/tupconvert.c
index a40382b1467..c95961a63e9 100644
--- a/src/backend/access/common/tupconvert.c
+++ b/src/backend/access/common/tupconvert.c
@@ -21,6 +21,7 @@
#include "postgres.h"
#include "access/htup_details.h"
+#include "access/sysattr.h"
#include "access/tupconvert.h"
#include "utils/builtins.h"
@@ -402,6 +403,59 @@ do_convert_tuple(HeapTuple tuple, TupleConversionMap *map)
}
/*
+ * Perform conversion of bitmap of columns according to the map.
+ *
+ * The input and output bitmaps are offset by
+ * FirstLowInvalidHeapAttributeNumber to accommodate system cols, like the
+ * column-bitmaps in RangeTblEntry.
+ */
+Bitmapset *
+execute_attr_map_cols(Bitmapset *in_cols, TupleConversionMap *map)
+{
+ AttrNumber *attrMap = map->attrMap;
+ int maplen = map->outdesc->natts;
+ Bitmapset *out_cols;
+ int out_attnum;
+
+ /* fast path for the common trivial case */
+ if (in_cols == NULL)
+ return NULL;
+
+ /*
+ * For each output column, check which input column it corresponds to.
+ */
+ out_cols = NULL;
+
+ for (out_attnum = FirstLowInvalidHeapAttributeNumber + 1;
+ out_attnum <= maplen;
+ out_attnum++)
+ {
+ int in_attnum;
+
+ if (out_attnum < 0)
+ {
+ /* System column. No mapping. */
+ in_attnum = out_attnum;
+ }
+ else if (out_attnum == 0)
+ continue;
+ else
+ {
+ /* normal user column */
+ in_attnum = attrMap[out_attnum - 1];
+
+ if (in_attnum == 0)
+ continue;
+ }
+
+ if (bms_is_member(in_attnum - FirstLowInvalidHeapAttributeNumber, in_cols))
+ out_cols = bms_add_member(out_cols, out_attnum - FirstLowInvalidHeapAttributeNumber);
+ }
+
+ return out_cols;
+}
+
+/*
* Free a TupleConversionMap structure.
*/
void