File tree 5 files changed +70
-1
lines changed
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;
7981
7981
drop trigger rem2_trig_row_after on rem2;
7982
7982
drop trigger loc2_trig_row_before_insert on loc2;
7983
7983
delete 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;
7984
8000
-- ===================================================================
7985
8001
-- test IMPORT FOREIGN SCHEMA
7986
8002
-- ===================================================================
Original file line number Diff line number Diff line change @@ -2124,6 +2124,20 @@ drop trigger loc2_trig_row_before_insert on loc2;
2124
2124
2125
2125
delete from rem2;
2126
2126
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
+
2127
2141
-- ===================================================================
2128
2142
-- test IMPORT FOREIGN SCHEMA
2129
2143
-- ===================================================================
Original file line number Diff line number Diff line change @@ -2397,10 +2397,15 @@ CopyFrom(CopyState cstate)
2397
2397
* possible to improve on this, but it does mean maintaining heap insert
2398
2398
* option flags per partition and setting them when we first open the
2399
2399
* 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.
2400
2405
*----------
2401
2406
*/
2402
2407
/* 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 ) &&
2404
2409
(cstate -> rel -> rd_createSubid != InvalidSubTransactionId ||
2405
2410
cstate -> rel -> rd_newRelfilenodeSubid != InvalidSubTransactionId ))
2406
2411
{
Original file line number Diff line number Diff line change @@ -545,6 +545,23 @@ SELECT * FROM instead_of_insert_tbl;
545
545
1 | test1
546
546
(1 row)
547
547
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;
548
565
-- clean up
549
566
DROP TABLE forcetest;
550
567
DROP TABLE vistest;
@@ -557,4 +574,5 @@ DROP FUNCTION fn_x_before();
557
574
DROP FUNCTION fn_x_after();
558
575
DROP TABLE instead_of_insert_tbl;
559
576
DROP VIEW instead_of_insert_tbl_view;
577
+ DROP VIEW instead_of_insert_tbl_view_2;
560
578
DROP FUNCTION fun_instead_of_insert_tbl();
Original file line number Diff line number Diff line change @@ -398,6 +398,21 @@ test1
398
398
399
399
SELECT * FROM instead_of_insert_tbl;
400
400
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 ;
401
416
402
417
-- clean up
403
418
DROP TABLE forcetest;
@@ -411,4 +426,5 @@ DROP FUNCTION fn_x_before();
411
426
DROP FUNCTION fn_x_after();
412
427
DROP TABLE instead_of_insert_tbl;
413
428
DROP VIEW instead_of_insert_tbl_view;
429
+ DROP VIEW instead_of_insert_tbl_view_2;
414
430
DROP FUNCTION fun_instead_of_insert_tbl();
You can’t perform that action at this time.
0 commit comments