Skip to content

'IS NOT DISTINCT FROM' not work in JOIN #26257

@PavelkoSemen

Description

@PavelkoSemen

Hello everyone!
Has anyone encountered such behavior in Trino: queries using NOT DISTINCT FROM return 0 rows after a JOIN.If in the query we leave only the part of the condition for K3, where both values are equal to NULL, then one row is returned.
If we use K1 and K2, one row is also returned.
However, when all three keys (K1, K2, K3) are specified in the condition, the query returns 0 rows.

CREATE  TABLE ice.test.ys_stage1
(
  k1 int,
  k2 int,
  k3 int,
  a1 int,
  a2 int,
  a3 int
);

CREATE  TABLE ice.test.ys_merge1
(
  k1 int,
  k2 int,
  k3 int,
  a1 int,
  a2 int,
  a3 int
);

INSERT INTO ice.test.ys_stage1 VALUES(0,0, NULL,9,9,9);
INSERT INTO ice.test.ys_merge1 VALUES(0,0, NULL,9,9,9);

# 0 row
SELECT
  count(*)
FROM ice.test.ys_stage1 t
  INNER JOIN ice.test.ys_merge1 AS s
    ON 1=1
    AND s.k1 IS NOT DISTINCT FROM t.k1
    AND s.k2 IS NOT DISTINCT FROM t.k2
    AND s.k3 IS NOT DISTINCT FROM t.k3;    

 # 1 row
SELECT
  count(*)
FROM ice.test.ys_stage1 t
  INNER JOIN ice.test.ys_merge1 AS s
    ON 1=1
    AND ((s.k1 = t.k1) OR (s.k1 IS NULL AND t.k1 IS NULL) )
    AND ((s.k2 = t.k2) OR (s.k2 IS NULL AND t.k2 IS NULL) )
    AND ((s.k3 = t.k3) OR (s.k3 IS NULL AND t.k3 IS NULL) );

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions