cockroachdb / cockroachdb/cockroach
sql: allow triggers to modify cascade queries
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
Postgres runs cascades, checks, and AFTER triggers for a query in that order, and then repeats the cycle with any newly-queued post-queries. It is possible for BEFORE triggers on cascading tables to make changes to the cascade queries. Here is a snippet from the Postgres docs:
```
There is also nonstandard behavior if BEFORE triggers modify rows or prevent updates
during an update that is caused by a referential action. This can lead to constraint
violations or stored data that does not honor the referential constraint.
```
With #133220, we prevent row-level BEFORE triggers from modifying or filtering rows in a cascade via a runtime assertion. However, we could relax this check for non-FK columns, since modifying them can't violate any FK constraints. We could also remove the check for FKs if we can be sure that the necessary check queries run after all cascades and triggers have fired. Note that this would result in a different execution order than Postgres, but that may be alright.
Jira issue: CRDB-43997
Epic CRDB-347
Contributor guide
Assessment
This issue has not been assessed yet.