pipekit/config/modules/pm30600.sql
Paul Trowbridge b855ab91d7 Make the three AP history modules incremental
The Accounts Payable group ran ~9.5 min, 83% of it in four full
reloads. The cost is the GPSERVER linked-server hop, not row volume
(pm30200 managed only ~590 rows/sec), so cutting rows crossing the link
is the whole win. Predicates go inside OPENQUERY to push down to the
remote — a 4-part name would drag the table across before filtering.

  pm30200  own DEX_ROW_TS
  pm30600  changed set: parent PM30200
  pm30300  changed set: PM30200 union PM20000

All three key on (vchrnmbr, doctype), verified exactly unique in
PM30200 at 108,803/108,803. Watermark resolves off gp.pm30200 with a
7-day lookback, so run order within the group must stay pm30200 first
and the lookback must exceed the sync interval.

The two-parent union on pm30300 is load-bearing: 38 rows have a parent
only in the open table, and a PM30200-only join would strand them
permanently. pm30600 needs no union (0 orphans, verified).

pm30700 stays full — 213 of its rows have no parent in either table, so
no changed-set join can reach them, and it only costs 13s. pm20100 and
pm00400 stay full because open and index tables delete rows, which a
delete-by-key incremental structurally cannot propagate (cf. icstt).

391s -> 15s. reconcile.py --super-quick reports IN SYNC for all three.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 00:21:59 -04:00

33 lines
904 B
SQL

SELECT * FROM OPENQUERY(GPSERVER, '
SELECT
d.[DOCTYPE] AS doctype,
RTRIM(d.[VCHRNMBR]) AS vchrnmbr,
d.[DSTSQNUM] AS dstsqnum,
d.[CNTRLTYP] AS cntrltyp,
d.[CRDTAMNT] AS crdtamnt,
d.[DEBITAMT] AS debitamt,
d.[DSTINDX] AS dstindx,
d.[DISTTYPE] AS disttype,
d.[CHANGED] AS changed,
RTRIM(d.[USERID]) AS userid,
d.[PSTGSTUS] AS pstgstus,
RTRIM(d.[VENDORID]) AS vendorid,
RTRIM(d.[TRXSORCE]) AS trxsorce,
d.[PSTGDATE] AS pstgdate,
RTRIM(d.[CURNCYID]) AS curncyid,
d.[CURRNIDX] AS currnidx,
d.[ORCRDAMT] AS orcrdamt,
d.[ORDBTAMT] AS ordbtamt,
RTRIM(d.[APTVCHNM]) AS aptvchnm,
d.[APTODCTY] AS aptodcty,
d.[SPCLDIST] AS spcldist,
RTRIM(d.[DistRef]) AS distref,
d.[DEX_ROW_ID] AS dex_row_id
FROM CHG.dbo.PM30600 d
WHERE EXISTS (
SELECT 1 FROM CHG.dbo.PM30200 p
WHERE p.VCHRNMBR = d.VCHRNMBR AND p.DOCTYPE = d.DOCTYPE
AND p.[DEX_ROW_TS] > ''{pm30600_ts}''
)
')