Skip to content

Commit

Permalink
feat: view vs materialized view
Browse files Browse the repository at this point in the history
  • Loading branch information
fadyat committed Oct 17, 2023
1 parent 0e706ae commit 086a6ff
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions dump/postgres/view.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## `View` vs `Materialized View`

| View | Materialized View |
|--------------------------------------|--------------------------------------------------------------------------|
| A view is a virtual table. | A materialized view is a physical copy of the table, stored on the disk. |
| "Updated" every time it is accessed. | "Updated" only via triggers or refresh command (manually). |
| Slow | Fast, because it is precomputed. |

### Advantages of `View`

- No storage space is required for a view.
- Restrict users from accessing some columns.
- Reducing complexity of queries.

View = alias for user query.

### Advantages of `Materialized View`

- Faster than views, because it is precomputed.
- Can be indexed.

Materialized view = cached query result.

### Resources

- https://www.timescale.com/blog/how-postgresql-views-and-materialized-views-work-and-how-they-influenced-timescaledb-continuous-aggregates/

0 comments on commit 086a6ff

Please sign in to comment.