Commit 5457a130 authored by Simon Riggs's avatar Simon Riggs

Reduce scope of changes for COPY FREEZE.

Allow support only for freezing tuples by explicit
command. Previous coding mistakenly extended
slightly beyond what was agreed as correct on -hackers.
So essentially a partial revoke of earlier work,
leaving just the COPY FREEZE command.
parent 3114cb60
......@@ -1875,13 +1875,11 @@ FreeBulkInsertState(BulkInsertState bistate)
* The HEAP_INSERT_SKIP_FSM option is passed directly to
* RelationGetBufferForTuple, which see for more info.
*
* HEAP_INSERT_COMMITTED should only be specified for inserts into
* HEAP_INSERT_FROZEN should only be specified for inserts into
* relfilenodes created during the current subtransaction and when
* there are no prior snapshots or pre-existing portals open.
*
* HEAP_INSERT_FROZEN only has meaning when HEAP_INSERT_COMMITTED is
* also set. This causes rows to be frozen, which is an MVCC violation
* and requires explicit options chosen by user.
* This causes rows to be frozen, which is an MVCC violation and
* requires explicit options chosen by user.
*
* Note that these options will be applied when inserting into the heap's
* TOAST table, too, if the tuple requires any out-of-line data.
......@@ -2086,10 +2084,9 @@ heap_prepare_insert(Relation relation, HeapTuple tup, TransactionId xid,
tup->t_data->t_infomask &= ~(HEAP_XACT_MASK);
tup->t_data->t_infomask2 &= ~(HEAP2_XACT_MASK);
tup->t_data->t_infomask |= HEAP_XMAX_INVALID;
if (options & HEAP_INSERT_COMMITTED)
if (options & HEAP_INSERT_FROZEN)
{
tup->t_data->t_infomask |= HEAP_XMIN_COMMITTED;
if (options & HEAP_INSERT_FROZEN)
HeapTupleHeaderSetXmin(tup->t_data, FrozenTransactionId);
}
else
......
......@@ -1994,15 +1994,12 @@ CopyFrom(CopyState cstate)
* which subtransaction created it is crucial for correctness
* of this optimisation.
*/
if (ThereAreNoPriorRegisteredSnapshots() &&
if (cstate->freeze &&
ThereAreNoPriorRegisteredSnapshots() &&
ThereAreNoReadyPortals() &&
cstate->rel->rd_newRelfilenodeSubid == GetCurrentSubTransactionId())
{
hi_options |= HEAP_INSERT_COMMITTED;
if (cstate->freeze)
hi_options |= HEAP_INSERT_FROZEN;
}
}
if (cstate->freeze && (hi_options & HEAP_INSERT_FROZEN) == 0)
ereport(NOTICE,
......
......@@ -26,8 +26,7 @@
/* "options" flag bits for heap_insert */
#define HEAP_INSERT_SKIP_WAL 0x0001
#define HEAP_INSERT_SKIP_FSM 0x0002
#define HEAP_INSERT_COMMITTED 0x0004
#define HEAP_INSERT_FROZEN 0x0008
#define HEAP_INSERT_FROZEN 0x0004
typedef struct BulkInsertStateData *BulkInsertState;
......
......@@ -260,8 +260,8 @@ TRUNCATE vistest;
COPY vistest FROM stdin CSV;
SELECT * FROM vistest;
a
---
a
----
a1
b
(2 rows)
......@@ -270,19 +270,26 @@ TRUNCATE vistest;
COPY vistest FROM stdin CSV;
SELECT * FROM vistest;
a
---
d
----
d1
e
(2 rows)
COMMIT;
SELECT * FROM vistest;
a
----
d1
e
(2 rows)
BEGIN;
TRUNCATE vistest;
COPY vistest FROM stdin CSV FREEZE;
SELECT * FROM vistest;
a
---
a
----
a2
b
(2 rows)
......@@ -291,12 +298,19 @@ TRUNCATE vistest;
COPY vistest FROM stdin CSV FREEZE;
SELECT * FROM vistest;
a
---
d
----
d2
e
(2 rows)
COMMIT;
SELECT * FROM vistest;
a
----
d2
e
(2 rows)
BEGIN;
TRUNCATE vistest;
COPY vistest FROM stdin CSV FREEZE;
......@@ -320,11 +334,11 @@ COPY vistest FROM stdin CSV FREEZE;
NOTICE: FREEZE option specified but pre-conditions not met
SELECT * FROM vistest;
a
---
----
p
g
z
d
d3
e
(5 rows)
......@@ -332,10 +346,10 @@ COMMIT;
CREATE FUNCTION truncate_in_subxact() RETURNS VOID AS
$$
BEGIN
SELECT * FROM nonexistent;
TRUNCATE vistest;
EXCEPTION
WHEN OTHERS THEN
TRUNCATE vistest;
INSERT INTO vistest VALUES ('subxact failure');
END;
$$ language plpgsql;
BEGIN;
......@@ -349,16 +363,16 @@ SELECT truncate_in_subxact();
COPY vistest FROM stdin CSV FREEZE;
SELECT * FROM vistest;
a
---
d
----
d4
e
(2 rows)
COMMIT;
SELECT * FROM vistest;
a
---
d
----
d4
e
(2 rows)
......
......@@ -183,34 +183,37 @@ CREATE TABLE vistest (LIKE testeoc);
BEGIN;
TRUNCATE vistest;
COPY vistest FROM stdin CSV;
a
a1
b
\.
SELECT * FROM vistest;
SAVEPOINT s1;
TRUNCATE vistest;
COPY vistest FROM stdin CSV;
d
d1
e
\.
SELECT * FROM vistest;
COMMIT;
SELECT * FROM vistest;
BEGIN;
TRUNCATE vistest;
COPY vistest FROM stdin CSV FREEZE;
a
a2
b
\.
SELECT * FROM vistest;
SAVEPOINT s1;
TRUNCATE vistest;
COPY vistest FROM stdin CSV FREEZE;
d
d2
e
\.
SELECT * FROM vistest;
COMMIT;
SELECT * FROM vistest;
BEGIN;
TRUNCATE vistest;
COPY vistest FROM stdin CSV FREEZE;
......@@ -230,7 +233,7 @@ SAVEPOINT s1;
TRUNCATE vistest;
ROLLBACK TO SAVEPOINT s1;
COPY vistest FROM stdin CSV FREEZE;
d
d3
e
\.
SELECT * FROM vistest;
......@@ -238,17 +241,17 @@ COMMIT;
CREATE FUNCTION truncate_in_subxact() RETURNS VOID AS
$$
BEGIN
SELECT * FROM nonexistent;
TRUNCATE vistest;
EXCEPTION
WHEN OTHERS THEN
TRUNCATE vistest;
INSERT INTO vistest VALUES ('subxact failure');
END;
$$ language plpgsql;
BEGIN;
INSERT INTO vistest VALUES ('z');
SELECT truncate_in_subxact();
COPY vistest FROM stdin CSV FREEZE;
d
d4
e
\.
SELECT * FROM vistest;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment