SQLite Forum

Affinity problem existing in functions like likely()
Login

Affinity problem existing in functions like likely()

(1.1) By Wang Ke (krking) on 2021-06-14 12:08:47 edited from 1.0 [source]

Hello all,

Consider the following behaviors:

CREATE TABLE t0 (c0 REAL);
INSERT INTO t0(c0) VALUES (0);
INSERT INTO t0(c0) VALUES (1);
CREATE UNIQUE INDEX idx ON t0(likely(c0));

SELECT count(*) FROM t0 WHERE c0 GLOB c0; --2
SELECT count(*) FROM t0 WHERE likely(c0) GLOB c0; --2
SELECT count(*) FROM t0 INDEXED BY idx WHERE c0 GLOB c0; --2
SELECT count(*) FROM t0 INDEXED BY idx WHERE likely(c0) GLOB c0; --0
SELECT count(*) FROM t0 INDEXED BY idx WHERE likely(c0) LIKE c0; --0
SELECT count(*) FROM t0 INDEXED BY idx WHERE CAST(likely(c0) AS TEXT) GLOB CAST(c0 AS TEXT); --0
SELECT count(*) FROM t0 INDEXED BY idx WHERE CAST(likely(c0) AS TEXT) LIKE CAST(c0 AS TEXT); --0

By specifying the index used and applying the likely() function, we can get unexpected results, indicating that there may be some problems concerning likely(). Besides, we also find opcode RealAffinity missing in this query.

Through bisecting, we found that the problem may be introduced in 44578865fa.

I'd like to know whether it's a bug or a feature.

Thank you!

(2) By Richard Hipp (drh) on 2021-06-14 14:02:02 in reply to 1.1 [link] [source]

(3) By Wang Ke (krking) on 2021-06-14 14:10:29 in reply to 2 [link] [source]

Thank you for the fix.