-
Notifications
You must be signed in to change notification settings - Fork 3.9k
sql/kv: support FOR NO KEY UPDATE and FOR KEY SHARE #52420
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
Comments
#46758 doesn't seem to talk about this sentinel column. Maybe it's a great idea; can you say more? I forgot if there always is a sentinel col fam; is there? Any downsides here? Can you remind me when this col fam is written to? |
This was actually tracked in #30852, and it looks like @RaduBerinde already addressed it in #42572! So the general idea is to essentially do what we do in #30624 – put all dynamic columns in a table into their own column families.
Kind of. By default, it includes every column in the table. So by default, there's a 1:1 mapping between rows and keys.
Two big downsides: inserting and deleting rows from the table now needs to touch multiple keys and scanning rows from the table now needs to scan over multiple keys. There's also the associated bookkeeping cost of extra kvs. |
Interestingly, VLDB 2020's best paper discusses contended in-memory transaction processing and references an optimization in OCC and MVCC systems that they call "timestamp splitting". The optimization splits the read and write timestamps of database records to avoid false contention between transactions that touch mutually exclusive subsets of columns in a record. It ends up being exactly what we're talking about here with column families. They even reference using "timestamp splitting" in YCSB and TPC-C, which we did in #32704 and #30624, respectively. |
Uh oh!
There was an error while loading. Please reload this page.
Originally tracked in #40205.
We added support for the
FOR UPDATE
explicit locking mode in #45701. In doing so, we aliasedFOR NO KEY UPDATE
toFOR UPDATE
andFOR KEY SHARE
toFOR SHARE
.Context: https://www.postgresql.org/docs/current/explicit-locking.html
Motivation
The
FOR NO KEY UPDATE
andFOR KEY SHARE
locking modes were added to PostgreSQL in postgres/postgres@0ac5ad5. The motivation for these weaker locking modes is to reduce contention between updates to an existing row and foreign key lookups (existence checks) on existing rows.This is an important optimization for certain workloads, and we should explore adding it to CockroachDB. Doing so would require some work in SQL to properly expose these as explicit locking modes and to use these weaker locking modes where possible implicitly (e.g. during value-only UPDATEs and during FK checks). Doing so would also require a lot of work in KV to expose and properly obey these weaker locking modes. This would require changes to the lock-table, to the latch manager, and to the timestamp cache.
Alternatives: Column Families
Column families can currently be used to a similar effect. We are currently exploring (#46758) the use of GetRequests directed at only the sentinel column family of a row when performing foreign key lookups. If/when we make that change, expressing each row as a first column family containing all columns in the primary key and a second column family containing all other columns would have the same effect as if we made this larger change.
Jira issue: CRDB-3949
The text was updated successfully, but these errors were encountered: