postgres=# select * from projects where slug = 'partial-matview-refresh';

Partial materialized-view refresh

Inspired by the October 29 Hacking Postgres session, viewer Adam Brusselback implemented WHERE support for targeted REFRESH MATERIALIZED VIEW and has continued revising it through review.

current state

needs review

blocker: The current patch has acknowledged privilege-escalation and error-cleanup bugs; the next revision has not been posted yet.

next

  • Review the security and failure-cleanup fixes in the next version
  • Test concurrency and isolation-level semantics
  • Post review to CommitFest

sessions

1
· 88:38 · youtube ↗

WHERE support for REFRESH MATERIALIZED VIEW

Partial refresh restricted by a predicate, including concurrency semantics.

The session explored adding a WHERE clause to REFRESH MATERIALIZED VIEW so selected rows can be refreshed without rebuilding the whole result. Reading the concurrent-refresh implementation revealed that Postgres creates a temporary difference table, then applies ordinary SQL deletes and inserts through SPI. After experimentally bypassing the normal DML guard, updates to a materialized view and its indexes worked. The group concluded that partial refresh looked technically approachable, while delete semantics, grammar, safety, and consistency still needed design work. Viewer Adam Brusselback explicitly credited this session as the inspiration for the patch he later submitted to pgsql-hackers and CommitFest.

[timecodes · 7]
  1. The case for partial materialized-view refresh
  2. Building a concurrent-refresh test case
  3. Tracing REFRESH through parser and executor code
  4. How concurrent refresh computes and applies a diff
  5. Designing a filtered merge without global deletes
  6. Testing direct DML on a materialized view
  7. Conclusions and remaining partial-refresh semantics
active

direct mapping