Commits

Anonymous committed 5457a13

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.

Comments (0)

Files changed (5)

src/backend/access/heap/heapam.c

  * 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.
 	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);
+		HeapTupleHeaderSetXmin(tup->t_data, FrozenTransactionId);
 	}
 	else
 		HeapTupleHeaderSetXmin(tup->t_data, xid);

src/backend/commands/copy.c

 		 * 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;
-		}
+			hi_options |= HEAP_INSERT_FROZEN;
 	}
 
 	if (cstate->freeze && (hi_options & HEAP_INSERT_FROZEN) == 0)

src/include/access/heapam.h

 /* "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;
 

src/test/regress/expected/copy2.out

 TRUNCATE vistest;
 COPY vistest FROM stdin CSV;
 SELECT * FROM vistest;
- a 
----
- a
+ a  
+----
+ a1
  b
 (2 rows)
 
 TRUNCATE vistest;
 COPY vistest FROM stdin CSV;
 SELECT * FROM vistest;
- a 
----
- d
+ a  
+----
+ 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
+ a  
+----
+ a2
  b
 (2 rows)
 
 TRUNCATE vistest;
 COPY vistest FROM stdin CSV FREEZE;
 SELECT * FROM vistest;
- a 
----
- d
+ a  
+----
+ d2
  e
 (2 rows)
 
 COMMIT;
+SELECT * FROM vistest;
+ a  
+----
+ d2
+ e
+(2 rows)
+
 BEGIN;
 TRUNCATE vistest;
 COPY vistest FROM stdin CSV FREEZE;
 COPY vistest FROM stdin CSV FREEZE;
 NOTICE:  FREEZE option specified but pre-conditions not met
 SELECT * FROM vistest;
- a 
----
+ a  
+----
  p
  g
  z
- d
+ d3
  e
 (5 rows)
 
 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;
 
 COPY vistest FROM stdin CSV FREEZE;
 SELECT * FROM vistest;
- a 
----
- d
+ a  
+----
+ d4
  e
 (2 rows)
 
 COMMIT;
 SELECT * FROM vistest;
- a 
----
- d
+ a  
+----
+ d4
  e
 (2 rows)
 

src/test/regress/sql/copy2.sql

 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;
 TRUNCATE vistest;
 ROLLBACK TO SAVEPOINT s1;
 COPY vistest FROM stdin CSV FREEZE;
-d
+d3
 e
 \.
 SELECT * FROM vistest;
 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;