Skip to content

Commit 4c04be9

Browse files
committed
Introduce xid8-based functions to replace txid_XXX.
The txid_XXX family of fmgr functions exposes 64 bit transaction IDs to users as int8. Now that we have an SQL type xid8 for FullTransactionId, define a new set of functions including pg_current_xact_id() and pg_current_snapshot() based on that. Keep the old functions around too, for now. It's a bit sneaky to use the same C functions for both, but since the binary representation is identical except for the signedness of the type, and since older functions are the ones using the wrong signedness, and since we'll presumably drop the older ones after a reasonable period of time, it seems reasonable to switch to FullTransactionId internally and share the code for both. Reviewed-by: Fujii Masao <[email protected]> Reviewed-by: Takao Fujii <[email protected]> Reviewed-by: Yoshikazu Imai <[email protected]> Reviewed-by: Mark Dilger <[email protected]> Discussion: https://postgr.es/m/20190725000636.666m5mad25wfbrri%40alap3.anarazel.de
1 parent aeec457 commit 4c04be9

36 files changed

+871
-355
lines changed

contrib/test_decoding/expected/ddl.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'inc
382382
-- test whether a known, but not yet logged toplevel xact, followed by a
383383
-- subxact commit is handled correctly
384384
BEGIN;
385-
SELECT txid_current() != 0; -- so no fixed xid apears in the outfile
385+
SELECT pg_current_xact_id() != '0'; -- so no fixed xid apears in the outfile
386386
?column?
387387
----------
388388
t

contrib/test_decoding/expected/decoding_in_xact.out

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
SET synchronous_commit = on;
33
-- fail because we're creating a slot while in an xact with xid
44
BEGIN;
5-
SELECT txid_current() = 0;
5+
SELECT pg_current_xact_id() = '0';
66
?column?
77
----------
88
f
@@ -13,7 +13,7 @@ ERROR: cannot create logical replication slot in transaction that has performed
1313
ROLLBACK;
1414
-- fail because we're creating a slot while in a subxact whose topxact has an xid
1515
BEGIN;
16-
SELECT txid_current() = 0;
16+
SELECT pg_current_xact_id() = '0';
1717
?column?
1818
----------
1919
f
@@ -50,7 +50,7 @@ CREATE TABLE nobarf(id serial primary key, data text);
5050
INSERT INTO nobarf(data) VALUES('1');
5151
-- decoding works in transaction with xid
5252
BEGIN;
53-
SELECT txid_current() = 0;
53+
SELECT pg_current_xact_id() = '0';
5454
?column?
5555
----------
5656
f

contrib/test_decoding/expected/oldest_xmin.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Parsed test spec with 2 sessions
22

33
starting permutation: s0_begin s0_getxid s1_begin s1_insert s0_alter s0_commit s0_checkpoint s0_get_changes s0_get_changes s1_commit s0_vacuum s0_get_changes
44
step s0_begin: BEGIN;
5-
step s0_getxid: SELECT txid_current() IS NULL;
5+
step s0_getxid: SELECT pg_current_xact_id() IS NULL;
66
?column?
77

88
f

contrib/test_decoding/expected/ondisk_startup.out

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ Parsed test spec with 3 sessions
22

33
starting permutation: s2b s2txid s1init s3b s3txid s2alter s2c s2b s2txid s3c s2c s1insert s1checkpoint s1start s1insert s1alter s1insert s1start
44
step s2b: BEGIN;
5-
step s2txid: SELECT txid_current() IS NULL;
5+
step s2txid: SELECT pg_current_xact_id() IS NULL;
66
?column?
77

88
f
99
step s1init: SELECT 'init' FROM pg_create_logical_replication_slot('isolation_slot', 'test_decoding'); <waiting ...>
1010
step s3b: BEGIN;
11-
step s3txid: SELECT txid_current() IS NULL;
11+
step s3txid: SELECT pg_current_xact_id() IS NULL;
1212
?column?
1313

1414
f
1515
step s2alter: ALTER TABLE do_write ADD COLUMN addedbys2 int;
1616
step s2c: COMMIT;
1717
step s2b: BEGIN;
18-
step s2txid: SELECT txid_current() IS NULL;
18+
step s2txid: SELECT pg_current_xact_id() IS NULL;
1919
?column?
2020

2121
f

contrib/test_decoding/expected/snapshot_transfer.out

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Parsed test spec with 2 sessions
33
starting permutation: s0_begin s0_begin_sub0 s0_log_assignment s0_sub_get_base_snap s1_produce_new_snap s0_insert s0_end_sub0 s0_commit s0_get_changes
44
step s0_begin: BEGIN;
55
step s0_begin_sub0: SAVEPOINT s0;
6-
step s0_log_assignment: SELECT txid_current() IS NULL;
6+
step s0_log_assignment: SELECT pg_current_xact_id() IS NULL;
77
?column?
88

99
f
@@ -26,7 +26,7 @@ stop
2626
starting permutation: s0_begin s0_begin_sub0 s0_log_assignment s0_begin_sub1 s0_sub_get_base_snap s1_produce_new_snap s0_insert s0_end_sub1 s0_end_sub0 s0_commit s0_get_changes
2727
step s0_begin: BEGIN;
2828
step s0_begin_sub0: SAVEPOINT s0;
29-
step s0_log_assignment: SELECT txid_current() IS NULL;
29+
step s0_log_assignment: SELECT pg_current_xact_id() IS NULL;
3030
?column?
3131

3232
f

contrib/test_decoding/specs/oldest_xmin.spec

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ teardown
1919
session "s0"
2020
setup { SET synchronous_commit=on; }
2121
step "s0_begin" { BEGIN; }
22-
step "s0_getxid" { SELECT txid_current() IS NULL; }
22+
step "s0_getxid" { SELECT pg_current_xact_id() IS NULL; }
2323
step "s0_alter" { ALTER TYPE basket DROP ATTRIBUTE mangos; }
2424
step "s0_commit" { COMMIT; }
2525
step "s0_checkpoint" { CHECKPOINT; }

contrib/test_decoding/specs/ondisk_startup.spec

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ session "s2"
2525
setup { SET synchronous_commit=on; }
2626

2727
step "s2b" { BEGIN; }
28-
step "s2txid" { SELECT txid_current() IS NULL; }
28+
step "s2txid" { SELECT pg_current_xact_id() IS NULL; }
2929
step "s2alter" { ALTER TABLE do_write ADD COLUMN addedbys2 int; }
3030
step "s2c" { COMMIT; }
3131

@@ -34,7 +34,7 @@ session "s3"
3434
setup { SET synchronous_commit=on; }
3535

3636
step "s3b" { BEGIN; }
37-
step "s3txid" { SELECT txid_current() IS NULL; }
37+
step "s3txid" { SELECT pg_current_xact_id() IS NULL; }
3838
step "s3c" { COMMIT; }
3939

4040
# Force usage of ondisk snapshot by starting and not finishing a

contrib/test_decoding/specs/snapshot_transfer.spec

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ session "s0"
2020
setup { SET synchronous_commit=on; }
2121
step "s0_begin" { BEGIN; }
2222
step "s0_begin_sub0" { SAVEPOINT s0; }
23-
step "s0_log_assignment" { SELECT txid_current() IS NULL; }
23+
step "s0_log_assignment" { SELECT pg_current_xact_id() IS NULL; }
2424
step "s0_begin_sub1" { SAVEPOINT s1; }
2525
step "s0_sub_get_base_snap" { INSERT INTO dummy VALUES (0); }
2626
step "s0_insert" { INSERT INTO harvest VALUES (1, 2, 3); }

contrib/test_decoding/sql/ddl.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'inc
220220
-- test whether a known, but not yet logged toplevel xact, followed by a
221221
-- subxact commit is handled correctly
222222
BEGIN;
223-
SELECT txid_current() != 0; -- so no fixed xid apears in the outfile
223+
SELECT pg_current_xact_id() != '0'; -- so no fixed xid apears in the outfile
224224
SAVEPOINT a;
225225
INSERT INTO tr_sub(path) VALUES ('4-top-1-#1');
226226
RELEASE SAVEPOINT a;

contrib/test_decoding/sql/decoding_in_xact.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ SET synchronous_commit = on;
33

44
-- fail because we're creating a slot while in an xact with xid
55
BEGIN;
6-
SELECT txid_current() = 0;
6+
SELECT pg_current_xact_id() = '0';
77
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
88
ROLLBACK;
99

1010
-- fail because we're creating a slot while in a subxact whose topxact has an xid
1111
BEGIN;
12-
SELECT txid_current() = 0;
12+
SELECT pg_current_xact_id() = '0';
1313
SAVEPOINT barf;
1414
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
1515
ROLLBACK TO SAVEPOINT barf;
@@ -29,7 +29,7 @@ INSERT INTO nobarf(data) VALUES('1');
2929

3030
-- decoding works in transaction with xid
3131
BEGIN;
32-
SELECT txid_current() = 0;
32+
SELECT pg_current_xact_id() = '0';
3333
-- don't show yet, haven't committed
3434
INSERT INTO nobarf(data) VALUES('2');
3535
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');

doc/src/sgml/datatype.sgml

+7-1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@
198198
<entry><productname>PostgreSQL</productname> Log Sequence Number</entry>
199199
</row>
200200

201+
<row>
202+
<entry><type>pg_snapshot</type></entry>
203+
<entry></entry>
204+
<entry>user-level transaction ID snapshot</entry>
205+
</row>
206+
201207
<row>
202208
<entry><type>point</type></entry>
203209
<entry></entry>
@@ -279,7 +285,7 @@
279285
<row>
280286
<entry><type>txid_snapshot</type></entry>
281287
<entry></entry>
282-
<entry>user-level transaction ID snapshot</entry>
288+
<entry>user-level transaction ID snapshot (deprecated; see <type>pg_snapshot</type>)</entry>
283289
</row>
284290

285291
<row>

0 commit comments

Comments
 (0)