Commit graph

23 commits

Author SHA1 Message Date
Yugo Nagata
132816cffe Prepare 1.12 2025-09-04 22:59:18 +09:00
Yugo Nagata
f4b40e93a6 Prepare 1.11 2025-05-26 17:07:09 +09:00
Yugo Nagata
966a865d60 Support for PostgreSQL 15 or earlier
- Not use List APIs for xid that are introduced from PostgreSQL 16

- Fix an error during isolation test
   ERROR:  subquery in FROM must have an alias

- Not use isolation test for PostgreSQL 13
2025-03-11 16:24:34 +09:00
Yugo Nagata
f1166c0421
Fix potential view inconsistency issues (#121)
Previously, the view contents could become inconsistent with the base tables
in the following scenarios:

1) A concurrent transaction modifies a base table and commits before the
   incremental view maintenance starts in the current transaction.

2) A concurrent transaction modifies a base table and commits before the
   create_immv or refresh_immv command generates data.

3) Concurrent transactions incrementally update a view with a self-join
   or modify multiple base tables simultaneously.

Incremental updates of a view are generally performed sequentially using an
exclusive lock. However, even if we are able to acquire the lock, a concurrent
transaction may have already incrementally updated the view and been committed
before we can acquire it. In REPEATABLE READ or SERIALIZABLE isolation levels,
this could lead to an inconsistent view state, which is the cause of the first
issue.

To fix this, a new field, lastivmupdate, has been added to the pg_ivm_immv
catalog to record the transaction ID of the most recent update to the view.
Before performing view maintenance, the transaction ID is checked. If the
transaction was still in progress at the start of the current transaction,
an error is raised to prevent anomalies.

To fix the second issue, the timing of CreateTrigger() has been moved to
before data generation. This ensures that locks conflicting with table
modifications have been acquired on all base tables. In addition, the latest
snapshot is used in READ COMMITTED level during the data generation to reflect
committed changes from concurrent transactions. Additionally, inconsistencies
that cannot be avoided through locking are prevented by checking the transaction
ID of the last view update, as done for the first issue.

However, concurrent table modifications and create_immv execution still cannot
be detected at the time of view creation. Therefore, create_immv raises a warning
in REPEATABLE READ or SERIALIZABLE isolation levels, suggesting that the command
be used in READ COMMITTED mode or that refresh_immv be executed afterward to
ensure the view remains consistent.

The third issue was caused by the snapshot used for checking tuple visibility in
the table's pre-update state not being the latest one. To fix this, the latest
snapshot is now used in READ COMMITTED mode.

Isolation tests are also added.

Issue #104
2025-03-10 18:26:54 +09:00
Yugo Nagata
417c291454
Change the schema from pg_catalog to pgivm (#116)
Previously, pg_upgrade failed due to the permission denied
because the pg_ivm_immv catalog was in the pg_catalog catalog
(Issue #79). To fix this, all objects created by pg_ivm are
moved to theschema pgivm, which is also created by pg_ivm.

pg_ivm is still not relocatable and this must be installed
to the pgivm schema because the catalog and some internal
functions are referred to unqualified by the schema name
from the pg_ivm module. In future, this might be able to
relocatable during installation, though.

This commit affects compatibility with previous releases.
To allow to access objects like create_immv function as
previous, you need to qualify them with the schema name
or setup search_path properly.
2025-02-17 12:07:21 +09:00
Yugo Nagata
80a7648add Bump up to 1.10 2024-12-09 20:01:46 +09:00
Yugo Nagata
12a0120d45 Prepare 1.9 2024-07-31 13:00:31 +09:00
Yugo Nagata
9736c8c832 Prepare 1.8 2024-03-01 23:28:28 +09:00
Yugo Nagata
8f87d0914a Prepare 1.7 2023-09-13 11:13:40 +09:00
Yugo Nagata
6f99049848 Prepare 1.6 2023-08-31 21:11:36 +09:00
Yugo Nagata
f0e5467281 Prepare 1.5 2023-01-30 12:28:53 +09:00
Yugo Nagata
b928e32774
Add CTE support (#47)
Simple CTEs which does not contain aggregates or DISTINCT are 
now supported similarly to simple sub-queries.

Before a view is maintained, all CTEs are converted to corresponding
subqueries to enable to treat CTEs as same as subqueries. For this
end, codes of the static function inline_cte in the core
(optimizer/plan/subselect.c) was imported.

Prohibit Unreferenced CTE is prohibited.
When a table in a unreferenced CTE is TRUNCATEd, the contents
of the IMMV is not affected so it must not be truncated. For
confirming it at the maintenance time, we have to check if the
modified table used in a CTE is actually referenced. Although
it would possible, we just disallow to create such IMMVs for now
since such unreferenced CTE is useless unless it doesn't contain
modifying commands, that is already prohibited.
2023-01-30 11:28:27 +09:00
Yugo Nagata
138eb19254
Fix Makefile to install pg_ivm--1.3--1.4.sql (#45)
This should have be included in the previous commit but was
accidentally forgotten. Issue #43
2023-01-10 18:41:50 +09:00
Yugo Nagata
e857213281 Allow to variable PG_CONFIG together with make command 2022-11-25 18:33:27 +09:00
Yugo Nagata
5f584e54c3 Fix a typo in Makefile 2022-09-30 01:22:23 +09:00
Yugo Nagata
fbbd86d825
Prepare 1.3 (#27) 2022-09-29 23:20:41 +09:00
Yugo Nagata
6439e8c7be Bump up the version 1.1 to 1.2 2022-07-28 21:29:12 +09:00
Yugo Nagata
6faf0b3baa
Support min/max aggregates (#18)
In order to re-calculate min/max values for groups where the min
or max value is deleted, we need the view query definition in string
form. However, pg_get_viewdef cannot be used for this purpose because
IMMV's defenition is in pg_ivm_immv but not pg_rewrite.  Therefore,
we have to convert query definition in pg_ivm_immv to query
definition string. We can use pg_get_querydef in PG15, but we cannot
in PG14 or earlier, so we use codes in ruleutil.c copied from PG13
or PG14 depending versions.
2022-07-25 13:11:33 +09:00
Yugo Nagata
1e80a34a86 Move the new function and catalog attributes to a update script 2022-06-16 10:07:54 +09:00
thoshiai
51a944b388 Add refresh_immv() function
refresh_immv(immv_name, with_data) is a function to refresh IMMV like
 REFRESH MATERIALIZED VIEW command. It has two argument.
immv_name is incrementally maintainable materialized view's name, and
with_data is an option that is corresponding to the WITH [NO] DATA option.
When with_data is set false, the IMMV gets unpopulated.

One of differences between IMMVs unpopulated by this function and
normal materialized views unpopulated by REFRESH ... WITH NO DATA
is that such IMMVs can be referenced by SELECT but return no rows,
while unpopulated materialized views are not scanable.

The behaviour may be changed in future to raise an error when unpopulated
an IMMV is scanned.
2022-06-16 03:06:47 +09:00
Yugo Nagata
f2d43bb923 Fix to delete the pg_ivm_immv entry when an IMMV is dropped 2022-04-28 19:47:30 +09:00
Yugo Nagata
eed6271128 Split files to make it easier to follow the core code 2022-04-27 14:45:47 +09:00
Yugo Nagata
1bce646d21 Initial release of pg_ivm 1.0 2022-04-01 01:08:28 +09:00