UNPKG

bc-code-intelligence-mcp

Version:

BC Code Intelligence MCP Server - Complete Specialist Bundle with AI-driven expert consultation, seamless handoffs, and context-preserving workflows

112 lines (83 loc) 5.67 kB
--- title: "DeleteAll Trigger Execution" domain: "sam-coder" difficulty: "advanced" bc_versions: "14+" tags: ["deleteall", "triggers", "ondelete", "execution-flow"] prerequisites: ["deleteall-method-usage", "table-triggers", "transaction-management"] samples: "samples/deleteall-triggers.md" --- # DeleteAll Trigger Execution ## Overview DeleteAll method execution in BC follows a specific trigger execution pattern that ensures business logic consistency while processing bulk deletions. Understanding this execution flow is crucial for designing proper OnDelete triggers and predicting system behavior during bulk operations. **Core Behavior**: DeleteAll executes OnDelete triggers for every individual record, maintaining complete business logic enforcement at the cost of performance. **Execution Pattern**: Sequential processing of each record with full trigger execution, validation, and related table operations. ## Trigger Execution Flow ### Individual Record Processing DeleteAll processes records sequentially, executing the complete OnDelete trigger chain for each record. This ensures business logic consistency but creates performance overhead proportional to record count and trigger complexity. ### Trigger Execution Sequence 1. **Record Selection**: DeleteAll identifies records matching filter criteria 2. **OnDelete Trigger Execution**: Full trigger logic executes for each record 3. **Validation Processing**: All validation logic and business rules execute 4. **Related Table Operations**: Cascade deletes and related table updates occur 5. **Transaction Management**: Individual record operations within transaction boundaries ### Business Logic Preservation OnDelete triggers execute with full access to record context, related data, and system state. This enables complex business logic including audit logging, cascade operations, and custom validation rules. ## Performance Implications ### Execution Overhead Sources - Individual record processing prevents batch optimization - OnDelete trigger execution adds computational overhead per record - Related table operations multiply database interactions - Validation logic extends processing time per record - Transaction management creates additional resource utilization ### Scalability Characteristics - Linear performance degradation with record count increase - Multiplicative impact from complex OnDelete trigger logic - Network round-trip multiplication with related table operations - Memory usage accumulation with trigger execution complexity ## Trigger Design Considerations ### Performance-Conscious Trigger Design - Minimize database operations within OnDelete triggers - Use efficient queries and avoid complex calculations - Implement conditional logic to skip unnecessary processing - Consider batch operations for related table updates where possible ### Business Logic Optimization - Separate essential validation from optional logging operations - Use TryFunction patterns for non-critical operations that might fail - Implement proper error handling to prevent cascade failures - Design triggers to be testable and maintainable ### Related Table Management - Design efficient cascade delete patterns - Minimize related table lookups and updates - Use appropriate transaction boundaries for related operations - Consider using temporary tables for complex related data processing ## Common Implementation Patterns ### Audit Trail Implementation OnDelete triggers commonly implement audit trail logging by capturing deleted record information before removal. Design efficient logging procedures that minimize performance impact. ### Cascade Delete Operations Related table cleanup through OnDelete triggers ensures referential integrity. Implement cascade patterns that balance completeness with performance requirements. ### Validation and Business Rules OnDelete triggers enforce business rules during deletion operations. Design validation logic that fails fast and provides meaningful error messages. ## Best Practices ### Trigger Development - Keep OnDelete triggers focused on essential business logic - Avoid complex calculations or external system calls in triggers - Implement proper error handling and recovery mechanisms - Design triggers to be testable in isolation ### Performance Management - Profile trigger execution under realistic data volumes - Monitor system resource utilization during DeleteAll operations - Implement appropriate timeout and cancellation mechanisms - Consider alternative approaches for performance-critical scenarios ### Testing and Validation - Test OnDelete triggers with various record states and conditions - Validate trigger behavior under high-volume deletion scenarios - Verify proper error handling and rollback behavior - Test concurrent operation impact on trigger execution ## Anti-Patterns ### Performance-Blind Trigger Design **Problematic Pattern**: Implementing complex OnDelete triggers without considering DeleteAll performance impact. Complex trigger logic compounds performance overhead and can make bulk deletions prohibitively slow. ### Inadequate Error Handling **Risk Pattern**: OnDelete triggers that fail without proper error handling can leave DeleteAll operations in inconsistent states. Implement comprehensive error handling and rollback mechanisms. ### External System Dependencies **Dangerous Pattern**: OnDelete triggers that depend on external systems create reliability risks. External system failures can block all deletion operations and create operational problems.