[
https://issues.apache.org/jira/browse/IMPALA-7996?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18118984#comment-18118984
]
ASF subversion and git services commented on IMPALA-7996:
---------------------------------------------------------
Commit 1f2018be7bbb060cae71f18f4d6c42c527019d98 in impala's branch
refs/heads/master from Aleksandr Efimov
[ https://gitbox.apache.org/repos/asf?p=impala.git;h=1f2018be7 ]
IMPALA-15280: Take referenced partitions from the final plan
HdfsScanNode registers its partitions with the descriptor table from
computeScanRangeLocations(), which runs while the scan's subtree is
being built. The descriptor table therefore describes every scan the
planner ever constructed, not the scans that ended up in the plan. A
subtree that is replaced afterwards leaves its partitions behind, and
toThrift() ships partition descriptors that nothing reads. The TODO
above the tuple descriptors in DescriptorTable.toThrift() already names
this situation.
Have each HdfsScanNode remember the ids it registered, and once the
plan is final, keep the union over the scans still reachable from the
plan fragments. Taking what the surviving scans registered, rather than
deriving the partitions again, is what makes this safe: HdfsScanNode is
the only caller of addReferencedPartition(), so the new set is by
construction a subset of the old one, it is the same set whenever every
scan that was built survives, and no scan can lose a partition it still
reads.
Deriving the partitions again from the scan would not give the same
answer. The loop in computeScanRangeLocations() walks
getSampledOrRawPartitions(), so a TABLESAMPLE scan registers the
sampled partitions and not partitions_, and a scan under a simple limit
leaves the loop once it has rows enough and never reaches the rest.
What each scan registered is the only record of what it asked for.
The walk covers every fragment, not the getFragmentsInPlanPreorder()
subset that createPlanExecInfo() uses: that one skips fragments reached
through a join build, and a scan below one of those still runs.
A table whose scans are all gone now ends up with an empty set rather
than the partitions its replaced scan had registered. That state is not
new: getReferencedPartitions() allocates an empty set for any table
toThrift() asks about, so a table whose tuple is still materialized
while nothing scans it already ships a descriptor with no partitions -
the situation the TODO above the tuple descriptors names. The backend
takes it today.
The EmptySetNode replacements on master - createScanNode() on conjuncts
implied false, the empty SPJ result set, dropped union operands - all
happen before the discarded side is planned, so no plan is expected to
change here. This is a prerequisite for IMPALA-7996, which replaces the
pruned input of a constant-false outer join after that input has been
built and trips PlannerTestBase.testHdfsPartitionsReferenced without
it.
Testing:
- PlannerTest, which asserts on every query that each partition in the
descriptor table is covered by a scan range. PlannerTestBase used to
check only the single-node plan and now checks the distributed and
parallel plans too.
Change-Id: I553281e7c77e3297585360f37160bc3f9d69a208
Assisted-by: claude-opus-5 (Claude Code)
Reviewed-on: http://gerrit.cloudera.org:8080/24723
Reviewed-by: Impala Public Jenkins <[email protected]>
Tested-by: Impala Public Jenkins <[email protected]>
> Inefficient plan for pathological ON FALSE clause
> -------------------------------------------------
>
> Key: IMPALA-7996
> URL: https://issues.apache.org/jira/browse/IMPALA-7996
> Project: IMPALA
> Issue Type: Bug
> Components: Frontend
> Affects Versions: Impala 3.1.0
> Reporter: Paul Rogers
> Assignee: Aleksandr Efimov
> Priority: Minor
>
> Bugs in the rewrite code prevented the ON clause from being subject to the
> full set of rewrite rules. See IMPALA-7997.
> Once that bug was fixed, it uncovered an inefficient plan for the
> pathological case of {{ON FALSE}}.
> {code:sql}
> # Constant conjunct in the ON-clause of an outer join is
> # assigned to the join.
> select *
> from functional.alltypessmall a
> right outer join functional.alltypestiny b
> on (a.id = b.id and !true)
> {code}
> Note the ON clause and its actual meaning:
> {noformat}
> a.id = b.id and !true --> a.id = b.id AND FALSE --> FALSE
> {noformat}
> (Note that a test should be added for the straight-up FALSE condition.)
> Once rewrites are applied applied, (or, presumably, if we have a test for
> {{ON FALSE}}), we get a new plan, which is actually worse:
> {noformat}
> PLAN-ROOT SINK
> |
> 02:NESTED LOOP JOIN [RIGHT OUTER JOIN]
> | join predicates: FALSE
> |
> |--01:SCAN HDFS [functional.alltypestiny b]
> | partitions=4/4 files=4 size=460B
> |
> 00:SCAN HDFS [functional.alltypessmall a]
> partitions=4/4 files=4 size=6.32KB
> {noformat}
> This says to loop over both tables, which is a very bad plan. The correct
> plan is to reduce the query to an empty result set.
> Similar case:
> {code:sql}
> # Constant conjunct in the ON-clause of an outer join is
> # assigned to the join.
> select *
> from functional.alltypessmall a
> left outer join functional.alltypestiny b
> on (a.id = b.id and 1 + 1 > 10)
> {code}
> Reasoning:
> {noformat}
> a.id = b.id and 1 + 1 > 10 --> a.id = b.id AND 2 > 10
> --> a.id = b.id AND FALSE --> FALSE
> {noformat}
> The plan after performing above rewrites, which is also an unnecessary nested
> loop join:
> {noformat}
> PLAN-ROOT SINK
> |
> 02:NESTED LOOP JOIN [LEFT OUTER JOIN]
> | join predicates: FALSE
> |
> |--01:SCAN HDFS [functional.alltypestiny b]
> | partitions=4/4 files=4 size=460B
> |
> 00:SCAN HDFS [functional.alltypessmall a]
> partitions=4/4 files=4 size=6.32KB
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]