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

Check constraints don't operate in system context [CORE470] #816

Open
firebird-automations opened this issue Jun 15, 2004 · 4 comments
Open

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: johnsparrowuk (johnsparrowuk)

SFID: 973159#⁠
Submitted By: johnsparrowuk

Check constraints only see committed data from other
transactions, when they should dirty-read to be
consistent with index behaviour (operate in system
transaction context?).
For example:

create table T (pk integer not null primary key, i integer
not null);

ALTER TABLE T ADD CONSTRAINT Unique_I_T CHECK
(not exists (select pk from T where new.i = T.i and pk
<> http://new.pk)

(snapshot transactions)
Trans 1:
insert into T values (1,1); WORKS FINE

Trans 2:
insert into T values (2,2); WORKS FINE
insert into T values (3,2); CHECK VIOL, COOL!
insert into T values (3,1); WORKS, OH DEAR!
commit

Trans 1:
commit

Start new trans:
select * from T
1,1
2,2
3,1 (violation of check constraint)

Example is simplistic, but more of a problem when
checking for overlapping periods (for example) which
can't have unique indexes applied.

@firebird-automations
Copy link
Collaborator Author

Commented by: Alice F. Bird (firebirds)

Date: 2004-06-15 18:37
Sender: johnsparrowuk
Logged In: YES
user_id=205339

Appologies for using the term 'dirty read'! I mean 'operate in
system context'. You say Potato, I say...
John

@firebird-automations
Copy link
Collaborator Author

Modified by: Alice F. Bird (firebirds)

description: SFID: 973159#⁠
Submitted By: johnsparrowuk

Check constraints only see committed data from other
transactions, when they should dirty-read to be
consistent with index behaviour (operate in system
transaction context?).
For example:

create table T (pk integer not null primary key, i integer
not null);

ALTER TABLE T ADD CONSTRAINT Unique_I_T CHECK
(not exists (select pk from T where new.i = T.i and pk
<> http://new.pk)

(snapshot transactions)
Trans 1:
insert into T values (1,1); WORKS FINE

Trans 2:
insert into T values (2,2); WORKS FINE
insert into T values (3,2); CHECK VIOL, COOL!
insert into T values (3,1); WORKS, OH DEAR!
commit

Trans 1:
commit

Start new trans:
select * from T
1,1
2,2
3,1 (violation of check constraint)

Example is simplistic, but more of a problem when
checking for overlapping periods (for example) which
can't have unique indexes applied.

=>

SFID: 973159#⁠
Submitted By: johnsparrowuk

Check constraints only see committed data from other
transactions, when they should dirty-read to be
consistent with index behaviour (operate in system
transaction context?).
For example:

create table T (pk integer not null primary key, i integer
not null);

ALTER TABLE T ADD CONSTRAINT Unique_I_T CHECK
(not exists (select pk from T where new.i = T.i and pk
<> http://new.pk)

(snapshot transactions)
Trans 1:
insert into T values (1,1); WORKS FINE

Trans 2:
insert into T values (2,2); WORKS FINE
insert into T values (3,2); CHECK VIOL, COOL!
insert into T values (3,1); WORKS, OH DEAR!
commit

Trans 1:
commit

Start new trans:
select * from T
1,1
2,2
3,1 (violation of check constraint)

Example is simplistic, but more of a problem when
checking for overlapping periods (for example) which
can't have unique indexes applied.

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Workflow: jira [ 10494 ] => Firebird [ 14786 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: arni (arni)

>>CHECK (not exists (select pk from T where new.i = T.i and pk <> http://new.pk)

This is very, very bad practice.
You should use in CHECK constraints only the fields of same table, not from other.
The really bug is situation when you are allowed to use such references in CHECK condition.

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