SQLite 3.44.1: incorrect IS NULL result for empty-set aggregation with LEFT JOIN
(1) By jidemimi (37904269) on 2026-05-03 09:59:27 [source]
Dear SQLite developers,
Observed in SQLite 3.44.1:
CREATE TABLE t0(X INT NOT NULL)
SELECT t1.X IS NULL, COUNT(*)
FROM t0 t1
LEFT JOIN t0 t2 ON t1.X = t2.X
WHERE t1.X IS NOT NULL OR 1=1
Result: A single row with values
t1.X IS NULL 0 COUNT(*) 0
Expected: A single row with values
t1.X IS NULL 1 COUNT(*) 0
This issue reproduces consistently on 3.44.1 but appears to be fixed in newer release versions (tested on 3.45.0+). Sharing this as a potential regression test case.
Thank you for your work on SQLite!
(2.1) By Igor Tandetnik (itandetnik) on 2026-05-03 13:56:11 edited from 2.0 in reply to 1 [link] [source]
Both outcomes are valid; your expectation of a particular result is wrong. t1.X is a bare column in an aggregate query (a column that appears neither in an aggregate function call, nor in a GROUP BY clause). Therefore, this applies:
If the aggregate is composed from one or more input rows, then a bare column will take on the value of an arbitrary row from the aggregate's input. The particular row chosen might change from one invocation to the the next. If the aggregate is empty (if the aggregate has no input rows, as happens if no rows match the WHERE clause), then the bare column can take on any arbitrary value, including values that are not found anywhere in the tables of the FROM clause.
Your example falls into "aggregate is empty" case. t1.X can have any value whatsoever, including but not limited to NULL.
(3) By jidemimi (37904269) on 2026-05-03 14:41:58 in reply to 2.1 [link] [source]
Thank you for your correction and detailed explanation!
I will keep learning and study the SQLite documentation more carefully.
(4) By jidemimi (37904269) on 2026-05-26 07:17:52 in reply to 2.1 [link] [source]
Here is an example.
CREATE TABLE t1(a INT, b TEXT);
INSERT INTO t1 VALUES(1, 'A'), (2, 'B'), (3, 'B');
CREATE INDEX idx_partial ON t1(a) WHERE b = 'B';
SELECT * FROM t1 WHERE a IN (1, 2) AND b = 'B';
Expected:(2, 'B')
Result:Null
I wonder if this is a bug.
(5) By Richard Hipp (drh) on 2026-05-26 09:32:58 in reply to 4 [link] [source]
That would be a bug, if I could get it to happen. I tried your script on the latest trunk check-in and on every historical version of SQLite that I have readily at hand, and they all got the correct answer, though. So I don't know how you are getting a empty result. Maybe give us more detail about what you are doing?
(6) By Spindrift (spindrift) on 2026-05-26 11:30:53 in reply to 4 [link] [source]
https://sqlite.org/fiddle/
Produces 2, B
for your code.
It's certainly worth ensuring that such "bugs" you may discover reproduce on this version of SQLite, as a minimum.
(7) By jidemimi (37904269) on 2026-05-28 02:43:25 in reply to 6 [link] [source]
I tested it in an earlier version,it has been fixed now.