SQLite Forum

Unexpected result in a equivalence transfer query
Login
Hello developers,

We found a testcase making SQLite outputs the wrong result as follows:

```
CREATE TABLE t1(a INT PRIMARY KEY);
INSERT INTO t1(a) VALUES(1),(2),(3);
CREATE TABLE t2(x INTEGER PRIMARY KEY,y INT);
INSERT INTO t2(y) VALUES(2),(3);
SELECT * FROM t2,t1 WHERE t2.y=t1.a AND t1.a=t2.x; -- expected: empty
SELECT * FROM t2,t1 WHERE likely(t2.y=t1.a) AND unlikely(t1.a=t2.x); -- unexpected: two lines
```

Presumably, this is a legacy issue related to the [recent fix (check-in f1f9b5de)](https://sqlite.org/src/info/f1f9b5de3c59489b) for the [equivalence transfer problem](https://sqlite.org/forum/info/eb8613976acfe23a), you probably forgot to consider the condition using `PRIMARY KEY` when dealing with equivalent transfer optimization.

Looking forward to your reply, further details will be appreciated!