You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #45714 [Messenger] Fix cannot select FOR UPDATE from view on Oracle (rjd22)
This PR was merged into the 4.4 branch.
Discussion
----------
[Messenger] Fix cannot select FOR UPDATE from view on Oracle
| Q | A
| ------------- | ---
| Branch? | 4.4 <!-- see below -->
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix#33718
| License | MIT
I realize this solution is quite getto. I hope to get some feedback on it so we can solve this oracle issue properly but ATM this is a good starting point to reach a proper solution.
For this reason I didn't add tests yet.
What happens is that Oracle doesn't like query's that combine ROWNUM and FOR UPDATE. To solve this the query needs to be wrapped in a subquery that limits the results by ID so:
```sql
SELECT a.* FROM (
SELECT m.*
FROM messenger_messages m
WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?)
ORDER BY available_at ASC
) a WHERE ROWNUM <= 1 FOR UPDATE;
```
becomes:
```sql
SELECT * FROM messenger_messages WHERE id in (
SELECT a.id FROM (
SELECT m.*
FROM messenger_messages m
WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?)
ORDER BY available_at ASC
) a WHERE ROWNUM <= 1
) FOR UPDATE;
```
I don't really know another way to solve this better. But feel free to nitpick at my solution.
Commits
-------
d4a695f [Messenger] Fix cannot select FOR UPDATE from view on Oracle
0 commit comments