Skip to content

workerutil: Remove second query in dequeue

Warren Gifford requested to merge ef/collapse-dequeue into main

Created by: efritz

We previously were doing a SELECT FOR UPDATE/UPDATE query followed by a SELECT query outside of a transaction. This PR combines the two queries into one.

There were some hurdles, which is why there were two queries in the first place. If you have an UPDATE query in a CTE, any selects of the updated row in the same query will see only old values. We also can't simply use RETURNING from the update to return new values as the column expressions and view name may be configured to pull from a different table or with complicated join conditions.

This PR combines the queries by frankenstein-modifying the column expressions to be replaced by the inlined updated value, if it's an updated column. Outstanding caveats: if users do something like supply a select expression like NOW() - w.process_after + '1 day'::interval then that won't quite work. We may want to replace all occurrences here instead.

Merge request reports

Loading