Skip to content

Correct move conditions from JOIN ON to WHERE for ANY JOIN` #21671

@vdimir

Description

@vdimir

I think this could lead to error with . A query like

SELECT *
FROM
	(SELECT 1 AS id) AS l
	INNER ANY JOIN (SELECT 1 AS id, number as v FROM system.numbers LIMIT 2) AS r
	          ON l.id = r.id AND r.v = 1

is not the same as

SELECT *
FROM
	(SELECT 1 AS id) AS l
	INNER ANY JOIN (SELECT 1 AS id, number as v FROM system.numbers LIMIT 2) AS r
	          ON l.id = r.id
WHERE
	r.v = 1

The first one should return a line while the second returns anything because it joins on the first machting line with and then apply .

IMHO the where clause should be added to a subselect like

SELECT *
FROM
	(SELECT 1 AS id) AS l
	INNER ANY JOIN (SELECT * FROM (SELECT 1 AS id, number AS v FROM system.numbers LIMIT 2) WHERE v = 1) AS r
	          ON l.id = r.id;

Originally posted by @PHaroZ in #18720 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp-joinsJOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla...comp-query-optimizerQuery plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa...feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions