Zoltán Borók-Nagy created IMPALA-15863:
------------------------------------------
Summary: Calcite planner: TPC-H Q21 scans lineitem 7 times and
runs 2x slower than with the original planner
Key: IMPALA-15863
URL: https://issues.apache.org/jira/browse/IMPALA-15863
Project: IMPALA
Issue Type: Improvement
Components: Frontend
Reporter: Zoltán Borók-Nagy
The Calcite planner plans the correlated EXISTS and NOT EXISTS subqueries of
TPC-H Q21 by re-deriving the outer query block. Subquery removal
(FILTER_SUB_QUERY_TO_CORRELATE) and RelDecorrelator.decorrelateQuery() in
CalciteRelNodeConverter.convert() evaluate each subquery for the distinct
(l_orderkey, l_suppkey) values of a new copy of the outer block (lineitem,
orders, supplier, nation). The result is joined back to the main query on those
two columns: EXISTS as an inner join, NOT EXISTS as a left outer join plus an
IS NULL filter. The NOT EXISTS copy applies EXISTS again, so the outer block is
computed 4 times. The original planner's StmtRewriter.mergeExpr() turns the
subqueries into a left semi join and a left anti join on the correlated
predicates. They end up as a right semi join and a right anti join, each over a
single lineitem scan.
On master, Q21 at SF1000 (Parquet, 12 executors, COMPUTE_PROCESSING_COST=true)
takes 61.0-68.5 s with PLANNER=CALCITE and 29.3-31.0 s with the original
planner (two runs of 5 each; medians 63.0-64.1 s vs 29.8-30.5 s). The Calcite
plan has 19 scans (7 of lineitem) and 18 hash joins (13 broadcast), against 6
scans (3 of lineitem) and 5 joins. It reads 403.5 GB instead of 165.6 GB. Its
per-host reservation is 6.41 GB and 196 threads instead of 1.14 GB and 72. The
estimates also go wrong. In the main block and in the NOT EXISTS copy, the
supplier join after the key-set join removes no rows (70.69M in and out), but
it is estimated at 374.08K rows. Both outputs are broadcast. Their hash table
builds take 9.92 GB and 7.95 GB per host (estimated 136 MB) and average
13.9-16.6 s per host (up to 21.4 s). They are the top two bottlenecks.
Plan EXISTS and NOT EXISTS subqueries that have an equality correlation
predicate as a semi join and an anti join against the subquery's own scan, as
StmtRewriter does. The other correlated predicates (here l2.l_suppkey <>
l1.l_suppkey) become other join predicates. This would avoid the 3 extra copies
of the outer block. IMPALA-15711 is related: it is about enabling the rule that
creates anti joins in Calcite plans.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)