-
Notifications
You must be signed in to change notification settings - Fork 8.3k
CROSS JOIN to INNER JOIN rewrite depends on tables order in query. #9194
Copy link
Copy link
Closed
Labels
comp-joinsJOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla...JOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla...
Description
How to reproduce
set enable_debug_queries = 1;
create table o (orderkey UInt32, custkey UInt32) engine = Memory;
create table l (orderkey UInt32) engine = Memory;
create table c (custkey UInt32) engine = Memory;
ANALYZE select * from l, o, c
where c.custkey = o.custkey and l.orderkey = o.orderkey;
ANALYZE select * from l, c, o
where c.custkey = o.custkey and l.orderkey = o.orderkey;
Second query is interpreted as CROSS JOIN
SELECT
`--l.orderkey` AS `l.orderkey`,
`--o.orderkey` AS `o.orderkey`,
`--o.custkey` AS `o.custkey`,
custkey AS `c.custkey`
FROM
(
SELECT
orderkey AS `--l.orderkey`,
o.orderkey AS `--o.orderkey`,
custkey AS `--o.custkey`
FROM l
ALL INNER JOIN
(
SELECT *
FROM o
) AS o ON `--l.orderkey` = `--o.orderkey`
WHERE `--l.orderkey` = `--o.orderkey`
)
ALL INNER JOIN
(
SELECT *
FROM c
) AS c ON custkey = `--o.custkey`
WHERE (custkey = `--o.custkey`) AND (`--l.orderkey` = `--o.orderkey`)
SELECT
`--l.orderkey` AS `l.orderkey`,
`--c.custkey` AS `c.custkey`,
orderkey AS `o.orderkey`,
custkey AS `o.custkey`
FROM
(
SELECT
orderkey AS `--l.orderkey`,
custkey AS `--c.custkey`
FROM l
CROSS JOIN c
)
ALL INNER JOIN
(
SELECT *
FROM o
) AS o ON (`--c.custkey` = custkey) AND (`--l.orderkey` = orderkey)
WHERE (`--c.custkey` = custkey) AND (`--l.orderkey` = orderkey)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
comp-joinsJOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla...JOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla...