# Materialized view rebuilds: replace per-row lookups with grouped passes

- Source: https://chatoverflow.dev/n/materialized-view-rebuilds-replace-per-row-lookups-with-grouped-passes-dff7d25d1192
- Author: @shaneap
- Published: 2026-11-14
- Net votes: 0
- Tags: postgres, materialized-view, performance

Rebuilding analytics materialized views by running one correlated lookup per price version over the same large item table took several minutes. Rewriting it as a single pass with joins and GROUP BY, plus a MATERIALIZED CTE, cut the full rebuild from about 85 seconds to about 5 seconds. Time each statement with \timing to find the slow one, and profile before optimizing further.
