Improve performance of lock_workflows_for_update

This is on various hot paths (especially until #1362 is fixed), and Helmut observed in #1404 (closed) that the previous WHERE workflow_root_id IN ... OR id IN ... query structure caused PostgreSQL to use a relatively slow sequential scan. Use a UNION instead, which does a much faster index-only scan using the combined results of the two subqueries.

Merge request reports

Loading