Skip to content

Commit d16e1ac

Browse files
BFD-4833: Restructure phase 1 prune query (#3232)
1 parent 63241b6 commit d16e1ac

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

apps/bfd-pipeline-idr/model/base_model.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -850,18 +850,22 @@ def stale_phase_1_claims_query(
850850
cutoff_date: datetime,
851851
) -> tuple[str, tuple[datetime, datetime]]:
852852
return (
853-
f"""
853+
f"""
854+
WITH claims AS (
855+
SELECT clm.clm_uniq_id
856+
FROM {header_table} clm
857+
WHERE clm.clm_type_cd BETWEEN {PHASE_1_SS_MIN} AND {PHASE_1_SS_MAX}
858+
AND clm.clm_src_id IN ('{FISS_CLM_SOURCE}', '{MCS_CLM_SOURCE}', '{VMS_CLM_SOURCE}')
859+
AND clm.bfd_updated_ts < %s
860+
ORDER BY clm.bfd_updated_ts, clm.clm_uniq_id
861+
)
854862
SELECT clm.clm_uniq_id
855-
FROM {header_table} clm
856-
WHERE clm.clm_type_cd BETWEEN {PHASE_1_SS_MIN} AND {PHASE_1_SS_MAX}
857-
AND clm.clm_src_id IN ('{FISS_CLM_SOURCE}', '{MCS_CLM_SOURCE}', '{VMS_CLM_SOURCE}')
858-
AND clm.bfd_updated_ts < %s
859-
AND NOT EXISTS (
863+
FROM claims clm
864+
WHERE NOT EXISTS (
860865
SELECT 1 FROM {item_table} item
861866
WHERE clm.clm_uniq_id = item.clm_uniq_id
862867
AND item.bfd_updated_ts >= %s
863868
)
864-
ORDER BY clm.clm_uniq_id
865869
LIMIT {PHASE_1_PRUNE_BATCH_LIMIT}
866870
""",
867871
(cutoff_date, cutoff_date),

0 commit comments

Comments
 (0)