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

Use random ROWID for inserted rows #12

Closed
losfair opened this issue Oct 4, 2022 · 2 comments · Fixed by #56
Closed

Use random ROWID for inserted rows #12

losfair opened this issue Oct 4, 2022 · 2 comments · Fixed by #56
Assignees

Comments

@losfair
Copy link

losfair commented Oct 4, 2022

With an optimistic VFS, sequentially increasing ROWIDs is a primary source of contention, and causes significant INSERT slowdown in my benchmark. We should provide a table-level option to allocate ROWIDs randomly.

This is possible in upstream SQLite by having a special row with rowid == max(int64). But not all applications like this special row.

The syntax might look like the WITHOUT ROWID table one:

CREATE TABLE t (...) RANDOM ROWID;
@AngeloR
Copy link

AngeloR commented Oct 4, 2022

Wouldn't exclusively random id allocation require consensus across the cluster anyway leading to some lock?

I would be in favour of some kind of vector clock based addition to the randomized row id to avoid this - that way we wouldn't be totally reliant on randomness of one machine dictating id's across the cluster.

We could go a step further and just introduce support for uuid7, but then we're just relying on system clock which is also a potential issue..

@losfair
Copy link
Author

losfair commented Oct 4, 2022

@AngeloR

Wouldn't exclusively random id allocation require consensus across the cluster anyway leading to some lock?

In an optimistic transactional distributed storage there is either no lock during data plane operation (FoundationDB) or a 2PC lock as an implementation detail (TiKV). The behavior exposed to the client is retry instead of lock: when there does not exist a possible serializable (and in some systems, linearizable) order between two concurrent transactions, one of them is rejected and the client has to retry.

Counter increment is a typical case: there never exists a serializable order for two concurrent transactions that both read the counter, increment it by one, and write it back.

Exclusive random ID though only generates a conflict when two concurrent transactions are attempting to acquire the same ID.

@psarna psarna self-assigned this Oct 27, 2022
psarna added a commit to psarna/libsql that referenced this issue Oct 27, 2022
With the ney RANDOM ROWID keywords, a table can explicitly
state that it wants its rowid to be generated randomly,
not consecutively, without having to previously create a sentinel
record with rowid == max(i64).

Fixes tursodatabase#12
psarna added a commit to psarna/libsql that referenced this issue Oct 27, 2022
With the ney RANDOM ROWID keywords, a table can explicitly
state that it wants its rowid to be generated randomly,
not consecutively, without having to previously create a sentinel
record with rowid == max(i64).

Fixes tursodatabase#12
psarna added a commit to psarna/libsql that referenced this issue Oct 27, 2022
With the new RANDOM ROWID keywords, a table can explicitly
state that it wants its rowid to be generated randomly,
not consecutively, without having to previously create a sentinel
record with rowid == max(i64).

Fixes tursodatabase#12
psarna added a commit to psarna/libsql that referenced this issue Oct 27, 2022
With the new RANDOM ROWID keywords, a table can explicitly
state that it wants its rowid to be generated randomly,
not consecutively, without having to previously create a sentinel
record with rowid == max(i64).

Fixes tursodatabase#12
psarna added a commit to psarna/libsql that referenced this issue Oct 28, 2022
With the new RANDOM ROWID keywords, a table can explicitly
state that it wants its rowid to be generated randomly,
not consecutively, without having to previously create a sentinel
record with rowid == max(i64).
RANDOM ROWID is mutually exclusive with WITHOUT ROWID,
and cannot be combined with AUTOINCREMENT primary key.

Fixes tursodatabase#12
penberg added a commit that referenced this issue Nov 7, 2022
With the new RANDOM ROWID keywords, a table can explicitly state that it
wants its rowid to be generated randomly, not consecutively, without
having to previously create a sentinel record with rowid == max(i64).
RANDOM ROWID is mutually exclusive with WITHOUT ROWID, and cannot be
combined with AUTOINCREMENT primary key.

This series come with tests.

Fixes #12
penberg added a commit to penberg/libsql that referenced this issue Jun 19, 2023
mvcc: implement a stub for reading from specified rowid
MarinPostma added a commit that referenced this issue Oct 17, 2023
Add support for queries over HTTP
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 a pull request may close this issue.

3 participants