Page 1 of 1

Key violation

Posted: Thu Aug 24, 2017 8:48 pm
by dportas
V: 3.007, OS: Windows 10

When I declare multiple keys it appears that only the first of the keys is enforced.

VAR foo REAL RELATION {a INTEGER, b INTEGER} KEY {a} KEY {b};

INSERT foo RELATION {TUPLE {a 1, b 1}};
INSERT foo RELATION {TUPLE {a 2, b 1}};

result:

a b
1 1
2 1

Re: Key violation

Posted: Fri Aug 25, 2017 1:31 am
by steved
Use D_INSERT:
D_INSERT foo RELATION {TUPLE {a 1, b 1}};
D_INSERT foo RELATION {TUPLE {a 2, b 1}};

ERROR: RS0232: Inserting tuple would violate uniqueness constraint of KEY {b}

stephen

Re: Key violation

Posted: Fri Aug 25, 2017 6:09 am
by dportas
Thanks, D_INSERT does work as an alternative workaround. I'm more interested in reporting the bug than in finding workarounds. I wonder what other operations might also be affected if constraints aren't being enforced correctly.

Re: Key violation

Posted: Sun Aug 27, 2017 9:03 am
by Dave
dportas wrote: Fri Aug 25, 2017 6:09 am Thanks, D_INSERT does work as an alternative workaround. I'm more interested in reporting the bug than in finding workarounds. I wonder what other operations might also be affected if constraints aren't being enforced correctly.
I've added this to my to-do list.

Note that KEY constraints are handled differently from other explicit constraints -- i.e., those declared with CONSTRAINT -- so a bug in KEY constraints does not imply a bug in CONSTRAINTs in general. Of course, there might be bugs in CONSTRAINTs in general; I can only state with certainty that they're not related to KEY constraints!

Notably (and perhaps annoyingly), INSERT correctly reports that it is not inserting a tuple, but does so anyway. E.g.:

var myvar5 real relation {x int, y int} key {x} key {y};

Ok.

insert myvar5 rel {tup {x 1, y 1}};

NOTICE: Inserted 1 tuple.

Ok.

insert myvar5 rel {tup {x 2, y 1}};

NOTICE: Inserted 0 tuples.

Ok.

myvar5
RELATION {x INTEGER, y INTEGER} {
TUPLE {x 1, y 1},
TUPLE {x 2, y 1}
}

Re: Key violation

Posted: Sun Aug 27, 2017 9:52 am
by Dave
I've corrected this for the forthcoming v3.008 update.

Re: Key violation

Posted: Sun Aug 27, 2017 12:09 pm
by Dave
The version 3.008 update that fixes this bug is now available for download from http://reldb.org

Re: Key violation

Posted: Mon Aug 28, 2017 8:25 am
by dportas
That was fast work! It has fixed the problem for me. Thanks.