From 90e28a8c1bbe9703d65e2b2804c1e6fe16e2f332 Mon Sep 17 00:00:00 2001 From: Jamal-B Date: Tue, 9 Jul 2024 15:59:19 +0200 Subject: [PATCH 1/3] Fix function names typos in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a6806b1..f8c4cdc 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ When an IMMV is created, some triggers are automatically created so that the vie Note that if you use PostgreSQL 17 or later, while `create_immv` is running, the `search_path` is temporarily changed to `pg_catalog, pg_temp`. -#### refresh_imm +#### refresh_immv Use `refresh_immv` function to refresh IMMV. ``` @@ -267,7 +267,7 @@ If some base tables have row level security policy, rows that are not visible to IVM is effective when we want to keep an IMMV up-to-date and small fraction of a base table is modified infrequently. Due to the overhead of immediate maintenance, IVM is not effective when a base table is modified frequently. Also, when a large part of a base table is modified or large data is inserted into a base table, IVM is not effective and the cost of maintenance can be larger than refresh from scratch. -In such situation, we can use `refesh_immv` function with `with_data = false` to disable immediate maintenance before modifying a base table. After a base table modification, call `refresh_immv`with `with_data = true` to refresh the view data and enable immediate maintenance. +In such situation, we can use `refresh_immv` function with `with_data = false` to disable immediate maintenance before modifying a base table. After a base table modification, call `refresh_immv`with `with_data = true` to refresh the view data and enable immediate maintenance. ## Authors IVM Development Group From 9ff132b5e63a3b0dd777c5e4a94cfe3dbcdbcfd4 Mon Sep 17 00:00:00 2001 From: Jamal-B Date: Tue, 9 Jul 2024 13:22:17 +0200 Subject: [PATCH 2/3] Allow to create unlogged IMMVs --- README.md | 8 +++++++- createas.c | 12 ++++++++++-- pg_ivm.c | 3 ++- pg_ivm.h | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f8c4cdc..4d559d5 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ When `pg_ivm` is installed, the following objects are created. Use `create_immv` function to create IMMV. ``` -create_immv(immv_name text, view_definition text) RETURNS bigint +create_immv(immv_name text, view_definition text [, unlogged bool DEFAULT false]) RETURNS bigint ``` `create_immv` defines a new IMMV of a query. A table of the name `immv_name` is created and a query specified by `view_definition` is executed and used to populate the IMMV. The query is stored in `pg_ivm_immv`, so that it can be refreshed later upon incremental view maintenance. `create_immv` returns the number of rows in the created IMMV. @@ -94,6 +94,12 @@ When an IMMV is created, some triggers are automatically created so that the vie Note that if you use PostgreSQL 17 or later, while `create_immv` is running, the `search_path` is temporarily changed to `pg_catalog, pg_temp`. +In some cases (e.g. for very large IMMVs containing volatile data), and only if you really know what you are doing, it may be useful to create an IMMV without writing to the [PostgreSQL Write-Ahead Logs](https://www.postgresql.org/docs/current/wal-intro.html) (the underlying table is created with the `UNLOGGED` parameter). Unlogged tables improve write performance, reduce vacuum impact and produce fewer WALs (thus reducing network usage, backup size and restoration time). +```sql +SELECT create_immv('myview', 'SELECT * FROM mytab', true); +``` +**Important:** see the [PostgreSQL documentation](https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-UNLOGGED) for unlogged tables **DRAWBACKS** (not replicated or included in physical backups, truncated in case of PostgreSQL crash, ...). + #### refresh_immv Use `refresh_immv` function to refresh IMMV. diff --git a/createas.c b/createas.c index 6218d16..12ad1c3 100644 --- a/createas.c +++ b/createas.c @@ -234,14 +234,22 @@ create_immv_nodata(List *tlist, IntoClause *into) */ ObjectAddress ExecCreateImmv(ParseState *pstate, CreateTableAsStmt *stmt, - ParamListInfo params, QueryEnvironment *queryEnv, - QueryCompletion *qc) + bool unlogged, ParamListInfo params, + QueryEnvironment *queryEnv, QueryCompletion *qc) { Query *query = castNode(Query, stmt->query); IntoClause *into = stmt->into; bool do_refresh = false; ObjectAddress address; + /* + * For volatile data, it can be useful not to write to WALs. + * SEE THE POSTGRESQL DOCUMENTATION FOR DRAWBACKS (not replicated or included in physical backups, truncated in case of a crash, ...): + * https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-UNLOGGED + */ + if (unlogged) + into->rel->relpersistence = RELPERSISTENCE_UNLOGGED; + /* Check if the relation exists or not */ if (CreateTableAsRelExists(stmt)) return InvalidObjectAddress; diff --git a/pg_ivm.c b/pg_ivm.c index e2afc6f..bb0326c 100644 --- a/pg_ivm.c +++ b/pg_ivm.c @@ -173,6 +173,7 @@ create_immv(PG_FUNCTION_ARGS) { text *t_relname = PG_GETARG_TEXT_PP(0); text *t_sql = PG_GETARG_TEXT_PP(1); + bool unlogged = PG_GETARG_BOOL(2); char *relname = text_to_cstring(t_relname); char *sql = text_to_cstring(t_sql); List *parsetree_list; @@ -228,7 +229,7 @@ create_immv(PG_FUNCTION_ARGS) query = transformStmt(pstate, (Node *)ctas); Assert(query->commandType == CMD_UTILITY && IsA(query->utilityStmt, CreateTableAsStmt)); - ExecCreateImmv(pstate, (CreateTableAsStmt *) query->utilityStmt, NULL, NULL, &qc); + ExecCreateImmv(pstate, (CreateTableAsStmt *) query->utilityStmt, unlogged, NULL, NULL, &qc); PG_RETURN_INT64(qc.nprocessed); } diff --git a/pg_ivm.h b/pg_ivm.h index 2c76f9b..069ff58 100644 --- a/pg_ivm.h +++ b/pg_ivm.h @@ -35,7 +35,7 @@ extern bool isImmv(Oid immv_oid); /* createas.c */ -extern ObjectAddress ExecCreateImmv(ParseState *pstate, CreateTableAsStmt *stmt, +extern ObjectAddress ExecCreateImmv(ParseState *pstate, CreateTableAsStmt *stmt, bool unlogged, ParamListInfo params, QueryEnvironment *queryEnv, QueryCompletion *qc); extern void CreateIvmTriggersOnBaseTables(Query *qry, Oid matviewOid); From e053a9ee72d42fd9e7fc2a4ef9b0b05d7eaaa19c Mon Sep 17 00:00:00 2001 From: Jamal-B Date: Mon, 22 Jul 2024 09:48:51 +0200 Subject: [PATCH 3/3] Prepare 1.10 --- Makefile | 3 ++- pg_ivm--1.9--1.10.sql | 9 +++++++++ pg_ivm.control | 2 +- rpm/pg_ivm.spec | 4 +++- 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 pg_ivm--1.9--1.10.sql diff --git a/Makefile b/Makefile index 2ad6381..9cf2262 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,8 @@ EXTENSION = pg_ivm DATA = pg_ivm--1.0.sql \ pg_ivm--1.0--1.1.sql pg_ivm--1.1--1.2.sql pg_ivm--1.2--1.3.sql \ pg_ivm--1.3--1.4.sql pg_ivm--1.4--1.5.sql pg_ivm--1.5--1.6.sql \ - pg_ivm--1.6--1.7.sql pg_ivm--1.7--1.8.sql pg_ivm--1.8--1.9.sql + pg_ivm--1.6--1.7.sql pg_ivm--1.7--1.8.sql pg_ivm--1.8--1.9.sql \ + pg_ivm--1.9--1.10.sql REGRESS = pg_ivm create_immv refresh_immv diff --git a/pg_ivm--1.9--1.10.sql b/pg_ivm--1.9--1.10.sql new file mode 100644 index 0000000..e085e94 --- /dev/null +++ b/pg_ivm--1.9--1.10.sql @@ -0,0 +1,9 @@ +-- functions + +CREATE FUNCTION create_immv(text, text, boolean default false) +RETURNS bigint +STRICT +AS 'MODULE_PATHNAME', 'create_immv' +LANGUAGE C; + +DROP FUNCTION create_immv(text, text); diff --git a/pg_ivm.control b/pg_ivm.control index c9bea89..27dc5af 100644 --- a/pg_ivm.control +++ b/pg_ivm.control @@ -1,6 +1,6 @@ # incremental view maintenance extension_ comment = 'incremental view maintenance on PostgreSQL' -default_version = '1.9' +default_version = '1.10' module_pathname = '$libdir/pg_ivm' relocatable = false schema = pg_catalog diff --git a/rpm/pg_ivm.spec b/rpm/pg_ivm.spec index e4f2db2..5587850 100644 --- a/rpm/pg_ivm.spec +++ b/rpm/pg_ivm.spec @@ -10,7 +10,7 @@ Summary: PostgreSQL-based distributed RDBMS Name: %{sname}_%{pgmajorversion} -Version: 1.9 +Version: 1.10 Release: 1%{dist} License: BSD Vendor: IVM Development Group @@ -55,6 +55,8 @@ PATH=%{pginstdir}/bin:$PATH %{__make} %{?_smp_mflags} INSTALL_PREFIX=%{buildroot %endif %changelog +* Mon Aug 26 2024 - Jamal Boukaffal 1.10-1 +- Update to 1.10 * Fri Jul 31 2024 - Yugo Nagata 1.9-1 - Update to 1.9 * Fri Mar 1 2024 - Yugo Nagata 1.8-1