(text/x-fossil-wiki)
The logic that computes DISTINCT sometimes thinks that a zeroblob() and a
blob of all zeros are different when they should be the same. The following
query illustrates the problem:
<blockquote><verbatim>
CREATE TABLE t1(a INTEGER);
INSERT INTO t1 VALUES(3);
INSERT INTO t1 VALUES(2);
INSERT INTO t1 VALUES(1);
INSERT INTO t1 VALUES(2);
INSERT INTO t1 VALUES(3);
CREATE TABLE t2(x);
INSERT INTO t2
SELECT DISTINCT
CASE a WHEN 1 THEN x'0000000000'
WHEN 2 THEN zeroblob(5)
ELSE 'xyzzy' END
FROM t1;
SELECT quote(x) FROM t2;
</verbatim></blockquote>
The final output above should only generate two rows: x'0000000000' and 'xyzzy'
since x'0000000000' and zeroblob(5) are logically equivalent. But it ends up
generating three rows. There are two x'0000000000' values in the output.
Bisecting shows that this problem was introduced by check-in
[45e581bff7a75db] on [2011-07-02] for SQLite version 3.7.8.
This problem was discovered by the developers during code analysis and
has never been reported in the wild.
|