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

Can insert DUPLICATE keys in UNIQUE index [CORE3660] #4010

Open
firebird-automations opened this issue Nov 12, 2011 · 4 comments
Open

Can insert DUPLICATE keys in UNIQUE index [CORE3660] #4010

firebird-automations opened this issue Nov 12, 2011 · 4 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Veselin Pavlov (pavlov_v)

Votes: 1

I have several databases working with fb 2.1.3 that has unique constrains on a group of fields but in fact there is duplicated records. Always one of the fields has null value. For example:
CREATE TABLE TABLE1 (
ID INTEGER NOT NULL,
F1 INTEGER,
F2 INTEGER,
F3 INTEGER
);
ALTER TABLE TABLE1 ADD CONSTRAINT UNQ1_TABLE1 UNIQUE (F1, F2, F3);
ALTER TABLE TABLE1 ADD CONSTRAINT PK_TABLE1 PRIMARY KEY (ID);

f1=1, f2=2, f3=null
f1=1, f2=2, f3=null

if I make a query

select * from table1 t where
f1=1
and f2=2
and f3 is null

the result contains only one of the records if the plan is using the "UNQ1_TABLE1" index
the result contains both records if PLAN (T NATURAL) is used.

After backup and restore under FB2.5 the problem persists.
If I drop the index and try to create it again I receive the error: "Invalid insert or update value(s): object columns are constrained - no 2 table rows can have duplicate column values.
attempt to store duplicate value (visible to active transactions) in unique index "UNQ_STOCK"."

I still can not simulate the problem. Only can observe the effect - One of the null values is not exactly null

I saw issue CORE3610, but I'm not sure the issue is the same.

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

> f1=1, f2=2, f3=null
> f1=1, f2=2, f3=null
>
> if I make a query
>
> select * from table1 t where
> f1=1
> and f2=2
> and f3 is null
>
> the result contains only one of the records if the plan is using the "UNQ1_TABLE1" index
> the result contains both records if PLAN (T NATURAL) is used.

Looks like corrupted index. Run gfix -v -fu and show result here, please.

> After backup and restore under FB2.5 the problem persists.

I you mean that at restore FB not allows to create unique index on duplicated data then it is expected behavior. Same as below:

> If I drop the index and try to create it again I receive the error: "Invalid insert or update value(s): object columns are constrained - no 2 table rows can have duplicate column values.
> attempt to store duplicate value (visible to active transactions) in unique index "UNQ_STOCK"."

> One of the null values is not exactly null

I don't understand this. Please explain.

@firebird-automations
Copy link
Collaborator Author

Commented by: Sean Leyne (seanleyne)

Your example does not show a commit between the DDL (table definition, CREATE/ALTER TABLE) statements and the DML (Data manipulation) statements (INSERT...). This is BAD, the 2 classes of statements should NOT be mixed.

Is the commit really missing or is it a typo?

@firebird-automations
Copy link
Collaborator Author

Modified by: Sean Leyne (seanleyne)

Link: This issue relate to CORE3675 [ CORE3675 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

Link: This issue relate to CORE3675 [ CORE3675 ] =>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant