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

[BUG] 'gen_random_uuid()' Constraint Error: Duplicate key #331

Closed
wyhaya opened this issue Jun 7, 2024 · 2 comments · Fixed by duckdb/duckdb#15482
Closed

[BUG] 'gen_random_uuid()' Constraint Error: Duplicate key #331

wyhaya opened this issue Jun 7, 2024 · 2 comments · Fixed by duckdb/duckdb#15482

Comments

@wyhaya
Copy link

wyhaya commented Jun 7, 2024

[dependencies]
duckdb = { version = "0.10.2", features = ["bundled"] }
use duckdb::Connection;

fn main() {
    let conn = Connection::open_in_memory().unwrap();
    conn.execute("CREATE TABLE test (id uuid primary key default gen_random_uuid())", []).unwrap();
    for _ in 0..999999 {
        conn.execute("insert into test default values", []).unwrap();
    }
}
cargo run --release
thread 'main' panicked at src/main.rs:12:61:
called `Result::unwrap()` on an `Err` value: DuckDBFailure(Error { code: Unknown, extended_code: 1 }, 
Some("Constraint Error: Duplicate key \"id: 620e391f-bf1c-412e-9fc3-917224f99a1c\" violates primary key constraint.
If this is an unexpected constraint violation please double check with the known index limitations section in our documentation (https://duckdb.org/docs/sql/indexes)."))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

In fact, I'm not quite sure whether this bug should belong to duckdb-rs, but I'm unfamiliar with C++, and I can't check it further, so I posted it here.

macOS 14.5
select version() -> v0.10.2

@Swoorup
Copy link
Contributor

Swoorup commented Jun 8, 2024

Sounds like a problem on https://github.com/duckdb/duckdb

@taniabogatsch
Copy link

Sounds like a problem on https://github.com/duckdb/duckdb

Yes, I could reproduce it with a simple SQL .test. I'll open an issue for us to pick this up. 👍
Linking this related issue: marcboeker/go-duckdb#339.

statement ok
CREATE TABLE test (id UUID PRIMARY KEY DEFAULT gen_random_uuid());

concurrentloop i 0 20

loop j 0 10000

statement ok
INSERT INTO test DEFAULT VALUES;

endloop

endloop
(venv) tania@motorbook duckdb % build/release/test/unittest test/temp.test
Filters: test/temp.test
[0/1] (0%): test/temp.test                                                      ================================================================================
Query unexpectedly failed! (test/temp.test:11)!
================================================================================
INSERT INTO test DEFAULT VALUES;
================================================================================
Constraint Error: Duplicate key "id: 7c047142-09fd-4666-8381-5794fc888e23" violates primary key constraint.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
unittest is a Catch v2.13.7 host application.
Run with -? for options

-------------------------------------------------------------------------------
test/temp.test
-------------------------------------------------------------------------------
/Users/tania/DuckDB/duckdb/test/sqlite/test_sqllogictest.cpp:210
...............................................................................

test/temp.test:11: FAILED:
explicitly with message:
  0

[1/1] (100%): test/temp.test                                                    
===============================================================================
test cases:     1 |     0 passed | 1 failed
assertions: 58757 | 58756 passed | 1 failed

carlopi added a commit to carlopi/duckdb that referenced this issue Dec 27, 2024
This is connected to raising RandomEngine to use 64bit state, but initialization need to be done on full
range otherwise entropy is limited when many repeated statement are executed.

Test case provided by @taniabogatsch

Fixes duckdb/duckdb-rs#331
Fixes marcboeker/go-duckdb#339
carlopi added a commit to carlopi/duckdb that referenced this issue Dec 27, 2024
This is connected to raising RandomEngine to use 64bit state, but initialization need to be done on full
range otherwise entropy is limited when many repeated statement are executed.

Test case provided by @taniabogatsch

Fixes duckdb/duckdb-rs#331
Fixes marcboeker/go-duckdb#339
carlopi added a commit to carlopi/duckdb that referenced this issue Dec 27, 2024
This is connected to raising RandomEngine to use 64bit state, see duckdb#13920, but
initialization need to be done on full range otherwise entropy is limited when many repeated statement are executed.

Note that here we only solve the problem for RandomLocalState.
A wider rework of the RandomEngine API migth be also handy.

Test case provided by @taniabogatsch

Fixes duckdb/duckdb-rs#331
Fixes marcboeker/go-duckdb#339

Note that impe
hannes added a commit to duckdb/duckdb that referenced this issue Dec 30, 2024
This is connected to raising RandomEngine to use 64bit state, see
#13920, but initialization need to
be done on full range otherwise entropy is limited when many repeated
statement are executed.

Note that here we only solve the problem for RandomLocalState.
A wider rework of the RandomEngine API would also be also handy, since
currently it takes a int64_t that can be either invalid (-1) or valid
(>=0), but out of scope here given interactions with sampling PRs make
it a larger change.

Test case by @taniabogatsch

Fixes duckdb/duckdb-rs#331
Fixes marcboeker/go-duckdb#339
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