db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DERBY-6665) Violation of deferred foreign key not detected on commit
Date Wed, 16 Jul 2014 12:04:05 GMT

    [ https://issues.apache.org/jira/browse/DERBY-6665?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14063414#comment-14063414
] 

Knut Anders Hatlen commented on DERBY-6665:
-------------------------------------------

Conglomerate sharing also causes problems if a FOREIGN KEY constraint and a UNIQUE/PRIMARY
KEY constraint share one physical conglomerate.

See for example this transcript, where the deferred uniqueness check was not performed on
commit:

{noformat}
ij version 10.11
ij> connect 'jdbc:derby:memory:db;create=true';
ij> create table t1(x int primary key);
0 rows inserted/updated/deleted
ij> create table t2(x int primary key initially deferred references t1 initially deferred);
0 rows inserted/updated/deleted
ij> insert into t1 values 1;
1 row inserted/updated/deleted
ij> autocommit off;
ij> insert into t2 values 3;
1 row inserted/updated/deleted
ij> insert into t2 values 3;
1 row inserted/updated/deleted
ij> insert into t1 values 3;
1 row inserted/updated/deleted
ij> commit;
ij> select * from t1;
X          
-----------
1          
3          

2 rows selected
ij> select * from t2;
X          
-----------
3          
3          

2 rows selected
{noformat}

The commit statement should have failed because T2 contained duplicates in its primary key
column.

> Violation of deferred foreign key not detected on commit
> --------------------------------------------------------
>
>                 Key: DERBY-6665
>                 URL: https://issues.apache.org/jira/browse/DERBY-6665
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.11.0.0
>            Reporter: Knut Anders Hatlen
>
> See the following script:
> {noformat}
> ij version 10.11
> ij> connect 'jdbc:derby:memory:db;create=true';
> ij> create table t1(x int primary key);
> 0 rows inserted/updated/deleted
> ij> create table t2(x int primary key);
> 0 rows inserted/updated/deleted
> ij> create table t3(x int, constraint fk1 foreign key (x) references t1 initially
deferred, constraint fk2 foreign key (x) references t2 initially deferred);
> 0 rows inserted/updated/deleted
> ij> insert into t1 values 1;
> 1 row inserted/updated/deleted
> ij> autocommit off;
> ij> insert into t3 values 1;
> 1 row inserted/updated/deleted
> ij> insert into t2 values 1;
> 1 row inserted/updated/deleted
> ij> delete from t1;
> 1 row inserted/updated/deleted
> ij> commit;
> ij> select * from t1;
> X          
> -----------
> 0 rows selected
> ij> select * from t2;
> X          
> -----------
> 1          
> 1 row selected
> ij> select * from t3;
> X          
> -----------
> 1          
> 1 row selected
> {noformat}
> Since T3.X contains a value (1) that is not present in T1, the foreign key FK1 is violated,
and the COMMIT statement should have failed.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message