sql: identify trigger-based table dependencies in backreferences#161910
sql: identify trigger-based table dependencies in backreferences#161910rafiss wants to merge 2 commits intocockroachdb:masterfrom
Conversation
|
@spilchen I was curious to learn more about this proposed change from the issue:
Was the intended change something like this? in the query: cockroach/pkg/workload/schemachange/error_screening.go Lines 127 to 145 in 9a19eae I wanted to understand why we need this change before going ahead with it |
|
I’m not 100% sure, but I believe my thinking was around the change to |
c4772c7 to
b5aeee8
Compare
Previously, when a trigger function referenced another table, the backreference in DependedOnBy was structurally identical to view dependencies. This made it impossible to distinguish trigger dependencies from view dependencies when inspecting crdb_internal.forward_dependencies. This commit adds a trigger_id field to TableDescriptor_Reference in the protobuf schema. When creating backreferences for trigger dependencies, we now set the trigger_id to identify the originating trigger. The crdb_internal.forward_dependencies virtual table has been updated to report dependedonby_type='trigger' when the trigger_id is set, instead of 'view'. Resolves: cockroachdb#147801 Epic: CRDB-42942 Release note: None
b5aeee8 to
741f0fe
Compare
Previously, trigger dependencies in DependedOnBy had TriggerID=0, making them indistinguishable from view dependencies. This caused issues when dropping a trigger that shared a referenced table with another trigger, as the drop would incorrectly remove the shared backref. This commit adds a migration that repairs existing trigger backrefs by: 1. Iterating through all tables with triggers in each database 2. For each trigger's DependsOn references, finding the corresponding backref with TriggerID=0 and setting the correct TriggerID 3. If multiple triggers reference the same table (which previously shared a single backref), creating separate backrefs for each trigger The migration processes descriptors in batches of 100 to avoid overly large transactions. Epic: CRDB-42942 Release note: none
741f0fe to
c8244d0
Compare
these were getting tracked before, but just were categorized the same as views. i ran the RSW test under stress and it seems fine as-is. |
Potential Bug(s) DetectedThe three-stage Claude Code analysis has identified potential bug(s) in this PR that may warrant investigation. Next Steps: Note: When viewing the workflow output, scroll to the bottom to find the Final Analysis Summary. After you review the findings, please tag the issue as follows:
|
sql: identify trigger-based table dependencies in backreferences
Previously, when a trigger function referenced another table, the backreference in DependedOnBy was structurally identical to view dependencies. This made it impossible to distinguish trigger dependencies from view dependencies when inspecting crdb_internal.forward_dependencies.
This commit adds a trigger_id field to TableDescriptor_Reference in the protobuf schema. When creating backreferences for trigger dependencies, we now set the trigger_id to identify the originating trigger. The crdb_internal.forward_dependencies virtual table has been updated to report dependedonby_type='trigger' when the trigger_id is set, instead of 'view'.
upgrades: add migration to repair trigger backrefs
Previously, trigger dependencies in DependedOnBy had TriggerID=0, making
them indistinguishable from view dependencies. This caused issues when
dropping a trigger that shared a referenced table with another trigger,
as the drop would incorrectly remove the shared backref.
This commit adds a migration that repairs existing trigger backrefs by:
backref with TriggerID=0 and setting the correct TriggerID
a single backref), creating separate backrefs for each trigger
The migration processes descriptors in batches of 100 to avoid overly
large transactions.
Resolves: #147801
Epic: CRDB-42942
Release note: None