mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-07-20 18:12:25 -04:00
The DELETE WHERE EventId IN (?,?,...) is intentional: it locks each row via the primary key, keeping the lock range minimal and preserving the canonical lock order that this PR's deadlock fix relies on. But a single IN-list with tens of thousands of placeholders (Events_Month after weeks of accumulation) can hit max_allowed_packet and max_prepared_stmt_count. Split the EventId list into 1000-row batches and loop. PK-based locking is preserved; SQL/packet size stays bounded. Switching to a predicate- based DELETE would re-introduce range locks on the bucket index and undo the deadlock work.