File tree 5 files changed +72
-1
lines changed
5 files changed +72
-1
lines changed Original file line number Diff line number Diff line change @@ -7883,6 +7883,22 @@ drop trigger rem2_trig_row_before on rem2;
7883
7883
drop trigger rem2_trig_row_after on rem2;
7884
7884
drop trigger loc2_trig_row_before_insert on loc2;
7885
7885
delete from rem2;
7886
+ -- test COPY FROM with foreign table created in the same transaction
7887
+ create table loc3 (f1 int, f2 text);
7888
+ begin;
7889
+ create foreign table rem3 (f1 int, f2 text)
7890
+ server loopback options(table_name 'loc3');
7891
+ copy rem3 from stdin;
7892
+ commit;
7893
+ select * from rem3;
7894
+ f1 | f2
7895
+ ----+-----
7896
+ 1 | foo
7897
+ 2 | bar
7898
+ (2 rows)
7899
+
7900
+ drop foreign table rem3;
7901
+ drop table loc3;
7886
7902
-- ===================================================================
7887
7903
-- test IMPORT FOREIGN SCHEMA
7888
7904
-- ===================================================================
Original file line number Diff line number Diff line change @@ -2085,6 +2085,20 @@ drop trigger loc2_trig_row_before_insert on loc2;
2085
2085
2086
2086
delete from rem2;
2087
2087
2088
+ -- test COPY FROM with foreign table created in the same transaction
2089
+ create table loc3 (f1 int , f2 text );
2090
+ begin ;
2091
+ create foreign table rem3 (f1 int , f2 text )
2092
+ server loopback options(table_name ' loc3' );
2093
+ copy rem3 from stdin;
2094
+ 1 foo
2095
+ 2 bar
2096
+ \.
2097
+ commit ;
2098
+ select * from rem3;
2099
+ drop foreign table rem3;
2100
+ drop table loc3;
2101
+
2088
2102
-- ===================================================================
2089
2103
-- test IMPORT FOREIGN SCHEMA
2090
2104
-- ===================================================================
Original file line number Diff line number Diff line change @@ -2423,10 +2423,17 @@ CopyFrom(CopyState cstate)
2423
2423
* possible to improve on this, but it does mean maintaining heap insert
2424
2424
* option flags per partition and setting them when we first open the
2425
2425
* partition.
2426
+ *
2427
+ * This optimization is not supported for relation types which do not
2428
+ * have any physical storage, with foreign tables and views using
2429
+ * INSTEAD OF triggers entering in this category. Partitioned tables
2430
+ * are not supported as per the description above.
2426
2431
*----------
2427
2432
*/
2428
2433
/* createSubid is creation check, newRelfilenodeSubid is truncation check */
2429
- if (cstate -> rel -> rd_rel -> relkind != RELKIND_PARTITIONED_TABLE &&
2434
+ if (cstate -> rel -> rd_rel -> relkind != RELKIND_FOREIGN_TABLE &&
2435
+ cstate -> rel -> rd_rel -> relkind != RELKIND_PARTITIONED_TABLE &&
2436
+ cstate -> rel -> rd_rel -> relkind != RELKIND_VIEW &&
2430
2437
(cstate -> rel -> rd_createSubid != InvalidSubTransactionId ||
2431
2438
cstate -> rel -> rd_newRelfilenodeSubid != InvalidSubTransactionId ))
2432
2439
{
Original file line number Diff line number Diff line change @@ -557,6 +557,23 @@ SELECT * FROM instead_of_insert_tbl;
557
557
1 | test1
558
558
(1 row)
559
559
560
+ -- Test of COPY optimization with view using INSTEAD OF INSERT
561
+ -- trigger when relation is created in the same transaction as
562
+ -- when COPY is executed.
563
+ BEGIN;
564
+ CREATE VIEW instead_of_insert_tbl_view_2 as select ''::text as str;
565
+ CREATE TRIGGER trig_instead_of_insert_tbl_view_2
566
+ INSTEAD OF INSERT ON instead_of_insert_tbl_view_2
567
+ FOR EACH ROW EXECUTE PROCEDURE fun_instead_of_insert_tbl();
568
+ COPY instead_of_insert_tbl_view_2 FROM stdin;
569
+ SELECT * FROM instead_of_insert_tbl;
570
+ id | name
571
+ ----+-------
572
+ 1 | test1
573
+ 2 | test1
574
+ (2 rows)
575
+
576
+ COMMIT;
560
577
-- clean up
561
578
DROP TABLE forcetest;
562
579
DROP TABLE vistest;
@@ -569,4 +586,5 @@ DROP FUNCTION fn_x_before();
569
586
DROP FUNCTION fn_x_after();
570
587
DROP TABLE instead_of_insert_tbl;
571
588
DROP VIEW instead_of_insert_tbl_view;
589
+ DROP VIEW instead_of_insert_tbl_view_2;
572
590
DROP FUNCTION fun_instead_of_insert_tbl();
Original file line number Diff line number Diff line change @@ -411,6 +411,21 @@ test1
411
411
412
412
SELECT * FROM instead_of_insert_tbl;
413
413
414
+ -- Test of COPY optimization with view using INSTEAD OF INSERT
415
+ -- trigger when relation is created in the same transaction as
416
+ -- when COPY is executed.
417
+ BEGIN ;
418
+ CREATE VIEW instead_of_insert_tbl_view_2 as select ' ' ::text as str;
419
+ CREATE TRIGGER trig_instead_of_insert_tbl_view_2
420
+ INSTEAD OF INSERT ON instead_of_insert_tbl_view_2
421
+ FOR EACH ROW EXECUTE PROCEDURE fun_instead_of_insert_tbl();
422
+
423
+ COPY instead_of_insert_tbl_view_2 FROM stdin;
424
+ test1
425
+ \.
426
+
427
+ SELECT * FROM instead_of_insert_tbl;
428
+ COMMIT ;
414
429
415
430
-- clean up
416
431
DROP TABLE forcetest;
@@ -424,4 +439,5 @@ DROP FUNCTION fn_x_before();
424
439
DROP FUNCTION fn_x_after();
425
440
DROP TABLE instead_of_insert_tbl;
426
441
DROP VIEW instead_of_insert_tbl_view;
442
+ DROP VIEW instead_of_insert_tbl_view_2;
427
443
DROP FUNCTION fun_instead_of_insert_tbl();
You can’t perform that action at this time.
0 commit comments