Skip to content

Decorrelation not properly work in some cases with InSubquery #1624

@Vedin

Description

@Vedin

That happens on the dbt-gitlab run:

  010001 (02000): SQL compilation error: unsupported feature: Physical plan does not support logical expression InSubquery(InSubquery { expr: Column(Column { relation: Some(Bare { table: "distinct_source" }), name: "max_task_instance" }), subquery: <subquery>, negated: false })
  compiled code at target/run/gitlab_snowflake/models/sources/gitlab_dotcom/renamed/scd/gitlab_dotcom_members_source.sql

Repro:

CREATE OR REPLACE TABLE t (
    a INT
);

INSERT INTO t VALUES (1), (2), (3), (4), (5);

-- Create table u
CREATE OR REPLACE TABLE u (
    a INT
);

INSERT INTO u VALUES (2), (4), (6);

SELECT 
    t.a,
    (t.a IN (SELECT u.a FROM u)) AS flag
FROM t;

one-liner:

WITH t AS (
    SELECT * FROM VALUES (1), (2), (3), (4), (5) AS t(a)
),
u AS (
    SELECT * FROM VALUES (2), (4), (6) AS u(a)
)
SELECT 
    t.a,
    (t.a IN (SELECT u.a FROM u)) AS flag
FROM t;

In snowflake they decorrelate it using LeftOuterJoin, we should do something like this as well.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions