Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit176572e

Browse files
committed
transform tuples for COPY TO/FROM as well
1 parent69abd81 commit176572e

File tree

4 files changed

+160
-24
lines changed

4 files changed

+160
-24
lines changed

‎expected/pathman_utility_stmt_hooking.out‎

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,76 @@ SELECT * FROM copy_stmt_hooking.test WHERE val > 20;
160160
/* COPY TO (partitioned column is not specified) */
161161
COPY copy_stmt_hooking.test(comment) FROM stdin;
162162
ERROR: partitioned column's value should not be NULL
163-
/* delete all data */
164-
SELECT drop_partitions('copy_stmt_hooking.test', true);
165-
NOTICE: function copy_stmt_hooking.test_upd_trig_func() does not exist, skipping
166-
drop_partitions
167-
-----------------
168-
5
163+
/* Drop column (make use of 'tuple_map') */
164+
ALTER TABLE copy_stmt_hooking.test DROP COLUMN comment;
165+
/* create new partition */
166+
SELECT get_number_of_partitions('copy_stmt_hooking.test');
167+
get_number_of_partitions
168+
--------------------------
169+
5
169170
(1 row)
170171

172+
INSERT INTO copy_stmt_hooking.test (val, c3, c4) VALUES (26, 1, 2);
173+
SELECT get_number_of_partitions('copy_stmt_hooking.test');
174+
get_number_of_partitions
175+
--------------------------
176+
6
177+
(1 row)
178+
179+
/* check number of columns in 'test' */
180+
SELECT count(*) FROM pg_attribute
181+
WHERE attnum > 0 AND attrelid = 'copy_stmt_hooking.test'::REGCLASS;
182+
count
183+
-------
184+
4
185+
(1 row)
186+
187+
/* check number of columns in 'test_6' */
188+
SELECT count(*) FROM pg_attribute
189+
WHERE attnum > 0 AND attrelid = 'copy_stmt_hooking.test_6'::REGCLASS;
190+
count
191+
-------
192+
3
193+
(1 row)
194+
195+
/* COPY FROM (test transformed tuples) */
196+
COPY copy_stmt_hooking.test (val, c3, c4) TO stdout;
197+
100
198+
600
199+
700
200+
1100
201+
1600
202+
2100
203+
2612
204+
/* COPY TO (insert into table with dropped column) */
205+
COPY copy_stmt_hooking.test(val, c3, c4) FROM stdin;
206+
/* COPY TO (insert into table without dropped column) */
207+
COPY copy_stmt_hooking.test(val, c3, c4) FROM stdin;
208+
/* check tuples from last partition (without dropped column) */
209+
SELECT *, tableoid::REGCLASS FROM copy_stmt_hooking.test ORDER BY val;
210+
val | c3 | c4 | tableoid
211+
-----+----+----+--------------------------
212+
1 | 0 | 0 | copy_stmt_hooking.test_1
213+
2 | 1 | 2 | copy_stmt_hooking.test_1
214+
6 | 0 | 0 | copy_stmt_hooking.test_2
215+
7 | 0 | 0 | copy_stmt_hooking.test_2
216+
11 | 0 | 0 | copy_stmt_hooking.test_3
217+
16 | 0 | 0 | copy_stmt_hooking.test_4
218+
21 | 0 | 0 | copy_stmt_hooking.test_5
219+
26 | 1 | 2 | copy_stmt_hooking.test_6
220+
27 | 1 | 2 | copy_stmt_hooking.test_6
221+
(9 rows)
222+
223+
/* drop modified table */
224+
DROP TABLE copy_stmt_hooking.test CASCADE;
225+
NOTICE: drop cascades to 6 other objects
226+
/* create table again */
227+
CREATE TABLE copy_stmt_hooking.test(
228+
val int not null,
229+
comment text,
230+
c3 int,
231+
c4 int);
232+
CREATE INDEX ON copy_stmt_hooking.test(val);
171233
/* test for HASH partitioning */
172234
SELECT create_hash_partitions('copy_stmt_hooking.test', 'val', 5);
173235
create_hash_partitions

‎sql/pathman_utility_stmt_hooking.sql‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CREATE EXTENSION pg_pathman;
66
* Test COPY
77
*/
88
CREATESCHEMAcopy_stmt_hooking;
9+
910
CREATETABLEcopy_stmt_hooking.test(
1011
valintnot null,
1112
commenttext,
@@ -75,8 +76,52 @@ test_no_part
7576
\.
7677

7778

78-
/* delete all data*/
79-
SELECT drop_partitions('copy_stmt_hooking.test', true);
79+
/* Drop column (make use of 'tuple_map')*/
80+
ALTERTABLEcopy_stmt_hooking.test DROP COLUMN comment;
81+
82+
83+
/* create new partition*/
84+
SELECT get_number_of_partitions('copy_stmt_hooking.test');
85+
INSERT INTOcopy_stmt_hooking.test (val, c3, c4)VALUES (26,1,2);
86+
SELECT get_number_of_partitions('copy_stmt_hooking.test');
87+
88+
/* check number of columns in 'test'*/
89+
SELECTcount(*)FROM pg_attribute
90+
WHERE attnum>0AND attrelid='copy_stmt_hooking.test'::REGCLASS;
91+
92+
/* check number of columns in 'test_6'*/
93+
SELECTcount(*)FROM pg_attribute
94+
WHERE attnum>0AND attrelid='copy_stmt_hooking.test_6'::REGCLASS;
95+
96+
97+
/* COPY FROM (test transformed tuples)*/
98+
COPYcopy_stmt_hooking.test (val, c3, c4) TO stdout;
99+
100+
/* COPY TO (insert into table with dropped column)*/
101+
COPYcopy_stmt_hooking.test(val, c3, c4)FROM stdin;
102+
212
103+
\.
104+
105+
/* COPY TO (insert into table without dropped column)*/
106+
COPYcopy_stmt_hooking.test(val, c3, c4)FROM stdin;
107+
2712
108+
\.
109+
110+
/* check tuples from last partition (without dropped column)*/
111+
SELECT*, tableoid::REGCLASSFROMcopy_stmt_hooking.testORDER BY val;
112+
113+
114+
/* drop modified table*/
115+
DROPTABLEcopy_stmt_hooking.test CASCADE;
116+
117+
118+
/* create table again*/
119+
CREATETABLEcopy_stmt_hooking.test(
120+
valintnot null,
121+
commenttext,
122+
c3int,
123+
c4int);
124+
CREATEINDEXONcopy_stmt_hooking.test(val);
80125

81126

82127
/* test for HASH partitioning*/

‎src/partition_filter.c‎

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ init_result_parts_storage(ResultPartsStorage *parts_storage,
177177
void
178178
fini_result_parts_storage(ResultPartsStorage*parts_storage,boolclose_rels)
179179
{
180-
/* Close partitions and their indices if asked to */
180+
HASH_SEQ_STATUSstat;
181+
ResultRelInfoHolder*rri_holder;/* ResultRelInfo holder */
182+
183+
/* Close partitions and free free conversion-related stuff */
181184
if (close_rels)
182185
{
183-
HASH_SEQ_STATUSstat;
184-
ResultRelInfoHolder*rri_holder;/* ResultRelInfo holder */
185-
186186
hash_seq_init(&stat,parts_storage->result_rels_table);
187187
while ((rri_holder= (ResultRelInfoHolder*)hash_seq_search(&stat))!=NULL)
188188
{
@@ -191,14 +191,31 @@ fini_result_parts_storage(ResultPartsStorage *parts_storage, bool close_rels)
191191
heap_close(rri_holder->result_rel_info->ri_RelationDesc,
192192
parts_storage->heap_close_lock_mode);
193193

194-
/* Drop TupleConversionMap as well as TupleDescs */
195-
if (rri_holder->tuple_map)
196-
{
197-
FreeTupleDesc(rri_holder->tuple_map->indesc);
198-
FreeTupleDesc(rri_holder->tuple_map->outdesc);
194+
/* Skip if there's no map */
195+
if (!rri_holder->tuple_map)
196+
continue;
199197

200-
free_conversion_map(rri_holder->tuple_map);
201-
}
198+
FreeTupleDesc(rri_holder->tuple_map->indesc);
199+
FreeTupleDesc(rri_holder->tuple_map->outdesc);
200+
201+
free_conversion_map(rri_holder->tuple_map);
202+
}
203+
}
204+
205+
/* Else just free conversion-related stuff */
206+
else
207+
{
208+
hash_seq_init(&stat,parts_storage->result_rels_table);
209+
while ((rri_holder= (ResultRelInfoHolder*)hash_seq_search(&stat))!=NULL)
210+
{
211+
/* Skip if there's no map */
212+
if (!rri_holder->tuple_map)
213+
continue;
214+
215+
FreeTupleDesc(rri_holder->tuple_map->indesc);
216+
FreeTupleDesc(rri_holder->tuple_map->outdesc);
217+
218+
free_conversion_map(rri_holder->tuple_map);
202219
}
203220
}
204221

‎src/utility_stmt_hooking.c‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
533533
Oidtuple_oid=InvalidOid;
534534

535535
constPartRelationInfo*prel;
536-
ResultRelInfoHolder*rri_holder_child;
536+
ResultRelInfoHolder*rri_holder;
537537
ResultRelInfo*child_result_rel;
538538

539539
CHECK_FOR_INTERRUPTS();
@@ -553,14 +553,26 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
553553
elog(ERROR,ERR_PART_ATTR_NULL);
554554

555555
/* Search for a matching partition */
556-
rri_holder_child=select_partition_for_insert(prel,&parts_storage,
557-
values[prel->attnum-1],
558-
prel->atttype,estate);
559-
child_result_rel=rri_holder_child->result_rel_info;
556+
rri_holder=select_partition_for_insert(prel,&parts_storage,
557+
values[prel->attnum-1],
558+
prel->atttype,estate);
559+
child_result_rel=rri_holder->result_rel_info;
560560
estate->es_result_relation_info=child_result_rel;
561561

562562
/* And now we can form the input tuple. */
563563
tuple=heap_form_tuple(tupDesc,values,nulls);
564+
565+
/* If there's a transform map, rebuild the tuple */
566+
if (rri_holder->tuple_map)
567+
{
568+
HeapTupletuple_old;
569+
570+
/* TODO: use 'tuple_map' directly instead of do_convert_tuple() */
571+
tuple_old=tuple;
572+
tuple=do_convert_tuple(tuple,rri_holder->tuple_map);
573+
heap_freetuple(tuple_old);
574+
}
575+
564576
if (tuple_oid!=InvalidOid)
565577
HeapTupleSetOid(tuple,tuple_oid);
566578

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp