Commit graph

39 commits

Author SHA1 Message Date
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
be13c952c2
Update README.md 2025-02-12 16:39:42 +09:00
Yongtao Huang
094add99f5
Clean duplicated code and some typos (#112)
Also, argument order mismatch of apply_new_delta_with_count()  between
declaration and definition is fixed.
2025-02-12 15:30:46 +09:00
Yongtao Huang
b8de2801c7
Fix a typo (#111) 2024-12-23 11:44:22 +09:00
Yugo Nagata
85b11c359a
Add a note for create_immv in README.md
With PostgreSQL 17 or later, while `refresh_immv` is running, 
the `search_path` is temporarily changed to `pg_catalog, pg_temp`.
2024-08-06 04:11:25 +09:00
Yugo Nagata
65a2d36b22
Add support for PostgreSQL 17 (#92)
Compilation errors and warning are fixed.

The design of create_immv is also chaned as similar to PG17, that is,
firstly a relation is created without data then it is populated
by using the refresh logic.

This commit contains the following changes:

 - Change functions to use a safe search_path during maintenance operations
   when used with PostgreSQL 17

  This prevents maintenance operations (automatic maintenance of IMMVs and
  refresh_immv) from performing unsafe access.  Functions used by IMMVs that
  need to reference non-default schemas must specify a search path during
  function creation.

 - refresh_immv can be executed by users with the MAINTAIN privilege
   when used with PostgreSQL 17

Issue #90
2024-07-31 12:37:43 +09:00
Éric Redon
aab9db3605
Fix typo in README heading (#81) 2024-02-20 16:37:14 +09:00
Yugo Nagata
71f9d268b0
Add support for PostgreSQL 16 (#69) (#70)
Build errors/warnings against PostgreSQL 16 are fixed.
Also, adapted to the change of codes, including:

- Get rid of the "new" and "old" entries in a view's rangetable.
(Although, removed codes were dead codes because pg_ivm doesn't
 have any rules in pg_rewrite.)

- Rework query relation permission checking

- Require empty Bitmapsets to be represented as NULL

- Fix some compiler warnings
2023-09-11 15:23:51 +09:00
Yugo Nagata
1b4fb57774
Prohibit types without default btree opclass in the target list (#67)
Currently, types that does not have an equality operator cannot
be used in the target list of the view definition, because all
of target list entries are used for comparison to identify rows
to be updated or deleted in the view. Previously, an error is
raised at the time such view is incrementally maintained, this
is fixed to check that at the view creation time.

This restriction may be relaxed in future after we can use an
index to identify rows in the view.

Issue #61
2023-08-31 21:06:23 +09:00
thoshiai
c355f4003b
Support exists_subquery (#53)
Add EXISTS clause support in IVM
   
Correlated subqueries using EXISTS in WHERE clause are supported.
   
An EXISTS subquery in WHERE clause is rewritten to LATERAL subquery
in FROM clause, and IVM' process can handle this like as a normal join. 
Also, hidden columns "ivm_exists_count_X__"  are added to check if 
EXISTS condition is satisfied.  This column stores the count of how many 
rows in the subquery are correlated to (joined to) each row of the main 
query. When a base table contained in EXISTS clause is modified, this 
count value in IMMV is updated, and a row whose count becomes zero 
is deleted.

restrictions :
- EXISTS subqueries are allowed only in WHERE clause.
- aggregate functions are not supported together with EXISTS.
- EXISTS subqueries in a subquery are not supported.
- EXISTS condition can use only with AND Expr
2023-08-31 11:51:36 +09:00
Valentino
1f729c842a
Update README.md (#55)
Correct spelling mistake
2023-03-20 17:44:21 +09:00
Yugo Nagata
0587e78651
Update README.md 2023-01-30 19:04:54 +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
0xflotus
65b2e4937e
Fix small typos in README.md (#44) 2023-01-10 18:20:27 +09:00
Yugo Nagata
5db54f4669
Use exclusive lock for view maintenance caused by UPDATE or DELETE (#42)
When using DELETE or UPDATE, we must use exclusive lock for now
because apply_old_delta(_with_count) could result in wrong results
with concurrent transactions. We would like to improve it in future,
but we prevent it by using the lock for now.
2022-12-16 23:31:00 +09:00
Yugo Nagata
78b8ac2e68
Add description of get_immv_def to README 2022-09-30 23:55:01 +09:00
Yugo Nagata
73b2fc216e Fix types in README 2022-07-25 17:37:22 +09:00
Yugo Nagata
cfe9491e6b Fix README for pg_ivm 1.2 2022-07-25 17:31:46 +09:00
thomas.boussekey
75ee63b99a
Fix minor typos in README (#16) 2022-07-21 23:38:26 +09:00
Yugo Nagata
3de95c09fa Improve refresh_immv behavior a bit
- Allow to use qualified name
- Confirm if executed by the owner of the IMMV
- Improve the message when specified relation is not an IMMV
- Create a unique index at refresh with no dat if possible
  This is actually required, but we want it behave as same
  as the pgsql-ivm version for now.
2022-06-23 11:33:06 +09:00
Yugo Nagata
279b14049e
Update README.md
Add description about how to disable or enable IVM
2022-06-22 16:41:33 +09:00
Yugo Nagata
384347fdeb
Update README for pg_ivm 1.1
Add description about aggregates, TRUNCATE, and refresh_immv.
2022-06-22 16:09:04 +09:00
Tatsuo Ishii
7868c7b923 Mention that pg_ivm is compatible with PostgreSQL 13 in addition to PostgreSQL 14. 2022-06-11 18:57:14 +09:00
Yugo Nagata
ad0d36220f
Update README.md 2022-05-12 16:25:15 +09:00
Yugo Nagata
0a99573ff3
Update README.md 2022-05-12 16:22:13 +09:00
Yugo Nagata
5776ea3aa6
Update README.md 2022-05-12 16:15:46 +09:00
Yugo Nagata
0c44342ba8
Update README.md 2022-05-12 16:14:36 +09:00
fjf2002
8374ae71b5
Update README.md
Typo fixed
2022-05-02 11:00:18 +02:00
Yugo Nagata
2255a73ff1
Update README.md 2022-04-27 15:08:01 +09:00
Yugo Nagata
f586a03716
Update README.md 2022-04-15 09:44:31 +09:00
Yugo Nagata
34c44eb4b1
Update README.md 2022-04-14 16:58:25 +09:00
Yugo Nagata
0a5f018fb9
Update README.md 2022-04-13 14:40:36 +09:00
Hanefi Onaldi
dc13661b13
Fix simple typos in README
Incremnetal -> Incremental
Installaion -> Installation
2022-04-01 15:08:36 +03:00
Tatsuo Ishii
5cdd35c7ab
Merge branch 'sraoss:main' into main 2022-04-01 10:28:40 +09:00
Yugo Nagata
94fb07b173
Update README.md 2022-04-01 10:27:45 +09:00
Tatsuo Ishii
2c960c7b27 Fix typo in an example sql. 2022-04-01 10:26:19 +09:00
Yugo Nagata
fc939ba681 Update README.md 2022-04-01 01:08:28 +09:00
Yugo Nagata
64eaed8831
Create README.md 2022-03-29 19:08:46 +09:00