]> granicus.if.org Git - postgresql/commitdiff
Optimize COPY FREEZE with CREATE TABLE also.
authorSimon Riggs <simon@2ndQuadrant.com>
Fri, 7 Dec 2012 13:26:52 +0000 (13:26 +0000)
committerSimon Riggs <simon@2ndQuadrant.com>
Fri, 7 Dec 2012 13:26:52 +0000 (13:26 +0000)
Jeff Davis, additional test by me

src/backend/commands/copy.c
src/test/regress/expected/copy2.out
src/test/regress/sql/copy2.sql

index c4104e4d9d52115034ede98ca9edb6664f56bee8..8200d98139933a0f1cb4a15a239bdf86a03984e2 100644 (file)
@@ -2002,7 +2002,8 @@ CopyFrom(CopyState cstate)
                if (cstate->freeze &&
                        ThereAreNoPriorRegisteredSnapshots() &&
                        ThereAreNoReadyPortals() &&
-                       cstate->rel->rd_newRelfilenodeSubid == GetCurrentSubTransactionId())
+                       (cstate->rel->rd_newRelfilenodeSubid == GetCurrentSubTransactionId() ||
+                        cstate->rel->rd_createSubid == GetCurrentSubTransactionId()))
                        hi_options |= HEAP_INSERT_FROZEN;
        }
 
index 7a9e546aad6d495395d0114a34015e4d1b5ceb88..604c27a2f2fa89dd38dcd13ad6cd0c3bc4a5e717 100644 (file)
@@ -254,7 +254,17 @@ SELECT * FROM testnull;
     | 
 (4 rows)
 
+BEGIN;
 CREATE TABLE vistest (LIKE testeoc);
+COPY vistest FROM stdin CSV;
+COMMIT;
+SELECT xmax, * FROM vistest;
+ xmax | a  
+------+----
+    0 | a0
+    0 | b
+(2 rows)
+
 BEGIN;
 TRUNCATE vistest;
 COPY vistest FROM stdin CSV;
@@ -324,14 +334,12 @@ SELECT * FROM vistest;
 COMMIT;
 TRUNCATE vistest;
 COPY vistest FROM stdin CSV FREEZE;
-NOTICE:  FREEZE option specified but pre-conditions not met
 BEGIN;
 INSERT INTO vistest VALUES ('z');
 SAVEPOINT s1;
 TRUNCATE vistest;
 ROLLBACK TO SAVEPOINT s1;
 COPY vistest FROM stdin CSV FREEZE;
-NOTICE:  FREEZE option specified but pre-conditions not met
 SELECT * FROM vistest;
  a  
 ----
index fbaa433be4e873e3c25c9dcae2bcd7967c75dab9..55568e68e406b30797f91c21c924ee967b3e6c64 100644 (file)
@@ -178,8 +178,14 @@ COPY testnull FROM stdin WITH NULL AS E'\\0';
 
 SELECT * FROM testnull;
 
-
+BEGIN;
 CREATE TABLE vistest (LIKE testeoc);
+COPY vistest FROM stdin CSV;
+a0
+b
+\.
+COMMIT;
+SELECT * FROM vistest;
 BEGIN;
 TRUNCATE vistest;
 COPY vistest FROM stdin CSV;