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

Inconsistent enforcement of primary key constraints in transaction #2241

Closed
2 tasks done
akbertram opened this issue Sep 3, 2021 · 8 comments
Closed
2 tasks done

Comments

@akbertram
Copy link
Contributor

What does happen?
When inserting, deleting, and then inserting again a row with a single primary key within a transaction, the final statement results in:

Error: Constraint Error: PRIMARY KEY or UNIQUE constraint violated: duplicated key

What should happen?
Primary key enforcement should reflect the current state of the database within the transaction.

To Reproduce

begin transaction;
create table test (id text primary key);
insert into test values ('Bob');
delete from test where id = 'Bob';
insert into test values ('Bob');
commit;

Environment (please complete the following information):

  • OS: Linux/Ubuntu 20.04
  • DuckDB Version: 0.2.7

Before submitting

  • Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?
  • Have you tried this on the latest master branch?
@hawkfish
Copy link
Contributor

hawkfish commented Sep 9, 2021

Looks like the key is still in the transaction's copy of the index for the second insert.

@Mytherin
Copy link
Collaborator

This seems related to #1631.

@hawkfish
Copy link
Contributor

LocalStorage::Delete does not seem to check the index at all. Since the change is in transaction-local storage, how easy is it to fix this without causing problems with the other transitions' view of the index?

@Mytherin
Copy link
Collaborator

LocalStorage::Delete does not seem to check the index at all. Since the change is in transaction-local storage, how easy is it to fix this without causing problems with the other transitions' view of the index?

Since the local storage is completely isolated from other transactions this specific set of queries should not be so difficult to solve, as LocalStorage::Delete could simply delete data inside the transaction-local indexes. This would only work if the insert and delete occur in the same transaction, however.

hawkfish pushed a commit to hawkfish/duckdb that referenced this issue Sep 17, 2021
Delete rows from local storage indexes
as part of transacted deletion.
Mytherin added a commit that referenced this issue Sep 19, 2021
@hawkfish
Copy link
Contributor

@akbertram Can you check whether this fixes your issue?

@akbertram
Copy link
Contributor Author

@hawkfish Thanks! I have DuckDb building locally but not the JDBC connector apparently. Can you point me to any instructions on how to build the java library?

@hawkfish
Copy link
Contributor

I think all you need to do is this:

  • To build optional components, use the flags defined in the Makefile, e.g. to build the JDBC driver, run BUILD_JDBC=1 make.

@akbertram
Copy link
Contributor Author

This is working perfectly in 0.5.0, thanks!

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

3 participants