mirror of
https://github.com/postgres/postgres.git
synced 2026-05-15 19:10:30 -04:00
Fix attribute mapping for COPY TO on partitioned tables.
Commit 4bea91f21f enabled COPY TO on a partitioned table to read
tuples from its partitions and mapped them to the root table's tuple
descriptor before output. However, it incorrectly built the attribute
map from the root table to the partition.
This commit fixes by building the attribute map from the partition to
the root table, ensuring that partition attributes are correctly
mapped to their corresponding root attributes.
Author: Chao Li <lic@highgo.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/85EA70F3-C3DB-477B-B856-EA569FDAAE7C@gmail.com
This commit is contained in:
parent
ce146621f7
commit
82f0135a26
3 changed files with 22 additions and 2 deletions
|
|
@ -1348,8 +1348,8 @@ CopyRelationTo(CopyToState cstate, Relation rel, Relation root_rel, uint64 *proc
|
|||
if (root_rel != NULL)
|
||||
{
|
||||
root_slot = table_slot_create(root_rel, NULL);
|
||||
map = build_attrmap_by_name_if_req(RelationGetDescr(root_rel),
|
||||
RelationGetDescr(rel),
|
||||
map = build_attrmap_by_name_if_req(RelationGetDescr(rel),
|
||||
RelationGetDescr(root_rel),
|
||||
false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -594,3 +594,14 @@ id val
|
|||
5 15
|
||||
6 16
|
||||
DROP TABLE PP;
|
||||
-- Check if COPY TO handles dropped columns in partitions.
|
||||
CREATE TABLE pp_dropcol (id int, val int) PARTITION BY RANGE (id);
|
||||
CREATE TABLE pp_dropcol_1 (dropme int, id int, val int);
|
||||
ALTER TABLE pp_dropcol_1 DROP COLUMN dropme;
|
||||
ALTER TABLE pp_dropcol ATTACH PARTITION pp_dropcol_1 FOR VALUES FROM (1) TO (10);
|
||||
INSERT INTO pp_dropcol VALUES (1, 11), (2, 12);
|
||||
COPY pp_dropcol TO stdout(header);
|
||||
id val
|
||||
1 11
|
||||
2 12
|
||||
DROP TABLE pp_dropcol;
|
||||
|
|
|
|||
|
|
@ -535,3 +535,12 @@ CREATE TABLE pp_510 PARTITION OF pp_2 FOR VALUES FROM (5) TO (10);
|
|||
INSERT INTO pp SELECT g, 10 + g FROM generate_series(1,6) g;
|
||||
COPY pp TO stdout(header);
|
||||
DROP TABLE PP;
|
||||
|
||||
-- Check if COPY TO handles dropped columns in partitions.
|
||||
CREATE TABLE pp_dropcol (id int, val int) PARTITION BY RANGE (id);
|
||||
CREATE TABLE pp_dropcol_1 (dropme int, id int, val int);
|
||||
ALTER TABLE pp_dropcol_1 DROP COLUMN dropme;
|
||||
ALTER TABLE pp_dropcol ATTACH PARTITION pp_dropcol_1 FOR VALUES FROM (1) TO (10);
|
||||
INSERT INTO pp_dropcol VALUES (1, 11), (2, 12);
|
||||
COPY pp_dropcol TO stdout(header);
|
||||
DROP TABLE pp_dropcol;
|
||||
|
|
|
|||
Loading…
Reference in a new issue