Details
-
Bug
-
Status: Resolved
-
Critical
-
Resolution: Fixed
-
Impala 4.0.0, Impala 4.1.0, Impala 4.2.0, Impala 4.1.1
-
None
-
ghx-label-11
Description
The following query fails with IndexOutOfBoundsException:
create table tbl (id int); select id from ( select id, row_number() over (order by id) rn, max(id) over () max_id from tbl ) t where id = max_id and rn < 10; ERROR: IndexOutOfBoundsException: Index: 0, Size: 0
The stacktrace in logs:
I0116 15:55:46.766265 23944 Frontend.java:2062] be402cb92ecc5490:11cbe79000000000] Analysis and authorization finished. I0116 15:55:46.803608 23944 jni-util.cc:288] be402cb92ecc5490:11cbe79000000000] java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(ArrayList.java:659) at java.util.ArrayList.get(ArrayList.java:435) at org.apache.impala.planner.AnalyticPlanner.inferPartitionLimits(AnalyticPlanner.java:914) at org.apache.impala.planner.AnalyticPlanner.createSingleNodePlan(AnalyticPlanner.java:115) at org.apache.impala.planner.SingleNodePlanner.createQueryPlan(SingleNodePlanner.java:295) at org.apache.impala.planner.SingleNodePlanner.createInlineViewPlan(SingleNodePlanner.java:1244) at org.apache.impala.planner.SingleNodePlanner.createTableRefNode(SingleNodePlanner.java:2208) at org.apache.impala.planner.SingleNodePlanner.createTableRefsPlan(SingleNodePlanner.java:931) at org.apache.impala.planner.SingleNodePlanner.createSelectPlan(SingleNodePlanner.java:750) at org.apache.impala.planner.SingleNodePlanner.createQueryPlan(SingleNodePlanner.java:278) at org.apache.impala.planner.SingleNodePlanner.createSingleNodePlan(SingleNodePlanner.java:170) at org.apache.impala.planner.Planner.createPlanFragments(Planner.java:120) at org.apache.impala.planner.Planner.createPlans(Planner.java:249) at org.apache.impala.service.Frontend.createExecRequest(Frontend.java:1733) at org.apache.impala.service.Frontend.getPlannedExecRequest(Frontend.java:2344) at org.apache.impala.service.Frontend.doCreateExecRequest(Frontend.java:2181) at org.apache.impala.service.Frontend.getTExecRequest(Frontend.java:1967) at org.apache.impala.service.Frontend.createExecRequest(Frontend.java:1789) at org.apache.impala.service.JniFrontend.createExecRequest(JniFrontend.java:164)
There is a predicate "rn < 10" on the row_number() results so the limit is considered push down into the inline view to make it a TopN query. While considering the conjuncts, the other predicate "id = max_id" is also checked. It fails the following code in AnalyticPlanner.inferPartitionLimits():
List<Expr> lhsSourceExprs = ((SlotRef) lhs).getDesc().getSourceExprs(); if (lhsSourceExprs.size() > 1 || !(lhsSourceExprs.get(0) instanceof AnalyticExpr)) { continue; }
'lhsSourceExprs' is empty since "id" is a slot ref for a source table column. Thus lhsSourceExprs.get(0) throws the IndexOutOfBoundsException.
To workaround this bug, users can disable this optimization by query option:
set ANALYTIC_RANK_PUSHDOWN_THRESHOLD=0;
Attachments
Issue Links
- is caused by
-
IMPALA-9979 Backend partitioned top-n operator
- Resolved
- is related to
-
IMPALA-12164 The query fails with "IllegalStateException: Illegal reference to non-materialized slot: tid=x sid=x"
- Resolved
- links to