From 1f023f929702efc9fd4230267b0f0e8d72ba5067 Mon Sep 17 00:00:00 2001 From: Simon Riggs Date: Fri, 7 Dec 2012 13:26:52 +0000 Subject: [PATCH] Optimize COPY FREEZE with CREATE TABLE also. Jeff Davis, additional test by me --- src/backend/commands/copy.c | 3 ++- src/test/regress/expected/copy2.out | 12 ++++++++++-- src/test/regress/sql/copy2.sql | 8 +++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index c4104e4d9d..8200d98139 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -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; } diff --git a/src/test/regress/expected/copy2.out b/src/test/regress/expected/copy2.out index 7a9e546aad..604c27a2f2 100644 --- a/src/test/regress/expected/copy2.out +++ b/src/test/regress/expected/copy2.out @@ -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 ---- diff --git a/src/test/regress/sql/copy2.sql b/src/test/regress/sql/copy2.sql index fbaa433be4..55568e68e4 100644 --- a/src/test/regress/sql/copy2.sql +++ b/src/test/regress/sql/copy2.sql @@ -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; -- 2.40.0