Skip to content

Design Change to execute refresh_immv() with False#132

Open
jatinp97 wants to merge 2 commits intosraoss:mainfrom
jatinp97:block-pgivm-drop-trigger
Open

Design Change to execute refresh_immv() with False#132
jatinp97 wants to merge 2 commits intosraoss:mainfrom
jatinp97:block-pgivm-drop-trigger

Conversation

@jatinp97
Copy link
Copy Markdown

@jatinp97 jatinp97 commented Apr 22, 2025

Issue #, if available:
#131

Description of changes:
Set the Dependency type to DEPENDENCY_INTERNAL from DEPENDENCY_AUTO.

By submitting this pull request, I confirm that my contribution is made under the terms of the PostgreSQL license.

Example:

postgres=# create table mytab (i INT);
postgres=# select pgivm.create_immv('myview', 'select * from mytab');
NOTICE:  could not create an index on immv "myview" automatically
DETAIL:  This target list does not have all the primary key columns, or this view does not contain GROUP BY or DISTINCT clause.
HINT:  Create an index on the immv for efficient incremental maintenance.

postgres=# select 'myview'::regclass::oid;
  oid  
-------
 16403
(1 row)

postgres=# select * from pg_trigger where tgrelid = 16403;
oid  | tgrelid | tgparentid |            tgname             | tgfoid | tgtype | tgenabled | tgisinternal | tgconstrrelid | tgconstrindid | tgconstraint | tgdeferrable | tginitdeferred | tgnargs | tgattr | tgargs | tgqual | tgoldtable | tgnewtable 
-------+---------+------------+-------------------------------+--------+--------+-----------+--------------+---------------+---------------+--------------+------------
--+----------------+---------+--------+--------+--------+------------+------------
16417 |   16403 |          0 | IVM_prevent_immv_change_16417 |  16399 |      6 | O         | t            |             0 |             0 |            0 | f          
  | f              |       0 |        | \x      |        |            | 

postgres=# drop trigger "IVM_prevent_immv_change_16417" on myview;
ERROR:  cannot drop trigger IVM_prevent_immv_change_16417 on table myview because table myview requires it
HINT:  You can drop table myview instead.

postgres=# drop trigger "IVM_trigger_ins_before_16406" on mytab;
ERROR:  cannot drop trigger IVM_trigger_ins_before_16406 on table mytab because table myview requires it
HINT:  You can drop table myview instead.
postgres=# drop table mytab;
ERROR:  cannot drop table mytab because other objects depend on it
DETAIL:  table myview depends on table mytab
HINT:  Use DROP ... CASCADE to drop the dependent objects too.

@yugo-n
Copy link
Copy Markdown
Collaborator

yugo-n commented May 8, 2025

Thank you for your pull request!

Although #131 should be fixed, but currently it is intended that we use DEPENDENCY AUTO for an implement reason. Specifically, when refresh_immv() is executed with specified false as the second argument, all triggers are dropped from tables to disable incremental view maintenance. So, your proposal to use DEPENDENCY_INTERNAL disables refresh_immv() to be run with false. To fix #131, first we have to change the design.

Copy link
Copy Markdown
Collaborator

@yugo-n yugo-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comments in the post
#132 (comment)

@yugo-n
Copy link
Copy Markdown
Collaborator

yugo-n commented May 8, 2025

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

AFYI, the license of pg_ivm is PostgreSQL License, not Apache 2.0.
https://github.com/sraoss/pg_ivm/blob/main/LICENSE

@jatinp97 jatinp97 changed the title Set the dependency type of Triggers to DEPENDENCY_INTERNAL Design Change to execute refresh_immv() with False May 22, 2025
@jatinp97
Copy link
Copy Markdown
Author

jatinp97 commented May 28, 2025

To circumvent the problem of use of DEPENDENCY_INTERNAL disable refresh_immv() to be run with false, I have used deleteDependencyRecordsFor which is used when redefining an existing object by deleting all records with given depender(classId/objectId). See the changes here

@MasahikoSawada
Copy link
Copy Markdown

While calling deleteDependencyRecordsFor() before dropping the trigger seems workable I have a question about the trigger management design of pg_ivm: can we use enable/disable triggers instead of dropping/recreating them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants