Are the rows locked in order in a SELECT … ORDER BY … FOR UPDATE statement?

时光毁灭记忆、已成空白 提交于 2019-12-04 07:27:30

The rows are locked in the order of the ORDER BY clause as it was when the table was scanned.

The query is executed and the rows ordered, then PostgreSQL locks the rows in order. Essentially, ORDER BY happens before FOR UPDATE.

Now it can happen that locking a row blocks because of locks held by concurrent transactions. If that happens, and we are at the READ COMMITTED isolation level, PostgreSQL waits until it can get the lock and then fetches the current version of the row, which it locks.

If the concurrent transaction modified the columns which define the ordering, the final result will not be in the order defined by ORDER BY.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!