Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
17333b6d
Commit
17333b6d
authored
Oct 13, 2007
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove contrib/txid, in preparation for migrating it into core.
parent
041a8b37
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
1 addition
and
1109 deletions
+1
-1109
contrib/Makefile
contrib/Makefile
+1
-2
contrib/txid/Makefile
contrib/txid/Makefile
+0
-18
contrib/txid/README.txid
contrib/txid/README.txid
+0
-106
contrib/txid/expected/txid.out
contrib/txid/expected/txid.out
+0
-221
contrib/txid/sql/txid.sql
contrib/txid/sql/txid.sql
+0
-61
contrib/txid/txid.c
contrib/txid/txid.c
+0
-603
contrib/txid/txid.sql.in
contrib/txid/txid.sql.in
+0
-87
contrib/txid/uninstall_txid.sql
contrib/txid/uninstall_txid.sql
+0
-11
No files found.
contrib/Makefile
View file @
17333b6d
# $PostgreSQL: pgsql/contrib/Makefile,v 1.
79 2007/10/07 23:32:19 wieck
Exp $
# $PostgreSQL: pgsql/contrib/Makefile,v 1.
80 2007/10/13 22:59:43 tgl
Exp $
subdir
=
contrib
top_builddir
=
..
...
...
@@ -30,7 +30,6 @@ WANTED_DIRS = \
pgstattuple
\
seg
\
spi
\
txid
\
tablefunc
\
vacuumlo
...
...
contrib/txid/Makefile
deleted
100644 → 0
View file @
041a8b37
# $PostgreSQL: pgsql/contrib/txid/Makefile,v 1.2 2007/10/11 19:54:17 tgl Exp $
MODULES
=
txid
DATA_built
=
txid.sql
DATA
=
uninstall_txid.sql
DOCS
=
README.txid
REGRESS
=
txid
ifdef
USE_PGXS
PG_CONFIG
=
pg_config
PGXS
:=
$(
shell
$(PG_CONFIG)
--pgxs
)
include
$(PGXS)
else
subdir
=
contrib/txid
top_builddir
=
../..
include
$(top_builddir)/src/Makefile.global
include
$(top_srcdir)/contrib/contrib-global.mk
endif
contrib/txid/README.txid
deleted
100644 → 0
View file @
041a8b37
txid - export transaction IDs to user level
===========================================
The goal is to make PostgreSQL's internal transaction ID and snapshot
data usable externally. This allows very efficient queue
implementation done inside database.
[towrite: what snapshot means]
The module defines type txid_snapshot and following functions:
txid_current() returns int8
Current transaction ID.
txid_current_snapshot() returns txid_snapshot
Current snapshot.
txid_snapshot_xmin( snap ) returns int8
Smallest TXID in snapshot. TXID's smaller than this
are all visible in snapshot.
txid_snapshot_xmax( snap ) returns int8
Largest TXID in snapshot. TXID's starting from this one are
all invisible in snapshot.
txid_snapshot_xip( snap ) setof int8
List of in-progress TXID's in snapshot, that are invisible.
Values are between xmin (inclusive) and xmax (exclusive).
txid_visible_in_snapshot(id, snap) returns bool
Is TXID visible in snapshot?
Fetching events
---------------
Lets say there is following event table:
CREATE TABLE events (
ev_txid int8 not null default txid_current(),
ev_data text
);
CREATE INDEX ev_txid_idx ON events (ev_txid);
Then event between 2 snapshots snap1 and snap2 can be fetched
with followign query:
SELECT ev_data FROM events
WHERE ev_txid >= txid_snapshot_xmin(:snap1)
AND ev_txid < txid_snapshot_xmax(:snap2)
AND NOT txid_visible_in_snapshot(ev_txid, :snap1)
AND txid_visible_in_snapshot(ev_txid, :snap2);
This is the simplest query but it has problem if there are long
transactions running - the txid_snapshot_xmin(snap1) will stay low
and the range will get very large.
This can be fixed by fetching only snap1.xmax ... snap1.xmax by range and
fetching possible txids below snap1.xmax explicitly:
SELECT ev_data FROM events
WHERE ((ev_txid >= txid_snapshot_xmax(:snap1) AND ev_txid < txid_snapshot_xmax(:snap2))
OR
(ev_txid IN (SELECT * FROM txid_snapshot_xip(:snap1))))
AND NOT txid_visible_in_snapshot(ev_txid, :snap1)
AND txid_visible_in_snapshot(ev_txid, :snap2);
Note that although the above queries work, PostgreSQL fails to
plan them efficiently. For actual usage the values for txid_snapshot_xmin,
txid_snapshot_xmax and txid_snapshot_xip should be filled in directly,
only then will they use index.
There are few more optimizations possible, like:
- Picking out only TXIDs that were actually committed between snap1 and snap2.
- Lowering the range from txid_snapshot_xmax(snap1) to decrease the list if TXIDs to be fetched separately.
To see example code for that it's best to see pgq.batch_event_sql() function in Skytools.
http://pgfoundry.org/projects/skytools/
Dumping and restoring data containing TXIDs.
--------------------------------------------
When reloading TXID data you will typically want to be sure that the current
XID counter is beyond the reloaded data. The easiest way to do this is to
increase the XID epoch to beyond the largest one in the input data.
You can look at current epoch with queries such as:
SELECT MAX(txid) >> 32 as epoch FROM ...;
Epoch can be changed with pg_resetxlog command:
pg_resetxlog -e NEWEPOCH DATADIR
Database needs to be shut down for that moment.
contrib/txid/expected/txid.out
deleted
100644 → 0
View file @
041a8b37
-- init
\set ECHO none
-- i/o
select '12:13:'::txid_snapshot;
txid_snapshot
---------------
12:13:
(1 row)
select '12:13:1,2'::txid_snapshot;
ERROR: invalid input for txid_snapshot: "12:13:1,2"
-- errors
select '31:12:'::txid_snapshot;
ERROR: invalid input for txid_snapshot: "31:12:"
select '0:1:'::txid_snapshot;
ERROR: invalid input for txid_snapshot: "0:1:"
select '12:13:0'::txid_snapshot;
ERROR: invalid input for txid_snapshot: "12:13:0"
select '12:16:14,13'::txid_snapshot;
ERROR: invalid input for txid_snapshot: "12:16:14,13"
select '12:16:14,14'::txid_snapshot;
ERROR: invalid input for txid_snapshot: "12:16:14,14"
create table snapshot_test (
nr integer,
snap txid_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;
snap
-------------------------------------------------------------------------------------------------------------------------------------
12:13:
12:20:13,15,18
100001:100009:100005,100007,100008
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
(4 rows)
select txid_snapshot_xmin(snap),
txid_snapshot_xmax(snap),
txid_snapshot_xip(snap)
from snapshot_test order by nr;
txid_snapshot_xmin | txid_snapshot_xmax | txid_snapshot_xip
--------------------+--------------------+-------------------
12 | 20 | 13
12 | 20 | 15
12 | 20 | 18
100001 | 100009 | 100005
100001 | 100009 | 100007
100001 | 100009 | 100008
100 | 150 | 101
100 | 150 | 102
100 | 150 | 103
100 | 150 | 104
100 | 150 | 105
100 | 150 | 106
100 | 150 | 107
100 | 150 | 108
100 | 150 | 109
100 | 150 | 110
100 | 150 | 111
100 | 150 | 112
100 | 150 | 113
100 | 150 | 114
100 | 150 | 115
100 | 150 | 116
100 | 150 | 117
100 | 150 | 118
100 | 150 | 119
100 | 150 | 120
100 | 150 | 121
100 | 150 | 122
100 | 150 | 123
100 | 150 | 124
100 | 150 | 125
100 | 150 | 126
100 | 150 | 127
100 | 150 | 128
100 | 150 | 129
100 | 150 | 130
100 | 150 | 131
(37 rows)
select id, txid_visible_in_snapshot(id, snap)
from snapshot_test, generate_series(11, 21) id
where nr = 2;
id | txid_visible_in_snapshot
----+--------------------------
11 | t
12 | t
13 | f
14 | t
15 | f
16 | t
17 | t
18 | f
19 | t
20 | f
21 | f
(11 rows)
-- test bsearch
select id, txid_visible_in_snapshot(id, snap)
from snapshot_test, generate_series(90, 160) id
where nr = 4;
id | txid_visible_in_snapshot
-----+--------------------------
90 | t
91 | t
92 | t
93 | t
94 | t
95 | t
96 | t
97 | t
98 | t
99 | t
100 | t
101 | f
102 | f
103 | f
104 | f
105 | f
106 | f
107 | f
108 | f
109 | f
110 | f
111 | f
112 | f
113 | f
114 | f
115 | f
116 | f
117 | f
118 | f
119 | f
120 | f
121 | f
122 | f
123 | f
124 | f
125 | f
126 | f
127 | f
128 | f
129 | f
130 | f
131 | f
132 | t
133 | t
134 | t
135 | t
136 | t
137 | t
138 | t
139 | t
140 | t
141 | t
142 | t
143 | t
144 | t
145 | t
146 | t
147 | t
148 | t
149 | t
150 | f
151 | f
152 | f
153 | f
154 | f
155 | f
156 | f
157 | f
158 | f
159 | f
160 | f
(71 rows)
-- test current values also
select txid_current() >= txid_snapshot_xmin(txid_current_snapshot());
?column?
----------
t
(1 row)
/* due to lazy xid alloc in 8.3 those are different in 8.2 and 8.3
select txid_current() < txid_snapshot_xmax(txid_current_snapshot());
select txid_visible_in_snapshot(txid_current(), txid_current_snapshot());
*/
-- test 64bitness
select txid_snapshot '1000100010001000:1000100010001100:1000100010001012,1000100010001013';
txid_snapshot
---------------------------------------------------------------------
1000100010001000:1000100010001100:1000100010001012,1000100010001013
(1 row)
select txid_visible_in_snapshot('1000100010001012', '1000100010001000:1000100010001100:1000100010001012,1000100010001013');
txid_visible_in_snapshot
--------------------------
f
(1 row)
select txid_visible_in_snapshot('1000100010001015', '1000100010001000:1000100010001100:1000100010001012,1000100010001013');
txid_visible_in_snapshot
--------------------------
t
(1 row)
-- test 64bit overflow
SELECT txid_snapshot '1:9223372036854775807:3';
txid_snapshot
-------------------------
1:9223372036854775807:3
(1 row)
SELECT txid_snapshot '1:9223372036854775808:3';
ERROR: invalid input for txid_snapshot: "1:9223372036854775808:3"
contrib/txid/sql/txid.sql
deleted
100644 → 0
View file @
041a8b37
-- init
\
set
ECHO
none
set
client_min_messages
=
'warning'
;
\
i
txid
.
sql
set
client_min_messages
=
'notice'
;
\
set
ECHO
all
-- i/o
select
'12:13:'
::
txid_snapshot
;
select
'12:13:1,2'
::
txid_snapshot
;
-- errors
select
'31:12:'
::
txid_snapshot
;
select
'0:1:'
::
txid_snapshot
;
select
'12:13:0'
::
txid_snapshot
;
select
'12:16:14,13'
::
txid_snapshot
;
select
'12:16:14,14'
::
txid_snapshot
;
create
table
snapshot_test
(
nr
integer
,
snap
txid_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
txid_snapshot_xmin
(
snap
),
txid_snapshot_xmax
(
snap
),
txid_snapshot_xip
(
snap
)
from
snapshot_test
order
by
nr
;
select
id
,
txid_visible_in_snapshot
(
id
,
snap
)
from
snapshot_test
,
generate_series
(
11
,
21
)
id
where
nr
=
2
;
-- test bsearch
select
id
,
txid_visible_in_snapshot
(
id
,
snap
)
from
snapshot_test
,
generate_series
(
90
,
160
)
id
where
nr
=
4
;
-- test current values also
select
txid_current
()
>=
txid_snapshot_xmin
(
txid_current_snapshot
());
/* due to lazy xid alloc in 8.3 those are different in 8.2 and 8.3
select txid_current() < txid_snapshot_xmax(txid_current_snapshot());
select txid_visible_in_snapshot(txid_current(), txid_current_snapshot());
*/
-- test 64bitness
select
txid_snapshot
'1000100010001000:1000100010001100:1000100010001012,1000100010001013'
;
select
txid_visible_in_snapshot
(
'1000100010001012'
,
'1000100010001000:1000100010001100:1000100010001012,1000100010001013'
);
select
txid_visible_in_snapshot
(
'1000100010001015'
,
'1000100010001000:1000100010001100:1000100010001012,1000100010001013'
);
-- test 64bit overflow
SELECT
txid_snapshot
'1:9223372036854775807:3'
;
SELECT
txid_snapshot
'1:9223372036854775808:3'
;
contrib/txid/txid.c
deleted
100644 → 0
View file @
041a8b37
This diff is collapsed.
Click to expand it.
contrib/txid/txid.sql.in
deleted
100644 → 0
View file @
041a8b37
-- ----------
-- txid.sql
--
-- SQL script for loading the transaction ID compatible datatype
--
-- Copyright (c) 2003-2007, PostgreSQL Global Development Group
-- Author: Jan Wieck, Afilias USA INC.
-- 64-bit txids: Marko Kreen, Skype Technologies
--
-- $PostgreSQL: pgsql/contrib/txid/txid.sql.in,v 1.2 2007/10/11 19:54:17 tgl Exp $
--
-- ----------
-- Adjust this setting to control where the objects get created.
SET search_path = public;
BEGIN;
--
-- A special transaction snapshot data type for faster visibility checks
--
CREATE TYPE txid_snapshot;
CREATE FUNCTION txid_snapshot_in(cstring)
RETURNS txid_snapshot
AS 'MODULE_PATHNAME' LANGUAGE C
IMMUTABLE STRICT;
CREATE FUNCTION txid_snapshot_out(txid_snapshot)
RETURNS cstring
AS 'MODULE_PATHNAME' LANGUAGE C
IMMUTABLE STRICT;
CREATE FUNCTION txid_snapshot_recv(internal)
RETURNS txid_snapshot
AS 'MODULE_PATHNAME' LANGUAGE C
IMMUTABLE STRICT;
CREATE FUNCTION txid_snapshot_send(txid_snapshot)
RETURNS bytea
AS 'MODULE_PATHNAME' LANGUAGE C
IMMUTABLE STRICT;
--
-- The data type itself
--
CREATE TYPE txid_snapshot (
INPUT = txid_snapshot_in,
OUTPUT = txid_snapshot_out,
RECEIVE = txid_snapshot_recv,
SEND = txid_snapshot_send,
INTERNALLENGTH = variable,
STORAGE = extended,
ALIGNMENT = double
);
--
-- Functions for txid
--
CREATE FUNCTION txid_current()
RETURNS bigint
AS 'MODULE_PATHNAME', 'txid_current' LANGUAGE C
STABLE;
CREATE FUNCTION txid_current_snapshot()
RETURNS txid_snapshot
AS 'MODULE_PATHNAME', 'txid_current_snapshot' LANGUAGE C
STABLE;
CREATE FUNCTION txid_snapshot_xmin(txid_snapshot)
RETURNS bigint
AS 'MODULE_PATHNAME', 'txid_snapshot_xmin' LANGUAGE C
IMMUTABLE STRICT;
CREATE FUNCTION txid_snapshot_xmax(txid_snapshot)
RETURNS bigint
AS 'MODULE_PATHNAME', 'txid_snapshot_xmax' LANGUAGE C
IMMUTABLE STRICT;
CREATE FUNCTION txid_snapshot_xip(txid_snapshot)
RETURNS setof bigint
AS 'MODULE_PATHNAME', 'txid_snapshot_xip' LANGUAGE C
IMMUTABLE STRICT;
CREATE FUNCTION txid_visible_in_snapshot(bigint, txid_snapshot)
RETURNS boolean
AS 'MODULE_PATHNAME', 'txid_visible_in_snapshot' LANGUAGE C
IMMUTABLE STRICT;
COMMIT;
contrib/txid/uninstall_txid.sql
deleted
100644 → 0
View file @
041a8b37
SET
search_path
=
public
;
DROP
FUNCTION
txid_current
();
DROP
FUNCTION
txid_current_snapshot
();
DROP
FUNCTION
txid_snapshot_xmin
(
txid_snapshot
);
DROP
FUNCTION
txid_snapshot_xmax
(
txid_snapshot
);
DROP
FUNCTION
txid_snapshot_xip
(
txid_snapshot
);
DROP
FUNCTION
txid_visible_in_snapshot
(
bigint
,
txid_snapshot
);
DROP
TYPE
txid_snapshot
CASCADE
;
-- need cascade to drop the I/O functions
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment