relation comparison in WHERE clause gives wrong result

This forum is to report technical problems with Rel.
Post Reply
HughDarwen
Posts: 121
Joined: Sat May 24, 2008 4:49 pm

relation comparison in WHERE clause gives wrong result

Post 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
HughDarwen
Posts: 121
Joined: Sat May 24, 2008 4:49 pm

Re: relation comparison in WHERE clause gives wrong result

Post 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
Dave
Site Admin
Posts: 368
Joined: Sun Nov 27, 2005 7:19 pm

Re: relation comparison in WHERE clause gives wrong result

Post by Dave »

I should be able to fix this for the next update.
Dave
Site Admin
Posts: 368
Joined: Sun Nov 27, 2005 7:19 pm

Re: relation comparison in WHERE clause gives wrong result

Post 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.
Dave
Site Admin
Posts: 368
Joined: Sun Nov 27, 2005 7:19 pm

Re: relation comparison in WHERE clause gives wrong result

Post 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.
Post Reply