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

Bulk insert into a fresh table from another table does not honor RANDOM ROWID #1046

Closed
avinassh opened this issue Feb 18, 2024 · 1 comment
Closed

Comments

@avinassh
Copy link
Member

This is similar to the bug #929

libsql> create table t(v) random rowid;
libsql> insert into t values (zeroblob(4096)), (zeroblob(4096)), (zeroblob(4096));
libsql> select rowid from t;
2504059759765544415
4456153655816913232
4534292316624990338
libsql>
libsql> create table y(v) random rowid;
libsql> insert into y select * from t;
libsql> select rowid from y;
1
2
3
libsql>

It should not assign consecutive ids, rather random ones.

avinassh added a commit that referenced this issue Feb 19, 2024
Tests added for:

1. VACUUM does not respect RANDOM ROWID - #929
2. Bulk insert into a fresh table does not respect RANDOM ROWID - #1046

In both cases, the table should end up random rowids, but they seem to have sequential ones.
github-merge-queue bot pushed a commit that referenced this issue Feb 19, 2024
…t ops (#1048)

* Add regression tests for random rowid bugs

Tests added for:

1. VACUUM does not respect RANDOM ROWID - #929
2. Bulk insert into a fresh table does not respect RANDOM ROWID - #1046

In both cases, the table should end up random rowids, but they seem to have sequential ones.

* bugfix: pass `regNextRowid` to `OP_NewRowid` call in `xferOptimization`

The register `regNextRowid` contains the `LIBSQL_RANDOM_ROWID_MARKER` value
which tells the VDBE to use a random value for row ids. The method `xferOptimization`
is used in `VACUUM` and bulk insert routines where data from one table is
inserted in another. Since the data is inserted in a loop, it checks for
max rowid once and then keeps inserting it serially. Hence we pass the marker
in each call, so that random id is generated.
@avinassh
Copy link
Member Author

closed by #1048

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

No branches or pull requests

1 participant