summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Kreen2007-04-05 09:16:30 +0000
committerMarko Kreen2007-04-05 09:16:30 +0000
commit823f1716466bdf9c2b1fe68bb4f73a6e4d3bc267 (patch)
treee6e03de9e487c98897f86c17f829bb3824df88fc
parent2cfcb93735bdb5b966b76c025d0eb988c87ae7fa (diff)
add algorithm description
-rw-r--r--sql/pgq/functions/pgq.batch_event_sql.sql33
1 files changed, 30 insertions, 3 deletions
diff --git a/sql/pgq/functions/pgq.batch_event_sql.sql b/sql/pgq/functions/pgq.batch_event_sql.sql
index 825de5b6..2c0588fe 100644
--- a/sql/pgq/functions/pgq.batch_event_sql.sql
+++ b/sql/pgq/functions/pgq.batch_event_sql.sql
@@ -2,13 +2,40 @@ create or replace function pgq.batch_event_sql(x_batch_id bigint)
returns text as $$
-- ----------------------------------------------------------------------
-- Function: pgq.batch_event_sql(1)
--- Creates SELECT statement that fetches events for this batch.
+-- Creates SELECT statement that fetches events for this batch.
--
-- Parameters:
--- x_batch_id - ID of a active batch.
+-- x_batch_id - ID of a active batch.
--
-- Returns:
--- SQL statement
+-- SQL statement.
+-- ----------------------------------------------------------------------
+
+-- ----------------------------------------------------------------------
+-- Algorithm description:
+-- Given 2 snapshots, sn1 and sn2 with sn1 having xmin1, xmax1
+-- and sn2 having xmin2, xmax2 create expression that filters
+-- right txid's from event table.
+--
+-- Simplest solution would be
+-- > WHERE ev_txid >= xmin1 AND ev_txid <= xmax2
+-- > AND NOT txid_in_snapshot(ev_txid, sn1)
+-- > AND txid_in_snapshot(ev_txid, sn2)
+--
+-- The simple solution has a problem with long transactions (xmin1 very low).
+-- All the batches that happen when the long tx is active will need
+-- to scan all events in that range. Here is 2 optimizations used:
+--
+-- 1) Use [xmax1..xmax2] for range scan. That limits the range to
+-- txids that actually happened between two snapshots. For txids
+-- in the range [xmin1..xmax1] look which ones were actually
+-- committed between snapshots and search for them using exact
+-- values using IN (..) list.
+--
+-- 2) As most TX are short, there could be lot of them that were
+-- just below xmax1, but were committed before xmax2. So look
+-- if there are ID's near xmax1 and lower the range to include
+-- them, thus decresing size of IN (..) list.
-- ----------------------------------------------------------------------
declare
rec record;