File tree Expand file tree Collapse file tree 5 files changed +70
-1
lines changed Expand file tree Collapse file tree 5 files changed +70
-1
lines changed Original file line number Diff line number Diff line change @@ -7981,6 +7981,22 @@ drop trigger rem2_trig_row_before on rem2;
79817981drop trigger rem2_trig_row_after on rem2;
79827982drop trigger loc2_trig_row_before_insert on loc2;
79837983delete from rem2;
7984+ -- test COPY FROM with foreign table created in the same transaction
7985+ create table loc3 (f1 int, f2 text);
7986+ begin;
7987+ create foreign table rem3 (f1 int, f2 text)
7988+ server loopback options(table_name 'loc3');
7989+ copy rem3 from stdin;
7990+ commit;
7991+ select * from rem3;
7992+ f1 | f2
7993+ ----+-----
7994+ 1 | foo
7995+ 2 | bar
7996+ (2 rows)
7997+
7998+ drop foreign table rem3;
7999+ drop table loc3;
79848000-- ===================================================================
79858001-- test IMPORT FOREIGN SCHEMA
79868002-- ===================================================================
Original file line number Diff line number Diff line change @@ -2124,6 +2124,20 @@ drop trigger loc2_trig_row_before_insert on loc2;
21242124
21252125delete from rem2;
21262126
2127+ -- test COPY FROM with foreign table created in the same transaction
2128+ create table loc3 (f1 int , f2 text );
2129+ begin ;
2130+ create foreign table rem3 (f1 int , f2 text )
2131+ server loopback options(table_name ' loc3' );
2132+ copy rem3 from stdin;
2133+ 1 foo
2134+ 2 bar
2135+ \.
2136+ commit ;
2137+ select * from rem3;
2138+ drop foreign table rem3;
2139+ drop table loc3;
2140+
21272141-- ===================================================================
21282142-- test IMPORT FOREIGN SCHEMA
21292143-- ===================================================================
Original file line number Diff line number Diff line change @@ -2397,10 +2397,15 @@ CopyFrom(CopyState cstate)
23972397 * possible to improve on this, but it does mean maintaining heap insert
23982398 * option flags per partition and setting them when we first open the
23992399 * partition.
2400+ *
2401+ * This optimization is not supported for relation types which do not
2402+ * have any physical storage, with foreign tables and views using
2403+ * INSTEAD OF triggers entering in this category. Partitioned tables
2404+ * are not supported as per the description above.
24002405 *----------
24012406 */
24022407 /* createSubid is creation check, newRelfilenodeSubid is truncation check */
2403- if (cstate -> rel -> rd_rel -> relkind != RELKIND_PARTITIONED_TABLE &&
2408+ if (RELKIND_CAN_HAVE_STORAGE ( cstate -> rel -> rd_rel -> relkind ) &&
24042409 (cstate -> rel -> rd_createSubid != InvalidSubTransactionId ||
24052410 cstate -> rel -> rd_newRelfilenodeSubid != InvalidSubTransactionId ))
24062411 {
Original file line number Diff line number Diff line change @@ -545,6 +545,23 @@ SELECT * FROM instead_of_insert_tbl;
545545 1 | test1
546546(1 row)
547547
548+ -- Test of COPY optimization with view using INSTEAD OF INSERT
549+ -- trigger when relation is created in the same transaction as
550+ -- when COPY is executed.
551+ BEGIN;
552+ CREATE VIEW instead_of_insert_tbl_view_2 as select ''::text as str;
553+ CREATE TRIGGER trig_instead_of_insert_tbl_view_2
554+ INSTEAD OF INSERT ON instead_of_insert_tbl_view_2
555+ FOR EACH ROW EXECUTE PROCEDURE fun_instead_of_insert_tbl();
556+ COPY instead_of_insert_tbl_view_2 FROM stdin;
557+ SELECT * FROM instead_of_insert_tbl;
558+ id | name
559+ ----+-------
560+ 1 | test1
561+ 2 | test1
562+ (2 rows)
563+
564+ COMMIT;
548565-- clean up
549566DROP TABLE forcetest;
550567DROP TABLE vistest;
@@ -557,4 +574,5 @@ DROP FUNCTION fn_x_before();
557574DROP FUNCTION fn_x_after();
558575DROP TABLE instead_of_insert_tbl;
559576DROP VIEW instead_of_insert_tbl_view;
577+ DROP VIEW instead_of_insert_tbl_view_2;
560578DROP FUNCTION fun_instead_of_insert_tbl();
Original file line number Diff line number Diff line change @@ -398,6 +398,21 @@ test1
398398
399399SELECT * FROM instead_of_insert_tbl;
400400
401+ -- Test of COPY optimization with view using INSTEAD OF INSERT
402+ -- trigger when relation is created in the same transaction as
403+ -- when COPY is executed.
404+ BEGIN ;
405+ CREATE VIEW instead_of_insert_tbl_view_2 as select ' ' ::text as str;
406+ CREATE TRIGGER trig_instead_of_insert_tbl_view_2
407+ INSTEAD OF INSERT ON instead_of_insert_tbl_view_2
408+ FOR EACH ROW EXECUTE PROCEDURE fun_instead_of_insert_tbl();
409+
410+ COPY instead_of_insert_tbl_view_2 FROM stdin;
411+ test1
412+ \.
413+
414+ SELECT * FROM instead_of_insert_tbl;
415+ COMMIT ;
401416
402417-- clean up
403418DROP TABLE forcetest;
@@ -411,4 +426,5 @@ DROP FUNCTION fn_x_before();
411426DROP FUNCTION fn_x_after();
412427DROP TABLE instead_of_insert_tbl;
413428DROP VIEW instead_of_insert_tbl_view;
429+ DROP VIEW instead_of_insert_tbl_view_2;
414430DROP FUNCTION fun_instead_of_insert_tbl();
You can’t perform that action at this time.
0 commit comments