diff options
| author | Thomas Munro | 2020-04-06 23:33:56 +0000 |
|---|---|---|
| committer | Thomas Munro | 2020-04-07 00:04:32 +0000 |
| commit | 4c04be9b05ad2ec5acd27c3417bf075c13cab134 (patch) | |
| tree | a85e0f90b3b5fd059b4155d93f00bf58f54955ca /src/test/regress/sql/xid.sql | |
| parent | aeec457de8a8820368e343e791accffe24dc7198 (diff) | |
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
Diffstat (limited to 'src/test/regress/sql/xid.sql')
| -rw-r--r-- | src/test/regress/sql/xid.sql | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/test/regress/sql/xid.sql b/src/test/regress/sql/xid.sql index a4fbca51766..565714d4620 100644 --- a/src/test/regress/sql/xid.sql +++ b/src/test/regress/sql/xid.sql @@ -46,3 +46,107 @@ create table xid8_t1 (x xid8); create index on xid8_t1 using btree(x); create index on xid8_t1 using hash(x); drop table xid8_t1; + + +-- pg_snapshot data type and related functions + +-- Note: another set of tests similar to this exists in txid.sql, for a limited +-- time (the relevant functions share C code) + +-- i/o +select '12:13:'::pg_snapshot; +select '12:18:14,16'::pg_snapshot; +select '12:16:14,14'::pg_snapshot; + +-- errors +select '31:12:'::pg_snapshot; +select '0:1:'::pg_snapshot; +select '12:13:0'::pg_snapshot; +select '12:16:14,13'::pg_snapshot; + +create temp table snapshot_test ( + nr integer, + snap pg_snapshot +); + +insert into snapshot_test values (1, '12:13:'); +insert into snapshot_test values (2, '12:20:13,15,18'); +insert into snapshot_test values (3, '100001:100009:100005,100007,100008'); +insert into snapshot_test values (4, '100:150:101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131'); +select snap from snapshot_test order by nr; + +select pg_snapshot_xmin(snap), + pg_snapshot_xmax(snap), + pg_snapshot_xip(snap) +from snapshot_test order by nr; + +select id, pg_visible_in_snapshot(id::text::xid8, snap) +from snapshot_test, generate_series(11, 21) id +where nr = 2; + +-- test bsearch +select id, pg_visible_in_snapshot(id::text::xid8, snap) +from snapshot_test, generate_series(90, 160) id +where nr = 4; + +-- test current values also +select pg_current_xact_id() >= pg_snapshot_xmin(pg_current_snapshot()); + +-- we can't assume current is always less than xmax, however + +select pg_visible_in_snapshot(pg_current_xact_id(), pg_current_snapshot()); + +-- test 64bitness + +select pg_snapshot '1000100010001000:1000100010001100:1000100010001012,1000100010001013'; +select pg_visible_in_snapshot('1000100010001012', '1000100010001000:1000100010001100:1000100010001012,1000100010001013'); +select pg_visible_in_snapshot('1000100010001015', '1000100010001000:1000100010001100:1000100010001012,1000100010001013'); + +-- test 64bit overflow +SELECT pg_snapshot '1:9223372036854775807:3'; +SELECT pg_snapshot '1:9223372036854775808:3'; + +-- test pg_current_xact_id_if_assigned +BEGIN; +SELECT pg_current_xact_id_if_assigned() IS NULL; +SELECT pg_current_xact_id() \gset +SELECT pg_current_xact_id_if_assigned() IS NOT DISTINCT FROM xid8 :'pg_current_xact_id'; +COMMIT; + +-- test xid status functions +BEGIN; +SELECT pg_current_xact_id() AS committed \gset +COMMIT; + +BEGIN; +SELECT pg_current_xact_id() AS rolledback \gset +ROLLBACK; + +BEGIN; +SELECT pg_current_xact_id() AS inprogress \gset + +SELECT pg_xact_status(:committed::text::xid8) AS committed; +SELECT pg_xact_status(:rolledback::text::xid8) AS rolledback; +SELECT pg_xact_status(:inprogress::text::xid8) AS inprogress; +SELECT pg_xact_status('1'::xid8); -- BootstrapTransactionId is always committed +SELECT pg_xact_status('2'::xid8); -- FrozenTransactionId is always committed +SELECT pg_xact_status('3'::xid8); -- in regress testing FirstNormalTransactionId will always be behind oldestXmin + +COMMIT; + +BEGIN; +CREATE FUNCTION test_future_xid_status(xid8) +RETURNS void +LANGUAGE plpgsql +AS +$$ +BEGIN + PERFORM pg_xact_status($1); + RAISE EXCEPTION 'didn''t ERROR at xid in the future as expected'; +EXCEPTION + WHEN invalid_parameter_value THEN + RAISE NOTICE 'Got expected error for xid in the future'; +END; +$$; +SELECT test_future_xid_status((:inprogress + 10000)::text::xid8); +ROLLBACK; |
