Commit d77717ba authored by Tom Lane's avatar Tom Lane

Code review for txid patch: add binary I/O functions, avoid dependence

on SerializableSnapshot, minor other cleanup.  Marko Kreen, some further
editorialization by me.
parent 1246fcd0
# $PostgreSQL: pgsql/contrib/txid/Makefile,v 1.2 2007/10/11 19:54:17 tgl Exp $
MODULES = txid MODULES = txid
DATA_built = txid.sql DATA_built = txid.sql
...@@ -5,7 +6,6 @@ DATA = uninstall_txid.sql ...@@ -5,7 +6,6 @@ DATA = uninstall_txid.sql
DOCS = README.txid DOCS = README.txid
REGRESS = txid REGRESS = txid
ifdef USE_PGXS ifdef USE_PGXS
PG_CONFIG = pg_config PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs) PGXS := $(shell $(PG_CONFIG) --pgxs)
...@@ -16,11 +16,3 @@ top_builddir = ../.. ...@@ -16,11 +16,3 @@ top_builddir = ../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk include $(top_srcdir)/contrib/contrib-global.mk
endif endif
test: install
$(MAKE) installcheck || { less regression.diffs; exit 1; }
ack:
cp results/* expected/
txid - export transaction IDs to user level
===========================================
txid - export transaction id's to user level The goal is to make PostgreSQL's internal transaction ID and snapshot
============================================
The goal is to make PostgreSQL internal transaction ID and snapshot
data usable externally. This allows very efficient queue data usable externally. This allows very efficient queue
implementation done inside database. implementation done inside database.
...@@ -32,7 +31,7 @@ txid_snapshot_xmax( snap ) returns int8 ...@@ -32,7 +31,7 @@ txid_snapshot_xmax( snap ) returns int8
txid_snapshot_xip( snap ) setof int8 txid_snapshot_xip( snap ) setof int8
List of in-progress TXID's in snapshot, that are invisible. List of in-progress TXID's in snapshot, that are invisible.
Values are between xmin and xmax. Values are between xmin (inclusive) and xmax (exclusive).
txid_visible_in_snapshot(id, snap) returns bool txid_visible_in_snapshot(id, snap) returns bool
...@@ -73,8 +72,8 @@ fetching possible txids below snap1.xmax explicitly: ...@@ -73,8 +72,8 @@ fetching possible txids below snap1.xmax explicitly:
AND NOT txid_visible_in_snapshot(ev_txid, :snap1) AND NOT txid_visible_in_snapshot(ev_txid, :snap1)
AND txid_visible_in_snapshot(ev_txid, :snap2); AND txid_visible_in_snapshot(ev_txid, :snap2);
Note that although the above queries work, the PostgreSQL fails to Note that although the above queries work, PostgreSQL fails to
plan them correctly. For actual usage the values for txid_snapshot_xmin, plan them efficiently. For actual usage the values for txid_snapshot_xmin,
txid_snapshot_xmax and txid_snapshot_xip should be filled in directly, txid_snapshot_xmax and txid_snapshot_xip should be filled in directly,
only then will they use index. only then will they use index.
...@@ -92,20 +91,16 @@ To see example code for that it's best to see pgq.batch_event_sql() function in ...@@ -92,20 +91,16 @@ To see example code for that it's best to see pgq.batch_event_sql() function in
Dumping and restoring data containing TXIDs. Dumping and restoring data containing TXIDs.
-------------------------------------------- --------------------------------------------
[towrite: reason for epoch increase] 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
You can look at current epoch with query: increase the XID epoch to beyond the largest one in the input data.
SELECT txid_current() >> 32 as epoch;
So new epoch should be: You can look at current epoch with queries such as:
SELECT (txid_current() >> 32) + 1 as newepoch; SELECT MAX(txid) >> 32 as epoch FROM ...;
Epoch can be changed with pg_resetxlog command: Epoch can be changed with pg_resetxlog command:
pg_resetxlog -e NEWEPOCH DATADIR pg_resetxlog -e NEWEPOCH DATADIR
Database needs to be shut down for that moment. Database needs to be shut down for that moment.
This diff is collapsed.
...@@ -5,21 +5,38 @@ ...@@ -5,21 +5,38 @@
-- --
-- Copyright (c) 2003-2007, PostgreSQL Global Development Group -- Copyright (c) 2003-2007, PostgreSQL Global Development Group
-- Author: Jan Wieck, Afilias USA INC. -- Author: Jan Wieck, Afilias USA INC.
--
-- 64-bit txids: Marko Kreen, Skype Technologies -- 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 -- A special transaction snapshot data type for faster visibility checks
-- --
CREATE OR REPLACE FUNCTION txid_snapshot_in(cstring) CREATE TYPE txid_snapshot;
CREATE FUNCTION txid_snapshot_in(cstring)
RETURNS txid_snapshot RETURNS txid_snapshot
AS 'MODULE_PATHNAME' LANGUAGE C AS 'MODULE_PATHNAME' LANGUAGE C
IMMUTABLE STRICT; IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION txid_snapshot_out(txid_snapshot) CREATE FUNCTION txid_snapshot_out(txid_snapshot)
RETURNS cstring RETURNS cstring
AS 'MODULE_PATHNAME' LANGUAGE C AS 'MODULE_PATHNAME' LANGUAGE C
IMMUTABLE STRICT; 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 -- The data type itself
...@@ -27,42 +44,44 @@ CREATE OR REPLACE FUNCTION txid_snapshot_out(txid_snapshot) ...@@ -27,42 +44,44 @@ CREATE OR REPLACE FUNCTION txid_snapshot_out(txid_snapshot)
CREATE TYPE txid_snapshot ( CREATE TYPE txid_snapshot (
INPUT = txid_snapshot_in, INPUT = txid_snapshot_in,
OUTPUT = txid_snapshot_out, OUTPUT = txid_snapshot_out,
RECEIVE = txid_snapshot_recv,
SEND = txid_snapshot_send,
INTERNALLENGTH = variable, INTERNALLENGTH = variable,
STORAGE = extended, STORAGE = extended,
ALIGNMENT = double ALIGNMENT = double
); );
CREATE OR REPLACE FUNCTION txid_current() --
-- Functions for txid
--
CREATE FUNCTION txid_current()
RETURNS bigint RETURNS bigint
AS 'MODULE_PATHNAME', 'txid_current' LANGUAGE C AS 'MODULE_PATHNAME', 'txid_current' LANGUAGE C
STABLE; STABLE;
CREATE OR REPLACE FUNCTION txid_current_snapshot() CREATE FUNCTION txid_current_snapshot()
RETURNS txid_snapshot RETURNS txid_snapshot
AS 'MODULE_PATHNAME', 'txid_current_snapshot' LANGUAGE C AS 'MODULE_PATHNAME', 'txid_current_snapshot' LANGUAGE C
STABLE; STABLE;
CREATE OR REPLACE FUNCTION txid_snapshot_xmin(txid_snapshot) CREATE FUNCTION txid_snapshot_xmin(txid_snapshot)
RETURNS bigint RETURNS bigint
AS 'MODULE_PATHNAME', 'txid_snapshot_xmin' LANGUAGE C AS 'MODULE_PATHNAME', 'txid_snapshot_xmin' LANGUAGE C
IMMUTABLE STRICT; IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION txid_snapshot_xmax(txid_snapshot) CREATE FUNCTION txid_snapshot_xmax(txid_snapshot)
RETURNS bigint RETURNS bigint
AS 'MODULE_PATHNAME', 'txid_snapshot_xmax' LANGUAGE C AS 'MODULE_PATHNAME', 'txid_snapshot_xmax' LANGUAGE C
IMMUTABLE STRICT; IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION txid_snapshot_xip(txid_snapshot) CREATE FUNCTION txid_snapshot_xip(txid_snapshot)
RETURNS setof bigint RETURNS setof bigint
AS 'MODULE_PATHNAME', 'txid_snapshot_xip' LANGUAGE C AS 'MODULE_PATHNAME', 'txid_snapshot_xip' LANGUAGE C
IMMUTABLE STRICT; IMMUTABLE STRICT;
CREATE FUNCTION txid_visible_in_snapshot(bigint, txid_snapshot)
--
-- Special comparision functions for visibility checks
--
CREATE OR REPLACE FUNCTION txid_visible_in_snapshot(bigint, txid_snapshot)
RETURNS boolean RETURNS boolean
AS 'MODULE_PATHNAME', 'txid_visible_in_snapshot' LANGUAGE C AS 'MODULE_PATHNAME', 'txid_visible_in_snapshot' LANGUAGE C
IMMUTABLE STRICT; IMMUTABLE STRICT;
COMMIT;
SET search_path = public;
DROP FUNCTION txid_current(); DROP FUNCTION txid_current();
DROP FUNCTION txid_current_snapshot(); DROP FUNCTION txid_current_snapshot();
...@@ -6,10 +6,6 @@ DROP FUNCTION txid_snapshot_xmin(txid_snapshot); ...@@ -6,10 +6,6 @@ DROP FUNCTION txid_snapshot_xmin(txid_snapshot);
DROP FUNCTION txid_snapshot_xmax(txid_snapshot); DROP FUNCTION txid_snapshot_xmax(txid_snapshot);
DROP FUNCTION txid_snapshot_xip(txid_snapshot); DROP FUNCTION txid_snapshot_xip(txid_snapshot);
DROP FUNCTION txid_visible_in_snapshot(bigint, txid_snapshot); DROP FUNCTION txid_visible_in_snapshot(bigint, txid_snapshot);
DROP FUNCTION txid_not_visible_in_snapshot(bigint, txid_snapshot);
DROP TYPE txid_snapshot cascade;
-- need cascade to drop those:
-- DROP FUNCTION txid_snapshot_in(cstring);
-- DROP FUNCTION txid_snapshot_out(txid_snapshot);
DROP TYPE txid_snapshot CASCADE;
-- need cascade to drop the I/O functions
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment