mv_rewrite
pg_fdw_mv_rewrite · Query rewriting extension that transparently rewrites queries to use lower-cost materialized views.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100374 | mv_rewrite | pg_fdw_mv_rewrite | 0.6.2 | FEAT | Unknown | C |
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
- Pinned upstream README
- Version 0.6.2 installation SQL
- Pinned planner-hook implementation
- Pinned extension entry point
mv_rewrite version 0.6.2 is an experimental planner extension that considers registered materialized views as alternative paths. When it finds a semantically usable view with a lower estimated cost, EXPLAIN shows a Custom Scan (MVRewriteScan) and the query reads the materialized view transparently.
Register a materialized view
The install script changes the current database’s session_preload_libraries setting to a versioned module name and loads it in the installing session. New sessions inherit the database setting. This persistent database-level side effect should be reviewed before installation.
Correctness and support boundary
Upstream explicitly says the code is not production ready. It considers selected GROUP BY aggregates, DISTINCT, ordering, simple SELECTs, joins, WHERE, and HAVING shapes; recursive queries and lateral joins are not properly supported. Planner matching is costly, so the extension provides a minimum-cost threshold, an enabled-table list, progress logging, and a global enable switch.
Registration does not refresh a materialized view. A stale view can therefore yield stale rewritten results even when matching is otherwise correct. Establish refresh and dependency procedures and compare plans and results with rewriting disabled. The source targets old PostgreSQL planner internals and has not changed since 2019. Test every query family, extension interaction, and PostgreSQL major version in isolation, and retain a reliable way to remove the database preload setting.