Skip to content

Commit

Permalink
Revert "source-postgres-batch: Fix XID wraparound behavior"
Browse files Browse the repository at this point in the history
This reverts commit e57acbc
and un-fixes #2383

Turns out the particular function we're using here doesn't
work on a standby replica, which is...bad.
  • Loading branch information
willdonnelly committed Feb 28, 2025
1 parent d6cd897 commit ca52be5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
SELECT xmin AS txid, * FROM "test"."foobar"
WHERE xmin::text::bigint >= 3
AND (((txid_current() - xmin::text::bigint)<<32)>>32) >= 0
ORDER BY xmin::text::bigint;
SELECT xmin AS txid, * FROM "test"."foobar" ORDER BY xmin::text::bigint;
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
SELECT xmin AS txid, * FROM "test"."foobar"
WHERE xmin::text::bigint >= 3
AND (((txid_current() - xmin::text::bigint)<<32)>>32) >= 0
AND (((xmin::text::bigint - $1::bigint)<<32)>>32) > 0
WHERE (((xmin::text::bigint - $1::bigint)<<32)>>32) > 0 AND xmin::text::bigint >= 3
ORDER BY (((xmin::text::bigint - $1::bigint)<<32)>>32);
9 changes: 2 additions & 7 deletions source-postgres-batch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,10 @@ func selectQueryTemplate(res *Resource) (string, error) {
// the XID epoch wraps around. If this assumption is violated it would in principle be doable
// to `SELECT txid_current() as polled_txid, ...` and use "polled_txid" as the cursor value.
const tableQueryTemplateXMIN = `{{if .IsFirstQuery -}}
SELECT xmin AS txid, * FROM {{quoteTableName .SchemaName .TableName}}
WHERE xmin::text::bigint >= 3
AND (((txid_current() - xmin::text::bigint)<<32)>>32) >= 0
ORDER BY xmin::text::bigint;
SELECT xmin AS txid, * FROM {{quoteTableName .SchemaName .TableName}} ORDER BY xmin::text::bigint;
{{- else -}}
SELECT xmin AS txid, * FROM {{quoteTableName .SchemaName .TableName}}
WHERE xmin::text::bigint >= 3
AND (((txid_current() - xmin::text::bigint)<<32)>>32) >= 0
AND (((xmin::text::bigint - $1::bigint)<<32)>>32) > 0
WHERE (((xmin::text::bigint - $1::bigint)<<32)>>32) > 0 AND xmin::text::bigint >= 3
ORDER BY (((xmin::text::bigint - $1::bigint)<<32)>>32);
{{- end}}`

Expand Down

0 comments on commit ca52be5

Please sign in to comment.