You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot rewrite JOINs when alias in right on is the same as select alias #23104
bugConfirmed user-visible misbehaviour in official releasecomp-joinsJOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla...minorPriority: minor
drop database if exists test_01600;
create database test_01600;
CREATE TABLE test_01600.base
(
`id` UInt64,
`id2` UInt64,
`d` UInt64,
`value` UInt64
)
ENGINE=MergeTree()
PARTITION BY d
ORDER BY (id,id2,d);
CREATE TABLE test_01600.derived1
(
`id1` UInt64,
`d1` UInt64,
`value1` UInt64
)
ENGINE = MergeTree()
PARTITION BY d1
ORDER BY (id1, d1)
;
CREATE TABLE test_01600.derived2
(
`id2` UInt64,
`d2` UInt64,
`value2` UInt64
)
ENGINE = MergeTree()
PARTITION BY d2
ORDER BY (id2, d2)
;
SELECT
base.id AS `base.id`,
derived2.id2 AS `derived2.id2`,
derived2.value2 AS `derived2.value2`,
derived1.value1 AS `derived1.value1`
FROM test_01600.base AS base
LEFT JOIN test_01600.derived2 AS derived2 ON base.id2 = derived2.id2
LEFT JOIN test_01600.derived1 AS derived1 ON base.id = derived1.id1
Error message:
Code: 48. DB::Exception: Received from localhost:9000. DB::Exception: Cannot rewrite JOINs. Alias 'derived2.id2' used in ON section depends on another alias 'derived2.id2': While processing SELECT base.id AS `base.id`, derived2.id2 AS `derived2.id2`, derived2.value2 AS `derived2.value2`, derived1.value1 AS `derived1.value1` FROM test_01600.base AS base LEFT JOIN test_01600.derived2 AS derived2 ON base.id2 = derived2.id2 LEFT JOIN test_01600.derived1 AS derived1 ON base.id = derived1.id1.
SELECTt1.col1AS`t1.col1`,
t1.col2AS`t1.col2`,
t2.col1AS`t2.col1`,
t2.col2AS`t2.col2`,
t3.col1AS`t3.col1`,
t3.col2AS`t3.col2`FROM
(SELECT1AS col1, 2AS col2) AS t1
FULL OUTER JOIN
(SELECT1AS col1, 3AS col2) AS t2
ONt1.col1=t2.col1
FULL OUTER JOIN
(SELECT1AS col1, 4AS col2) AS t3
ONt2.col1=t3.col1;
fails:
Code: 48. DB::Exception: Received from localhost:9000. DB::Exception: Cannot rewrite JOINs. Alias 't2.col1' used in ON section depends on another alias 't2.col1': While processing SELECT t1.col1 AS `t1.col1`, t1.col2 AS `t1.col2`, t2.col1 AS `t2.col1`, t2.col2 AS `t2.col2`, t3.col1 AS `t3.col1`, t3.col2 AS `t3.col2` FROM (SELECT 1 AS col1, 2 AS col2) AS t1 FULL OUTER JOIN (SELECT 1 AS col1, 3 AS col2) AS t2 ON t1.col1 = t2.col1 FULL OUTER JOIN (SELECT 1 AS col1, 4 AS col2) AS t3 ON t2.col1 = t3.col1. (NOT_IMPLEMENTED)
Remove the aliasing from the main select, then it should work. Or at least like this:
SELECT
t1.col1,
t1.col2 AS `t1.col2`,
t2.col1,
t2.col2 AS `t2.col2`,
t3.col1,
t3.col2 AS `t3.col2`
FROM
(SELECT 1 AS col1, 2 AS col2) AS t1
FULL OUTER JOIN
(SELECT 1 AS col1, 3 AS col2) AS t2
ON t1.col1 = t2.col1
FULL OUTER JOIN
(SELECT 1 AS col1, 4 AS col2) AS t3
ON t2.col1 = t3.col1;
bugConfirmed user-visible misbehaviour in official releasecomp-joinsJOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla...minorPriority: minor
Activity
filimonov commentedon Apr 15, 2021
20.6 and earlier - works. 20.7 and newer - fails.
dimovnike commentedon Nov 24, 2022
one join works, two fail.
here is another example:
works
fails:
IssaMisherky commentedon Jul 2, 2023
Remove the aliasing from the main select, then it should work. Or at least like this:
Close: #23104