sraoss / pgsql-ivm

IVM (Incremental View Maintenance) development for PostgreSQL
Other
129 stars 12 forks source link

Reduce probbility of deadlock #126

Closed yugo-n closed 3 years ago

yugo-n commented 3 years ago

If the view has more than one base tables, we need an exclusive lock on the view so that the view would be maintained serially to avoid the inconsistency that occurs when two base tables are modified in concurrent transactions. However, if the view has only one table, we can use a weaker lock.

Previously, we checked the view definition at maintenance time to determin the lock strength. However, this caused high probability of dead-lock, because we needed to upgrade the lock level after the weeker lock acquired to get the view definition.

Now, the lock type is determined at view definition, and passed via an argument of the trigger function to avoid the lock level upgrading.