The naive test for equality

From: David Cressey <david.cressey_at_earthlink.net>
Date: Sun, 31 Jul 2005 18:16:00 GMT
Message-ID: <Az8He.11756$oZ.2638_at_newsread2.news.atl.earthlink.net>



There's been discussion about whether the relational engine does or does not understand equality. I'd like to suggest that the relational engine does understand the "what" of equality testing, but is sometimes naive about the "how". Before I go any further with this, let me first describe a naive test for equality.

Here's how it works:

Every value has a type, and is represented by a bit string.

If values A and B are to be tested for equality, the first step is to see if the type of A and the type of B are the same. If not, then an error flag is raised, and the test returns FALSE.

If A and B are of the same type, then the length of the two bitstrings are compared. If the lengths are different, the test returns FALSE.

If the types are the same, and the lengths are the same, the bit strings are compared, one bit at a time. If any corresponding bit is different in A and B, the test returns FALSE.

Otherwise, the test returns TRUE.

Well, what makes me call this test naive? It's naive because it has tested the two representations for equality, and not the two values. The naive test will always work correctly, provided there are no synonyms and no homonyms. There are a lot of datatypes that have these two features, and for those datatypes, the naive test works just fine.

I'm going to sidestep the issue of homonyms.

What if we had a type engine with the following interesting feature: if we ask it to test "humid" and "moist" for equality, it returns TRUE. I'm going to sidestep the question of whether such a type engine is mathematically valid, and the question of how it is implemented.

The point is that the naive test fails to deliver the same answer as the type engine does, because it doesn't recognize "humid" and "moist" as synonyms.

Here's where the relational engine may be able to use the "what" of the equality test, but can't grasp the "how".

There's more, but I'll leave here for now. Received on Sun Jul 31 2005 - 20:16:00 CEST

Original text of this message