Page 1 of 1

relation comparison in WHERE clause gives wrong result

Posted: Mon Oct 06, 2008 2:49 pm
by HughDarwen
Using the same example as in my "join on RVA" post, also today:

var EXAM_MARK base relation { StudentId CHAR, CourseId CHAR, Mark INTEGER } key {ALL BUT Mark};
EXAM_MARK := relation { tuple { StudentId 'S1', CourseId 'C1', Mark 85 }, tuple { StudentId 'S1', CourseId 'C2', Mark 49 }, tuple { StudentId 'S2', CourseId 'C1', Mark 49 }, tuple { StudentId 'S3', CourseId 'C3', Mark 66 }, tuple { StudentId 'S4', CourseId 'C1', Mark 93 } };

the following query gave the wrong result, as indicated:

WITH EXAM_MARK{StudentId} as ns,
ns RENAME (StudentId as s1) as ns1,
ns RENAME (StudentId as s2) as ns2,
(ns1 JOIN ns2) as s1s2:
s1s2 where s1<>s2 and (((EXAM_MARK where s1 = StudentId){CourseId})>=
((EXAM_MARK where s2 = StudentId){CourseId}))

RELATION {s1 CHARACTER, s2 CHARACTER} {
TUPLE {s1 "S1", s2 "S2"},
TUPLE {s1 "S1", s2 "S3"},
TUPLE {s1 "S1", s2 "S4"},
TUPLE {s1 "S2", s2 "S1"},
TUPLE {s1 "S2", s2 "S3"},
TUPLE {s1 "S2", s2 "S4"},
TUPLE {s1 "S3", s2 "S1"},
TUPLE {s1 "S3", s2 "S2"},
TUPLE {s1 "S3", s2 "S4"},
TUPLE {s1 "S4", s2 "S1"},
TUPLE {s1 "S4", s2 "S2"},
TUPLE {s1 "S4", s2 "S3"}
}


Note carefully that TUPLE { S1 "S1", s2 "S3" } (the second in the above list) should not be present, as evidenced when I extract the relation comparison from the WHERE clause and evaluate it with "S1" and "S3" in place of the attribute names s1 and s2:

(((EXAM_MARK where 'S1' = StudentId){CourseId})>=
((EXAM_MARK where 'S3' = StudentId){CourseId}))

false

Hugh

Re: relation comparison in WHERE clause gives wrong result

Posted: Mon Oct 06, 2008 2:58 pm
by HughDarwen
I should have added that the following equivalent expression, using GROUP, works fine, as you can see:

(((EXAM_MARK{ALL BUT Mark} group ( {CourseId} AS G1)) RENAME (StudentId AS S1)
join
(EXAM_MARK{ALL BUT Mark} group ( {CourseId} AS G2)) RENAME (StudentId AS S2))
where G1 >= G2 and S1<>S2){ALL BUT G1, G2}

RELATION {S1 CHARACTER, S2 CHARACTER} {
TUPLE {S1 "S1", S2 "S2"},
TUPLE {S1 "S1", S2 "S4"},
TUPLE {S1 "S2", S2 "S4"},
TUPLE {S1 "S4", S2 "S2"}
}


Hugh

Re: relation comparison in WHERE clause gives wrong result

Posted: Tue Oct 07, 2008 7:34 pm
by Dave
I should be able to fix this for the next update.

Re: relation comparison in WHERE clause gives wrong result

Posted: Wed Oct 15, 2008 1:58 am
by Dave
Oddly, this bug appears to be related to the "Complex rel exp causes exception" bug described at http://shark.armchair.mb.ca/~dave/relfo ... ?f=2&t=104. I've fixed the other bugs noted on September 26th and on October 6th, but these two are proving difficult. Both seem to derive from the use of nested WHERE operators in a single expression.

Re: relation comparison in WHERE clause gives wrong result

Posted: Thu Oct 16, 2008 1:25 am
by Dave
Dave wrote:Oddly, this bug appears to be related to the "Complex rel exp causes exception" bug described at http://shark.armchair.mb.ca/~dave/relfo ... ?f=2&t=104. I've fixed the other bugs noted on September 26th and on October 6th, but these two are proving difficult. Both seem to derive from the use of nested WHERE operators in a single expression.
These bugs indeed had a common cause, which I've just corrected. The new update will be released shortly.