Skip to content

Commit 269ae02

Browse files
author
Antonin Houska
committed
Handle partitions with different order of columns.
1 parent 20ef8f7 commit 269ae02

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

concurrent.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,15 +576,33 @@ find_tuple_in_partition(HeapTuple tup, Relation partition,
576576
ScanKey key, int nkeys, ItemPointer ctid)
577577
{
578578
Oid part_oid = RelationGetRelid(partition);
579+
HeapTuple tup_mapped = NULL;
579580
PartitionEntry *entry;
580581

581582
entry = partitions_lookup(partitions, part_oid);
582583
if (entry == NULL)
583584
elog(ERROR, "identity index not found for partition %u", part_oid);
584585
Assert(entry->part_oid == part_oid);
585586

587+
/*
588+
* Make sure the tuple so it matches the partition.
589+
*/
590+
if (entry->conv_map)
591+
{
592+
/*
593+
* convert_tuple_for_dest_table() is not suitable here because we need
594+
* to keep the original tuple. XXX Should we add a boolean argument to
595+
* the function that indicates whether it should free the original
596+
* tuple?
597+
*/
598+
tup_mapped = pg_rewrite_execute_attr_map_tuple(tup,
599+
entry->conv_map);
600+
tup = tup_mapped;
601+
}
586602
find_tuple(tup, partition, entry->ident_index, key, nkeys, ctid,
587603
entry->ind_slot);
604+
if (tup_mapped)
605+
pfree(tup_mapped);
588606
}
589607

590608
/*

pg_rewrite.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,6 @@ get_identity_index(Relation rel_dst, Relation rel_src)
13711371
index_src = index_open(index_src_oid, AccessShareLock);
13721372
tupdesc_src = RelationGetDescr(index_src);
13731373

1374-
13751374
/*
13761375
* The tuple descriptors might not be equal, since some attributes of
13771376
* rel_dst can have different types. What should match though is attribute

specs/pg_rewrite_concurrent.spec

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ setup
44
CREATE EXTENSION pg_rewrite;
55

66
CREATE TABLE tbl_src(i int primary key, j int);
7-
INSERT INTO tbl_src(i, j) VALUES (1, 1), (4, 4);
7+
INSERT INTO tbl_src(i, j) VALUES (1, 10), (4, 40);
88

99
CREATE TABLE tbl_dst(i int primary key, j int) PARTITION BY RANGE(i);
1010
CREATE TABLE tbl_dst_part_1 PARTITION OF tbl_dst FOR VALUES FROM (1) TO (4);
11-
CREATE TABLE tbl_dst_part_2 PARTITION OF tbl_dst FOR VALUES FROM (4) TO (8);
11+
12+
-- Create a partition with different order of columns, to test that
13+
-- partition maps work.
14+
CREATE TABLE tbl_dst_part_2(j int, i int primary key);
15+
ALTER TABLE tbl_dst ATTACH PARTITION tbl_dst_part_2 FOR VALUES FROM (4) TO (8);
1216
}
1317

1418
teardown
@@ -66,12 +70,12 @@ BEGIN
6670
PERFORM pg_sleep(.1);
6771
END LOOP;
6872
END;
69-
$$
73+
$$;
7074
}
7175
step do_changes
7276
{
7377
-- Insert one row into each partition.
74-
INSERT INTO tbl_src VALUES (2, 2), (3, 3), (5, 5);
78+
INSERT INTO tbl_src VALUES (2, 20), (3, 30), (5, 50);
7579

7680
-- Update with no identity change.
7781
UPDATE tbl_src SET j=0 WHERE i=1;

0 commit comments

Comments
 (0)