OUTER JOIN used with DISTINCT or GROUP BY on indexed column containing one NULL value can omit unmatched null row

Details

Detail name Value
Changelog Number 32800
Type Bug
Status Resolved
Affected Versions Exasol 8.0.3, Exasol 8.29.0, Exasol 2025.1.0, Exasol 2025.2.0, Exasol 2026.1.0
Fix Versions Exasol 2025.1.17
Resolution Date 2026-11-12

Description

A query containing an OUTER JOIN and DISTINCT or GROUP BY on an indexed column containing a NULL value can omit unmatched NULL value row when all of the following conditions are met:

  1. A table column contains unique values which includes one NULL value.
  2. An index exists on this column (created explicitly or automatically by a prior query).
  3. The table containing this column is on the null-generating side of an outer join.
  4. The query uses DISTINCT or GROUP BY on this column together with one or more additional columns from the same table.
CREATE TABLE p(id INT);
INSERT INTO p VALUES 1, 2;

-- Table n is on the NULL generating side of the outer join
CREATE TABLE n(id INT, k INT, payload INT);
INSERT INTO n VALUES (1, NULL, 7);

-- Index is automatically created during this query
SELECT * FROM p LEFT JOIN n ON p.id = n.k;

-- Observed:
-- (null)	7
--
-- Expected:
-- (null)	7
-- (null)   (null)
SELECT DISTINCT n.k, n.payload
FROM p
LEFT JOIN n ON p.id = n.id;

-- Observed:
-- (null)	7
--
-- Expected:
-- (null)	7
-- (null)   (null)
SELECT n.k, n.payload
FROM p
LEFT JOIN n ON p.id = n.id
GROUP BY n.k, n.payload;

Workaround

The workaround is, apply CAST to indexed column containing NULL to the same datatype.

-- Expected/Observed:
-- (null)	7
-- (null)   (null)
SELECT DISTINCT cast(n.k as int), n.payload
FROM p
LEFT JOIN n ON p.id = n.id;

-- Expected/Observed:
-- (null)	7
-- (null)   (null)
SELECT CAST(n.k AS INT), n.payload
FROM p
LEFT JOIN n ON p.id = n.id
GROUP BY CAST(n.k AS INT), n.payload;

Fix

The query behaves as expected.