You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Added an example demonstrating an IMMV with aggregate functions
(Issue #105)
- Added examples for listing and deleting an IMMV. (Issue #109)
- Noted that IMMVs must be manually dropped and recreated after
restoring data from pg_dump or performing pg_upgrade. (Issue #118)
- Added a reinder to set session_preload_libraries or
shared_preload_libraries during instlation. (Issue #119)
Copy file name to clipboardexpand all lines: README.md
+123-2
Original file line number
Diff line number
Diff line change
@@ -68,12 +68,25 @@ If you installed PostgreSQL from rpm or deb, you will need the devel package (fo
68
68
69
69
> **Important:** Don't forget to set the `PG_CONFIG` variable (`make PG_CONFIG=...`) or the `PATH` to the `pg_config` command in case you want to use `pg_ivm` on a non-default or custom build of PostgreSQL. Read more [here](https://wiki.postgresql.org/wiki/Building_and_Installing_PostgreSQL_Extension_Modules).
70
70
71
-
And, execute CREATE EXTENSION comand.
71
+
Once installed, execute `CREATE EXTENSION` comand.
72
72
73
73
```sql
74
74
CREATE EXTENSION pg_ivm;
75
75
```
76
76
77
+
### Configuration
78
+
79
+
To ensure `pg_ivm` maintains IMMVs correctly, add it to either shared_preload_libraries or session_preload_libraries in postgresql.conf:
80
+
81
+
```
82
+
# Add pg_ivm to preload libraries
83
+
shared_preload_libraries = 'pg_ivm'
84
+
# OR
85
+
session_preload_libraries = 'pg_ivm'
86
+
```
87
+
88
+
After making this change, restart PostgreSQL for the configuration to take effect.
89
+
77
90
### RPM packages and yum repository
78
91
79
92
RPM packages of pg_ivm are available from the [PostgreSQL yum repository](https://yum.postgresql.org/). See the [instruction](https://yum.postgresql.org/howto/) for details. Note that we are not the maintainer of this yum repository and RPMs for pg_ivm in it may be not always latest.
@@ -133,6 +146,8 @@ The catalog `pgivm.pg_ivm_immv` stores IMMV information.
133
146
134
147
## Example
135
148
149
+
### `CREATE MATERIALIZED VIEW` and `REFRESH MATERIALIZED VIEW`
150
+
136
151
In general, IMMVs allow faster updates than `REFRESH MATERIALIZED VIEW` at the price of slower updates to their base tables. Update of base tables is slower because triggers will be invoked and the IMMV is updated in triggers per modification statement.
137
152
138
153
For example, suppose a normal materialized view defined as below:
@@ -156,6 +171,8 @@ REFRESH MATERIALIZED VIEW
156
171
Time: 20575.721 ms (00:20.576)
157
172
```
158
173
174
+
### Creating an IMMV
175
+
159
176
On the other hand, after creating IMMV with the same view definition as below:
160
177
161
178
```
@@ -169,7 +186,7 @@ NOTICE: created index "immv_index" on immv "immv"
169
186
(1 row)
170
187
```
171
188
172
-
updating a tuple in a base table takes more than the normal view, but its content is updated automatically and this is faster than the `REFRESH MATERIALIZED VIEW` command.
189
+
Updating a tuple in a base table takes more than the normal view, but its content is updated automatically and this is faster than the `REFRESH MATERIALIZED VIEW` command.
173
190
174
191
```sql
175
192
test=# UPDATE pgbench_accounts SET abalance = 1234 WHERE aid = 1;
@@ -198,6 +215,110 @@ UPDATE 1
198
215
Time: 3224.741 ms (00:03.225)
199
216
```
200
217
218
+
### IMMV with Aggregate Functions
219
+
220
+
You can create an IMMV that includes aggregate functions.
FROM pgbench_accounts JOIN pgbench_branches USING(bid) GROUP BY bid');
226
+
NOTICE: created index "immv_agg_index"on immv "immv_agg"
227
+
create_immv
228
+
-------------
229
+
100
230
+
(1 row)
231
+
232
+
Time: 5772.625 ms (00:05.773)
233
+
```
234
+
235
+
Creating this view takes about five seconds, and the normal refresh operation requires a similar amount of time. The following example demonstrates refreshing the IMMV using `refresh_immv`. The execution time would be approximately the same if you used `REFRESH MATERIALIZED VIEW` on a regular materialized view with the same definition.
After restoring data from a `pg_dump` backup or upgrading `PostgreSQL` using `pg_upgrade`, all IMMVs must be manually dropped and recreated.
321
+
201
322
## Supported View Definitions and Restriction
202
323
203
324
Currently, IMMV's view definition can contain inner joins, DISTINCT clause, some built-in aggregate functions, simple sub-queries in `FROM` clause, EXISTS sub-queries, and simple CTE (`WITH` query). Inner joins including self-join are supported, but outer joins are not supported. Supported aggregate functions are count, sum, avg, min and max. Other aggregates, sub-queries which contain an aggregate or `DISTINCT` clause, sub-queries in other than `FROM` clause, window functions, `HAVING`, `ORDER BY`, `LIMIT`/`OFFSET`, `UNION`/`INTERSECT`/`EXCEPT`, `DISTINCT ON`, `TABLESAMPLE`, `VALUES`, and `FOR UPDATE`/`SHARE` can not be used in view definition.
0 commit comments