Skip to content

Commit a532a26

Browse files
author
Alexander Korotkov
committed
Merge branch 'PGPROEE9_6-15-64-xid' into PGPROEE9_6
2 parents 0e24dbf + 8b2162a commit a532a26

File tree

113 files changed

+1524
-941
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+1524
-941
lines changed

contrib/hstore/hstore_io.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ hstore_from_record(PG_FUNCTION_ARGS)
833833
ItemPointerSetInvalid(&(tuple.t_self));
834834
tuple.t_tableOid = InvalidOid;
835835
tuple.t_data = rec;
836+
HeapTupleSetInvalidEpoch(&tuple);
836837

837838
values = (Datum *) palloc(ncolumns * sizeof(Datum));
838839
nulls = (bool *) palloc(ncolumns * sizeof(bool));
@@ -978,6 +979,7 @@ hstore_populate_record(PG_FUNCTION_ARGS)
978979
ItemPointerSetInvalid(&(tuple.t_self));
979980
tuple.t_tableOid = InvalidOid;
980981
tuple.t_data = rec;
982+
HeapTupleSetInvalidEpoch(&tuple);
981983
}
982984

983985
/*

contrib/pageinspect/btreefuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ bt_page_stats(PG_FUNCTION_ARGS)
221221
values[j++] = psprintf("%d", stat.free_size);
222222
values[j++] = psprintf("%d", stat.btpo_prev);
223223
values[j++] = psprintf("%d", stat.btpo_next);
224-
values[j++] = psprintf("%d", (stat.type == 'd') ? stat.btpo.xact : stat.btpo.level);
224+
values[j++] = psprintf(XID_FMT, (stat.type == 'd') ? stat.btpo.xact : stat.btpo.level);
225225
values[j++] = psprintf("%d", stat.btpo_flags);
226226

227227
tuple = BuildTupleFromCStrings(TupleDescGetAttInMetadata(tupleDesc),

contrib/pageinspect/heapfuncs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,19 @@ heap_page_items(PG_FUNCTION_ARGS)
192192
lp_offset == MAXALIGN(lp_offset) &&
193193
lp_offset + lp_len <= raw_page_size)
194194
{
195+
HeapTupleData tup;
195196
HeapTupleHeader tuphdr;
196197
bytea *tuple_data_bytea;
197198
int tuple_data_len;
198199

199200
/* Extract information from the tuple header */
200201

201202
tuphdr = (HeapTupleHeader) PageGetItem(page, id);
203+
tup.t_data = tuphdr;
204+
HeapTupleCopyEpochFromPage(&tup, page);
202205

203-
values[4] = UInt32GetDatum(HeapTupleHeaderGetRawXmin(tuphdr));
204-
values[5] = UInt32GetDatum(HeapTupleHeaderGetRawXmax(tuphdr));
206+
values[4] = TransactionIdGetDatum(HeapTupleGetXmin(&tup));
207+
values[5] = TransactionIdGetDatum(HeapTupleGetRawXmax(&tup));
205208
/* shared with xvac */
206209
values[6] = UInt32GetDatum(HeapTupleHeaderGetRawCommandId(tuphdr));
207210
values[7] = PointerGetDatum(&tuphdr->t_ctid);

contrib/pageinspect/pageinspect--1.5.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ CREATE FUNCTION page_header(IN page bytea,
2828
OUT special smallint,
2929
OUT pagesize smallint,
3030
OUT version smallint,
31+
OUT xid_epoch xid,
32+
OUT multi_epoch xid,
3133
OUT prune_xid xid)
3234
AS 'MODULE_PATHNAME', 'page_header'
3335
LANGUAGE C STRICT PARALLEL SAFE;

contrib/pageinspect/rawpage.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ page_header(PG_FUNCTION_ARGS)
175175

176176
Datum result;
177177
HeapTuple tuple;
178-
Datum values[9];
179-
bool nulls[9];
178+
Datum values[11];
179+
bool nulls[11];
180180

181181
PageHeader page;
182182
XLogRecPtr lsn;
@@ -225,7 +225,9 @@ page_header(PG_FUNCTION_ARGS)
225225
values[5] = UInt16GetDatum(page->pd_special);
226226
values[6] = UInt16GetDatum(PageGetPageSize(page));
227227
values[7] = UInt16GetDatum(PageGetPageLayoutVersion(page));
228-
values[8] = TransactionIdGetDatum(page->pd_prune_xid);
228+
values[8] = TransactionIdGetDatum(page->pd_xid_epoch);
229+
values[9] = TransactionIdGetDatum(page->pd_multi_epoch);
230+
values[10] = TransactionIdGetDatum(page->pd_prune_xid);
229231

230232
/* Build and return the tuple. */
231233

contrib/pg_visibility/pg_visibility.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ tuple_all_visible(HeapTuple tup, TransactionId OldestXmin, Buffer buffer)
741741
* be set here. So just check the xmin.
742742
*/
743743

744-
xmin = HeapTupleHeaderGetXmin(tup->t_data);
744+
xmin = HeapTupleGetXmin(tup);
745745
if (!TransactionIdPrecedes(xmin, OldestXmin))
746746
return false; /* xmin not old enough for all to see */
747747

contrib/pgrowlocks/pgrowlocks.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pgrowlocks(PG_FUNCTION_ARGS)
132132
htsu = HeapTupleSatisfiesUpdate(tuple,
133133
GetCurrentCommandId(false),
134134
scan->rs_cbuf);
135-
xmax = HeapTupleHeaderGetRawXmax(tuple->t_data);
135+
xmax = HeapTupleGetRawXmax(tuple);
136136
infomask = tuple->t_data->t_infomask;
137137

138138
/*
@@ -148,7 +148,7 @@ pgrowlocks(PG_FUNCTION_ARGS)
148148
PointerGetDatum(&tuple->t_self));
149149

150150
values[Atnum_xmax] = palloc(NCHARS * sizeof(char));
151-
snprintf(values[Atnum_xmax], NCHARS, "%d", xmax);
151+
snprintf(values[Atnum_xmax], NCHARS, XID_FMT, xmax);
152152
if (infomask & HEAP_XMAX_IS_MULTI)
153153
{
154154
MultiXactMember *members;
@@ -189,7 +189,7 @@ pgrowlocks(PG_FUNCTION_ARGS)
189189
strcat(values[Atnum_modes], ",");
190190
strcat(values[Atnum_pids], ",");
191191
}
192-
snprintf(buf, NCHARS, "%d", members[j].xid);
192+
snprintf(buf, NCHARS, XID_FMT, members[j].xid);
193193
strcat(values[Atnum_xids], buf);
194194
switch (members[j].status)
195195
{
@@ -230,7 +230,7 @@ pgrowlocks(PG_FUNCTION_ARGS)
230230
values[Atnum_ismulti] = pstrdup("false");
231231

232232
values[Atnum_xids] = palloc(NCHARS * sizeof(char));
233-
snprintf(values[Atnum_xids], NCHARS, "{%d}", xmax);
233+
snprintf(values[Atnum_xids], NCHARS, "{" XID_FMT "}", xmax);
234234

235235
values[Atnum_modes] = palloc(NCHARS);
236236
if (infomask & HEAP_XMAX_LOCK_ONLY)

contrib/pgstattuple/pgstatapprox.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ statapprox_heap(Relation rel, output_type *stat)
148148
tuple.t_data = (HeapTupleHeader) PageGetItem(page, itemid);
149149
tuple.t_len = ItemIdGetLength(itemid);
150150
tuple.t_tableOid = RelationGetRelid(rel);
151+
HeapTupleCopyEpochFromPage(&tuple, page);
151152

152153
/*
153154
* We count live and dead tuples, but we also need to add up

contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,7 +2784,9 @@ UPDATE ft2 SET c2 = c2 + 400, c3 = c3 || '_update7' WHERE c1 % 10 = 7 RETURNING
27842784
Remote SQL: UPDATE "S 1"."T 1" SET c2 = (c2 + 400), c3 = (c3 || '_update7'::text) WHERE ((("C 1" % 10) = 7)) RETURNING "C 1", c2, c3, c4, c5, c6, c7, c8
27852785
(4 rows)
27862786

2787-
UPDATE ft2 SET c2 = c2 + 400, c3 = c3 || '_update7' WHERE c1 % 10 = 7 RETURNING *;
2787+
WITH updated AS (
2788+
UPDATE ft2 SET c2 = c2 + 400, c3 = c3 || '_update7' WHERE c1 % 10 = 7 RETURNING *
2789+
) SELECT * FROM updated ORDER BY c1;
27882790
c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
27892791
------+-----+--------------------+------------------------------+--------------------------+----+------------+-----
27902792
7 | 407 | 00007_update7 | Thu Jan 08 00:00:00 1970 PST | Thu Jan 08 00:00:00 1970 | 7 | 7 | foo
@@ -2927,7 +2929,9 @@ EXPLAIN (verbose, costs off)
29272929
Remote SQL: DELETE FROM "S 1"."T 1" WHERE ((("C 1" % 10) = 5)) RETURNING "C 1", c4
29282930
(4 rows)
29292931

2930-
DELETE FROM ft2 WHERE c1 % 10 = 5 RETURNING c1, c4;
2932+
WITH deleted AS (
2933+
DELETE FROM ft2 WHERE c1 % 10 = 5 RETURNING c1, c4
2934+
) SELECT * FROM deleted ORDER BY c1;
29312935
c1 | c4
29322936
------+------------------------------
29332937
5 | Tue Jan 06 00:00:00 1970 PST
@@ -3953,7 +3957,9 @@ INSERT INTO ft2 (c1,c2,c3,c6) VALUES (1218, 818, 'ggg', '(--;') RETURNING *;
39533957
1218 | 818 | ggg_trig_update | | | (--; | ft2 |
39543958
(1 row)
39553959

3956-
UPDATE ft2 SET c2 = c2 + 600 WHERE c1 % 10 = 8 AND c1 < 1200 RETURNING *;
3960+
WITH updated AS (
3961+
UPDATE ft2 SET c2 = c2 + 600 WHERE c1 % 10 = 8 AND c1 < 1200 RETURNING *
3962+
) SELECT * FROM updated ORDER BY c1;
39573963
c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
39583964
------+-----+------------------------+------------------------------+--------------------------+----+------------+-----
39593965
8 | 608 | 00008_trig_update | Fri Jan 09 00:00:00 1970 PST | Fri Jan 09 00:00:00 1970 | 8 | 8 | foo

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4473,6 +4473,7 @@ make_tuple_from_result_row(PGresult *res,
44734473
*/
44744474
if (ctid)
44754475
tuple->t_self = tuple->t_data->t_ctid = *ctid;
4476+
HeapTupleSetInvalidEpoch(tuple);
44764477

44774478
/*
44784479
* Stomp on the xmin, xmax, and cmin fields from the tuple created by
@@ -4482,8 +4483,8 @@ make_tuple_from_result_row(PGresult *res,
44824483
* assumption. If we don't do this then, for example, the tuple length
44834484
* ends up in the xmin field, which isn't what we want.
44844485
*/
4485-
HeapTupleHeaderSetXmax(tuple->t_data, InvalidTransactionId);
4486-
HeapTupleHeaderSetXmin(tuple->t_data, InvalidTransactionId);
4486+
HeapTupleSetXmax(tuple, InvalidTransactionId);
4487+
HeapTupleSetXmin(tuple, InvalidTransactionId);
44874488
HeapTupleHeaderSetCmin(tuple->t_data, InvalidTransactionId);
44884489

44894490
/* Clean up */

contrib/postgres_fdw/sql/postgres_fdw.sql

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,15 +669,19 @@ UPDATE ft2 SET c2 = c2 + 300, c3 = c3 || '_update3' WHERE c1 % 10 = 3;
669669
UPDATE ft2 SET c2 = c2 + 300, c3 = c3 || '_update3' WHERE c1 % 10 = 3;
670670
EXPLAIN (verbose, costs off)
671671
UPDATE ft2 SET c2 = c2 + 400, c3 = c3 || '_update7' WHERE c1 % 10 = 7 RETURNING *; -- can be pushed down
672-
UPDATE ft2 SET c2 = c2 + 400, c3 = c3 || '_update7' WHERE c1 % 10 = 7 RETURNING *;
672+
WITH updated AS (
673+
UPDATE ft2 SET c2 = c2 + 400, c3 = c3 || '_update7' WHERE c1 % 10 = 7 RETURNING *
674+
) SELECT * FROM updated ORDER BY c1;
673675
EXPLAIN (verbose, costs off)
674676
UPDATE ft2 SET c2 = ft2.c2 + 500, c3 = ft2.c3 || '_update9', c7 = DEFAULT
675677
FROM ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 9; -- can't be pushed down
676678
UPDATE ft2 SET c2 = ft2.c2 + 500, c3 = ft2.c3 || '_update9', c7 = DEFAULT
677679
FROM ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 9;
678680
EXPLAIN (verbose, costs off)
679681
DELETE FROM ft2 WHERE c1 % 10 = 5 RETURNING c1, c4; -- can be pushed down
680-
DELETE FROM ft2 WHERE c1 % 10 = 5 RETURNING c1, c4;
682+
WITH deleted AS (
683+
DELETE FROM ft2 WHERE c1 % 10 = 5 RETURNING c1, c4
684+
) SELECT * FROM deleted ORDER BY c1;
681685
EXPLAIN (verbose, costs off)
682686
DELETE FROM ft2 USING ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 2; -- can't be pushed down
683687
DELETE FROM ft2 USING ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 2;
@@ -704,7 +708,9 @@ CREATE TRIGGER t1_br_insert BEFORE INSERT OR UPDATE
704708

705709
INSERT INTO ft2 (c1,c2,c3) VALUES (1208, 818, 'fff') RETURNING *;
706710
INSERT INTO ft2 (c1,c2,c3,c6) VALUES (1218, 818, 'ggg', '(--;') RETURNING *;
707-
UPDATE ft2 SET c2 = c2 + 600 WHERE c1 % 10 = 8 AND c1 < 1200 RETURNING *;
711+
WITH updated AS (
712+
UPDATE ft2 SET c2 = c2 + 600 WHERE c1 % 10 = 8 AND c1 < 1200 RETURNING *
713+
) SELECT * FROM updated ORDER BY c1;
708714

709715
-- Test errors thrown on remote side during update
710716
ALTER TABLE "S 1"."T 1" ADD CONSTRAINT c2positive CHECK (c2 >= 0);

contrib/test_decoding/test_decoding.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ pg_output_begin(LogicalDecodingContext *ctx, TestDecodingData *data, ReorderBuff
215215
{
216216
OutputPluginPrepareWrite(ctx, last_write);
217217
if (data->include_xids)
218-
appendStringInfo(ctx->out, "BEGIN %u", txn->xid);
218+
appendStringInfo(ctx->out, "BEGIN " XID_FMT, txn->xid);
219219
else
220220
appendStringInfoString(ctx->out, "BEGIN");
221221
OutputPluginWrite(ctx, last_write);
@@ -233,7 +233,7 @@ pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
233233

234234
OutputPluginPrepareWrite(ctx, true);
235235
if (data->include_xids)
236-
appendStringInfo(ctx->out, "COMMIT %u", txn->xid);
236+
appendStringInfo(ctx->out, "COMMIT " XID_FMT, txn->xid);
237237
else
238238
appendStringInfoString(ctx->out, "COMMIT");
239239

src/backend/access/common/heaptuple.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,10 @@ heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
568568
result = ObjectIdGetDatum(HeapTupleGetOid(tup));
569569
break;
570570
case MinTransactionIdAttributeNumber:
571-
result = TransactionIdGetDatum(HeapTupleHeaderGetRawXmin(tup->t_data));
571+
result = TransactionIdGetDatum(HeapTupleGetRawXmin(tup));
572572
break;
573573
case MaxTransactionIdAttributeNumber:
574-
result = TransactionIdGetDatum(HeapTupleHeaderGetRawXmax(tup->t_data));
574+
result = TransactionIdGetDatum(HeapTupleGetRawXmax(tup));
575575
break;
576576
case MinCommandIdAttributeNumber:
577577
case MaxCommandIdAttributeNumber:
@@ -616,6 +616,7 @@ heap_copytuple(HeapTuple tuple)
616616
newTuple->t_len = tuple->t_len;
617617
newTuple->t_self = tuple->t_self;
618618
newTuple->t_tableOid = tuple->t_tableOid;
619+
HeapTupleCopyEpoch(newTuple, tuple);
619620
newTuple->t_data = (HeapTupleHeader) ((char *) newTuple + HEAPTUPLESIZE);
620621
memcpy((char *) newTuple->t_data, (char *) tuple->t_data, tuple->t_len);
621622
return newTuple;
@@ -642,6 +643,7 @@ heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest)
642643
dest->t_len = src->t_len;
643644
dest->t_self = src->t_self;
644645
dest->t_tableOid = src->t_tableOid;
646+
HeapTupleCopyEpoch(dest, src);
645647
dest->t_data = (HeapTupleHeader) palloc(src->t_len);
646648
memcpy((char *) dest->t_data, (char *) src->t_data, src->t_len);
647649
}
@@ -752,6 +754,7 @@ heap_form_tuple(TupleDesc tupleDescriptor,
752754
tuple->t_len = len;
753755
ItemPointerSetInvalid(&(tuple->t_self));
754756
tuple->t_tableOid = InvalidOid;
757+
HeapTupleSetInvalidEpoch(tuple);
755758

756759
HeapTupleHeaderSetDatumLength(td, len);
757760
HeapTupleHeaderSetTypeId(td, tupleDescriptor->tdtypeid);
@@ -840,6 +843,7 @@ heap_modify_tuple(HeapTuple tuple,
840843
newTuple->t_data->t_ctid = tuple->t_data->t_ctid;
841844
newTuple->t_self = tuple->t_self;
842845
newTuple->t_tableOid = tuple->t_tableOid;
846+
HeapTupleCopyEpoch(newTuple, tuple);
843847
if (tupleDesc->tdhasoid)
844848
HeapTupleSetOid(newTuple, HeapTupleGetOid(tuple));
845849

@@ -1438,6 +1442,7 @@ heap_tuple_from_minimal_tuple(MinimalTuple mtup)
14381442
result->t_len = len;
14391443
ItemPointerSetInvalid(&(result->t_self));
14401444
result->t_tableOid = InvalidOid;
1445+
HeapTupleSetInvalidEpoch(result);
14411446
result->t_data = (HeapTupleHeader) ((char *) result + HEAPTUPLESIZE);
14421447
memcpy((char *) result->t_data + MINIMAL_TUPLE_OFFSET, mtup, mtup->t_len);
14431448
memset(result->t_data, 0, offsetof(HeapTupleHeaderData, t_infomask2));

0 commit comments

Comments
 (0)