Commit graph

129 commits

Author SHA1 Message Date
Yugo Nagata
326720874e
Fix a bug of automatic index creation (#40)
It is intended that a unique index is created only if all primary
keys of tables in FROM clause appear in the target list. For this
purpose, pull_varnos_of_level was used to extract relations in the
FROM clause, but it is incorrect and actually we should use
get_relids_in_jointree.

Due to this bug, an index could be created even even where there
is a pkey attribute from just one of relations in FROM clause.
2022-12-16 12:42:35 +09:00
thoshiai
59081de628
Fix segmentation fault in incorrect view def (#39)
A segfault was occurred when non-SELECT query was specified in create_immv since the statement type was not checked.

issue #37
2022-12-15 19:03:49 +09:00
Yugo Nagata
e857213281 Allow to variable PG_CONFIG together with make command 2022-11-25 18:33:27 +09:00
thoshiai
24dc053659
Fix not to create IMMV including other IMMV(#30) (#31)
Previously, IMMV including IMMV in its definition can be created by
create_immv(), but it should not be supported by IMMV because we
cannot maintain it recursively for now. This patch prevents it by raising
an error for such view definition on create_immv().
2022-10-18 15:51:41 +09:00
Yugo Nagata
6eddcd2a63 Merge branch 'main' of https://github.com/sraoss/pg_ivm into main 2022-09-30 23:57:01 +09:00
Yugo Nagata
5e69211d7b Bump up version number to 1.3 2022-09-30 23:56:33 +09:00
Yugo Nagata
78b8ac2e68
Add description of get_immv_def to README 2022-09-30 23:55:01 +09:00
Yugo Nagata
e31dc21eaa
Use object_access_hook to drop an IMMV entry from pg_ivm_immv (#29)
Previously, we used an event trigger and executed DELETE command,
but it caused a privilege error when non-superuser dropped a table
even if it is irrelevant to IMMV.

To fix it, we now use object_access_hook and an entry is deleted
via CatalogTupleDelete which doesn't need the superuser privilege.

Issue #25
2022-09-30 23:49:51 +09:00
thoshiai
1d21409321
Add get_immv_def func (#23)
get_immv_def reconstructs the underlying SELECT command for a
IMMV. This is a decompiled reconstruction, not the original text
of the command.
2022-09-30 18:59:51 +09:00
Yugo Nagata
b6702f9a3a
Use snapshot to check tuple visibility in pre-update state (#28)
When multiple tables are updated or the view contains a self-join,
we need to calculate table states that was before it is modified
during incremental view maintenance. For get the pre-update state,
tuples inserted in a command must be removed when the table is scanned.

Previously, we used xmin and cmin system columns for this purpose,
but this way is problematic because after a tuple is frozen, its xmin
no longer has any meaning. Actually, we will get inconsistent view
results after XID wraparound.

Also, we can see similar similar inconsistency when using sub-transaction
because xmin values do not always monotonically increasing by command
executions.

To fix this, we use a snapshot that taken just before the table is
modified for checking tuple visibility in pre-state table instead of
using xmin and cmin system columns. A new function returning boolean,
ivm_visible_in_prestate, is added, and this is called in WHERE clause
of sub-queries to calculate pre-state table. This function check if a
specified tuple in the post-update table is visible or not using the
snapshot and return true if the tuple is visible.
2022-09-30 11:53:12 +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
4c6016999d
Fix to get view definition string with correct column names (#26)
Previously, a query string returned from pg_ivm_get_querydef
did not include column names specified when IMMV was defined
by create_immv. This caused failures in maintenance of MIN/MAX
aggregate views whose columns had alias names.

It is fixed by rewriting the result column name in the parse tree
using the view's tuple descriptor prior to calling pg_get_querydef
for PG15 or higher, or specifying the tuple descriptor to
get_query_def for PG14 or earlier.
2022-09-29 22:24:28 +09:00
Yugo Nagata
79d4b13ba1
Fix comment typo and test for aggregates without GROUP BY (#24)
We usually try to create a unique index on an IMMV for both
performance and constraint reasons. However, we don't need
such index for an aggregate view without GROUP BY because
it has always only one row. Also, we don't need to raise
NOTICE message to suggest to create an index.

This change was mistakenly introduced in cfe9491e6b,
but it should have been a separate commit. In this commit,
a typo and tests are fixed.
2022-09-28 16:02:53 +09:00
Yugo Nagata
508f93f7dc Fix comments in pg_ivm.spec 2022-09-06 15:31:30 +09:00
thoshiai
52895572ac
Merge pull request #19 from marcocitus/marcocitus/fix-compile-warning
Fix gcc warning in ExecRefreshImmv
2022-08-17 01:18:07 +09:00
Marco Slot
046b323ce5 Fix compiler warning in ExecRefreshImmv 2022-07-28 18:05:39 +02:00
Yugo Nagata
6439e8c7be Bump up the version 1.1 to 1.2 2022-07-28 21:29:12 +09:00
Yugo Nagata
7c7f2de5a5 Remove tailing tab space 2022-07-25 17:40: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
Yugo Nagata
6dcfb31848 Update to 1.2 2022-07-25 15:21:38 +09:00
Yugo Nagata
f1e36a9781 Add regression tests for some cases
Per sub-queries support, a test for join with subquery is added.
In passing, the order of tests are fixed with according to that in pgsql-ivm.
Also, some other tests related to aggregates and sub-queries are added.
2022-07-25 15:14:40 +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
thoshiai
790b0d2bd6
Support simple subquery (#17)
A simple subquery in FROM clause is supported.
DISTINCT and aggregate functions are not supported in subquery.
2022-07-25 09:24:51 +09:00
thomas.boussekey
75ee63b99a
Fix minor typos in README (#16) 2022-07-21 23:38:26 +09:00
thoshiai
2ead2e207e
Add support for PostgreSQL 15 (#15) 2022-07-14 22:54:33 +09:00
Yugo Nagata
d7d1fb0f49 Update to 1.1 2022-06-23 11:48:07 +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
1c4408199c Fix error codes for invalid input to create_immv 2022-06-22 17:59:20 +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
Yugo Nagata
53c9509163 Fix check for aggregate functions to work with PostgreSQL 13
In PostgreSQL 14 or later, OIDs of aggregate functions are
described in fmrgoids.h, but that in PostgreSQL 13 doesn't
contain aggregate function OIDs. Therefore, we get the OID
by passing the function name and arg type to to_regprocedure().
2022-06-21 23:08:54 +09:00
Yugo Nagata
d99aeb848e Allow TRUNCATE on base tables (#144)
When a base table is truncated, the view content will be empty if the
view definition query does not contain an aggregate without a GROUP clause.
Therefore, such views can be truncated.

Aggregate views without a GROUP clause always have one row. Therefore,
if a base table is truncated, the view will not be empty and will contain
a row with NULL value (or 0 for count()). So, in this case, we refresh the
view instead of truncating it.
2022-06-21 21:27:21 +09:00
Yugo Nagata
57c8bac1a0 Add aggregates support
Built-in count, sum, avg are supported. We have not supported min/max
yet, but will support in future.

When an IMMV with any aggregates are defined, additional columns
are created for each aggregate function. Although such columns are
"hidden" in pgsql-ivm version, they are always visible for users
in the extension version.
2022-06-21 20:50:45 +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
7ab42004d2
Merge pull request #12 from sraoss/11-pg_ivm-test-fails-on-postgresql-15-beta1
Fix the test to grant create permissions on the public schema
2022-06-13 13:25:49 +09:00
Yugo Nagata
a37de7aa7a
Merge pull request #13 from tatsuo-ishii/README_fix
Mention that pg_ivm is compatible with PostgreSQL 13 in addition to 
PostgreSQL 14.
2022-06-13 09:35:48 +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
a75443f8ea Fix the test to grant create permissions on the public schema
As of PG15, PUBLIC CREATE was revoked from public schema, so
we have to grant it in contrib_regression database.
2022-06-03 15:53:41 +09:00
Yugo Nagata
9719ed644d
Merge pull request #10 from tatsuo-ishii/rel13
Allow to build pg_ivm on PostgreSQL 13.
2022-06-02 14:46:59 +09:00
Yugo Nagata
42a5bcd24e Fix pg_ivm.spec take2 2022-06-02 12:04:55 +09:00
Yugo Nagata
575e8ff0ac Fix spec file 2022-06-02 11:27:41 +09:00
Tatsuo Ishii
612b59694e Allow to build pg_ivm on PostgreSQL 13. 2022-05-17 21:32:04 +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
Yugo Nagata
f4579fa3fc
Merge pull request #8 from sraoss/header
Fix a header guard macro. Reported by Issue #6.
2022-05-03 03:24:39 +09:00