Skip to content

Define grace/staleness period for materialized views #15326

@findepi

Description

@findepi

Per @martint comment #15104 (comment)

I'm thinking of syntax like this:

CREATE MATERIALIZED VIEW <name>
    (GRACE PERIOD <interval>)?
    (WHEN STALE (FAIL | REFRESH))?
    AS (<query>)
    (WITH NO DATA)?
  • A materialized view can be in either usable or unusable state.
  • GRACE PERIOD indicates the maximum allowed time since creation or last refresh before the MV is considered unusable. If omitted, the MV will always be considered usable (i.e., infinite grace period)
  • WHEN STALE (FAIL | REFRESH) indicates what to do once the MV is considered unusable. If FAIL, querying the MV will result in a failure indicating the MV is stale. If REFRESH, the query will transparently produce the correct results as if the MV was up to date (either by refreshing the MV before the query runs or by running the underlying query directly as if it were a regular view.
  • WITH NO DATA causes the MV to be created but not populated in the beginning. One open question is whether the MV is considered unusable until the first refresh occurs (explicitly via REFRESH MATERIALIZED VIEW or implicitly if WHEN STALE REFRESH is specified), or whether it's considered within the grace period. In the latter case, the WHEN STALE clause would only make sense when a grace period is specified explicitly (since otherwise, it's infinite), so we could constrain it syntactically just for that scenario.

We don't need to implement all those features up front, but I'd like to have a plausible plan for what the syntax would look like when we get to it.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions