-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |