In the HIR ⇒ MIR lowering phase, decorrelated equi-joins that refer to the outer context in their join conditions will produce decorrelated plans that will result in sub-optimal join order with unnecessary cross join stages.
For example, the OPTIMIZED PLAN for the following query:
SELECT * FROM outer JOIN LATERAL (
SELECT *
FROM
facts
JOIN dim01 ON(x * facts.dim01_k01 = y * dim01.dim01_k01)
) ON(true);
If we don't de-dupe the Get materialize.left_joins_raw.outer part after decorrelation we can end up with a plan that has two cross joins (lhs = outer x facts and rhs = outer x dim01), but can then do an equi-join between lhs and rhs.
Solution
Unclear.
Example schema
CREATE TABLE outer(
x int not null,
y int not null
);
CREATE TABLE facts(
facts_k01 int not null,
dim01_k01 int,
dim02_k01 int,
dim03_k01 int,
facts_d01 int,
facts_d02 int,
facts_d03 int,
facts_d04 int,
facts_d05 int
);
CREATE TABLE dim01(
dim01_k01 int,
dim01_d01 int,
dim01_d02 int,
dim01_d03 int,
dim01_d04 int,
dim01_d05 int
);
Problem
In the
HIR ⇒ MIR
lowering phase, decorrelated equi-joins that refer to the outer context in their join conditions will produce decorrelated plans that will result in sub-optimal join order with unnecessary cross join stages.For example, the
OPTIMIZED PLAN
for the following query:looks as follows
but the decorrelated plan looks as follows:
If we don't de-dupe the
Get materialize.left_joins_raw.outer
part after decorrelation we can end up with a plan that has two cross joins (lhs = outer x facts
andrhs = outer x dim01
), but can then do an equi-join betweenlhs
andrhs
.Solution
Unclear.
Example schema
See also
22437