Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-warehouse): prune partitions in duckgres status lateral probes (#69092)

Eric Duongde835e0d3263
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/jobs_db.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/jobs_db.py
index f78e52d4efa0..a4cd16e54573 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/jobs_db.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/jobs_db.py
@@ -32,10 +32,17 @@ def _latest_status_lateral(status_table: str, batch_alias: str) -> str:
"""Latest status row for one batch via the (batch_id, created_at DESC, id DESC)
index. Drop-in for a join to the DISTINCT ON v_latest_source_batch* view, but a
per-batch lookup instead of materializing the whole view. SELECTs `_ls.*` so all
- downstream <alias>.<col> references (job_state, created_at, attempt, batch_id) work."""
+ downstream <alias>.<col> references (job_state, created_at, attempt, batch_id) work.
+
+ The created_at bound exists for partition pruning, mirroring the delta queue's
+ `latest_status_lateral`: both status tables are range-partitioned by created_at,
+ and without the predicate every probe descends into every partition. A batch's
+ status rows are always written within the queue's retention horizon, so the
+ 2x-retention bound cannot hide a live row."""
return (
f"LATERAL (SELECT _ls.* FROM {status_table} _ls "
f"WHERE _ls.batch_id = {batch_alias}.id "
+ f"AND _ls.created_at > now() - interval '{PARTITION_PRUNING_INTERVAL}' "
f"ORDER BY _ls.created_at DESC, _ls.id DESC LIMIT 1)"
)