Unexpected result caused by modification to sqlite_stat1
(1) By axelteo on 2026-03-05 07:35:24 [source]
Dear SQLite Developers,
I found a test case with an unexpected result on the latest checkout [e438b564ca84377746464034d770e9c1f5899d93].
Modifying the statistics in sqlite_stat1 changes the output of the same query, even though the underlying data and schema remain the same.
Case 1: Without modified statistics
CREATE TABLE t0 (c1 UNIQUE NOT NULL);
INSERT INTO t0 VALUES (1);
CREATE TABLE t1 (c0 UNIQUE);
INSERT INTO t1 VALUES (0);
SELECT DISTINCT * FROM t0 LEFT OUTER JOIN t1 ON ((t1.c0) > (t0.c1));
-- returns 1 row
Case 2: With modified statistics
CREATE TABLE t0 (c1 UNIQUE NOT NULL);
INSERT INTO t0 VALUES (1);
CREATE TABLE t1 (c0 UNIQUE);
INSERT INTO t1 VALUES (0);
ANALYZE;
UPDATE sqlite_stat1 SET stat='1 1000' WHERE tbl='t1';
ANALYZE sqlite_schema;
SELECT DISTINCT * FROM t0 LEFT OUTER JOIN t1 ON ((t1.c0)>(t0.c1));
-- returns 2 rows
Thank you for your efforts in bug fixing and analysis.
(2) By Richard Hipp (drh) on 2026-03-05 11:23:56 in reply to 1 [link] [source]
This problem goes back almost 9 years to version 3.19.0 and specifically check-in 2017-04-15T11:53:47z. It has to do with the skip-ahead optimization,
I am investigation now and I might yet change my mind, but right now I think that since the issue has been around for so long without anyone noticing and because it is not a vulnerability or database corruption issue, the fix for this will not make it into version 3.52.0 release.