TUPLE IN (...) expression in combination with OUTER JOIN can lead to wrong results

Details

Detail name Value
Changelog Number 32857
Type Bug
Status Resolved
Affected Versions Exasol 7.1.0, Exasol 8.0.0, 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 “TUPLE IN (…)” expression can be incorrectly evaluated to NULL instead of FALSE/TRUE when the following conditions apply:

  • One of the values on the left-hand side of the IN is an expression that includes a column reference.
  • This expression is from the NULL-generating table of an outer join (e.g. the right side of a LEFT JOIN).
  • One of the values on the left-hand side of the IN does not match any corresponding values from the tuples on the right side.
  • The query compares the TUPLE IN () result to a BOOLEAN value, for example with = or another IN (but not with IS TRUE or IS FALSE).

Example

-- Setup
create or replace table t_null(y int);
insert into t_null values (1);
create or replace table t_outer(x int);
insert into t_outer values (1), (2);

-- Expected: 2 rows, values (1, 1), (2, NULL)
-- Observed: 1 row, values (1, 1)
select x, y from t_outer left join t_null on x=y where ((0, y) in (1, 2)) = false;

-- Expected: 2 rows, values (1, 1), (2, NULL)
-- Observed: 1 row, values (1, 1)
select x, y from t_outer left join t_null on x=y where ((0, y + 2) in (1, 2)) = false;

Workaround

  1. Exasol version 8.34.0 and later: Add IS TRUE or IS FALSE to the predicate. For example, for the above query:
  2. Exasol version 8.34.0 and later: You might be able to change the existing predicate to IS TRUE or IS FALSE, which would be simpler:
  3. Expand the IN predicate as separate equality predicates. Wrap one equality predicate for each tuple in COALESCE(..., NULL) to ensure that the optimizer does not convert the expression back to an IN predicate (this is only necessary for tuples of length 2).
-- Expected/Observed (>= Exasol 8.34): 2 rows, values (1, 1), (2, NULL)
select x, y from t_outer left join t_null on x=y where (((0, y) in (1, 2)) = false) is true;
-- Expected/Observed (>= Exasol 8.34): 2 rows, values (1, 1), (2, NULL)
select x, y from t_outer left join t_null on x=y where ((0, y) in (1, 2)) is false;
-- Expected/Observed: 2 rows, values (1, 1), (2, NULL)
select x, y
from t_outer left join t_null on x=y
where ((0 = 1 and coalesce(y = 2, NULL)) or (0 = 3 and coalesce(y = 4, NULL))) is false;

Fix

The query behaves as expected.