Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify semantics of locks wrt SELECT/READ #1614

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

beckermarc
Copy link
Contributor

There is a common misunderstanding that pessimistic locking, prevents plain select queries without locks.

See also HANA docs https://help.sap.com/docs/SAP_HANA_PLATFORM/4fe29514fd584807ac9f2a04f6754767/20fcf24075191014a89e9dc7b8408b26.html

See also PostgreSQL docs
https://www.postgresql.org/docs/current/explicit-locking.html#LOCKING-ROWS

See also H2 docs
https://www.h2database.com/html/commands.html#select

There is a common misunderstanding that pessimistic locking, prevents select queries without locks.

See also HANA docs https://help.sap.com/docs/SAP_HANA_PLATFORM/4fe29514fd584807ac9f2a04f6754767/20fcf24075191014a89e9dc7b8408b26.html
Copy link
Contributor

@agoerler agoerler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should have a table

state select without lock select with shared lock select with exclusive lock / update
not locked passes -> not locked passes -> shared lock passes -> exclusive lock
shared lock passes -> not locked passes -> shared lock passes -> exclusive lock
exclusive lock passes -> not locked passes -> exclusive lock waits -> exclusive lock

guides/providing-services.md Outdated Show resolved Hide resolved
guides/providing-services.md Outdated Show resolved Hide resolved
@beckermarc
Copy link
Contributor Author

Maybe we should have a table

Maybe, but I don't think your table is correct, is it?

  • "shared lock" / "select with exclusive lock / update" should be "waits"
  • "exclusive lock" / "select with shared lock" should be "waits"

@agoerler
Copy link
Contributor

agoerler commented Feb 3, 2025

Maybe we should have a table

Maybe, but I don't think your table is correct, is it?

  • "shared lock" / "select with exclusive lock / update" should be "waits"

Yes, you are right. A shared lock can be promoted to an exclusive lock. But I think only in the transaction where the lock was originally created, I think. Others will wait.

  • "exclusive lock" / "select with shared lock" should be "waits"

Yes, you are right.

@johannes-vogel
Copy link
Contributor

Should we also link the db documentation?

@beckermarc
Copy link
Contributor Author

The db docs are also rather cryptic sometimes and not so clear in my opinion. Therefore not sure if that provides a lot of additional value. Do you think they would be helpful after taking a look at them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants