Details
-
Bug
-
Status: Patch Available
-
Major
-
Resolution: Unresolved
-
4.8.0
-
None
-
None
-
None
Description
ScanUtil seems to throw an ArrayIndexOutOfBoundsException iif :
- There are more than one PK column INCLUDED in the index.
- And there's IN clause with PKs (indexed columns).
- And there's a non-PK column comparison.
I could avoid the exception by modifying the ScanUtil.java to check the array length and offset, but it's just a temp work.
To reproduce my problem:
Table & Index
CREATE TABLE INCLUDED_PK (id1 SMALLINT NOT NULL, id2 SMALLINT NOT NULL, tid1 SMALLINT NOT NULL, liked SMALLINT CONSTRAINT pk PRIMARY KEY (id1, id2, tid1)) CREATE INDEX INCLUDED_PK_INDEX ON INCLUDED_PK(id1 ASC, id2 ASC, liked ASC) INCLUDE (tid1)
Query throwing an exception
SELECT id1, id2, tid1, liked FROM INCLUDED_PK WHERE ((id1,id2) IN ((1,1), (2,2), (3,3))) AND liked > 10 limit 10
Testing the query with QueryPlanTest
2016-06-09 14:18:44,589 DEBUG [main] org.apache.phoenix.util.ReadOnlyProps(317): Creating new ReadOnlyProps due to phoenix.query.dateFormat with yyyy-MM-dd HH:mm:ss.SSS!=yyyy-MM-dd
2016-06-09 14:18:44,597 DEBUG [main] org.apache.phoenix.jdbc.PhoenixStatement(1402): Execute query: EXPLAIN SELECT id1, id2, tid1, liked FROM INCLUDED_PK WHERE ((id1,id2) IN ((1,1), (2,2), (3,3))) AND liked > 10 limit 10
2016-06-09 14:18:44,601 DEBUG [main] org.apache.phoenix.compile.FromCompiler$BaseColumnResolver(568): Re-resolved stale table INCLUDED_PK with seqNum 0 at timestamp 0 with 4 columns: [ID1, ID2, TID1, 0.LIKED]
2016-06-09 14:18:44,683 DEBUG [main] org.apache.phoenix.compile.FromCompiler$BaseColumnResolver(568): Re-resolved stale table INCLUDED_PK_INDEX with seqNum 0 at timestamp 0 with 4 columns: [:ID1, :ID2, 0:LIKED, :TID1]
2016-06-09 14:18:44,684 DEBUG [main] org.apache.phoenix.compile.FromCompiler$BaseColumnResolver(568): Re-resolved stale table INCLUDED_PK with seqNum 0 at timestamp 0 with 4 columns: [ID1, ID2, TID1, 0.LIKED]
java.lang.ArrayIndexOutOfBoundsException: 6
at org.apache.phoenix.util.ScanUtil.setKey(ScanUtil.java:417)
at org.apache.phoenix.util.ScanUtil.setKey(ScanUtil.java:348)
at org.apache.phoenix.util.ScanUtil.getKey(ScanUtil.java:320)
at org.apache.phoenix.util.ScanUtil.getMinKey(ScanUtil.java:293)
at org.apache.phoenix.compile.ScanRanges.create(ScanRanges.java:130)
at org.apache.phoenix.compile.WhereOptimizer.pushKeyExpressionsToScan(WhereOptimizer.java:302)
at org.apache.phoenix.compile.WhereCompiler.compile(WhereCompiler.java:149)
at org.apache.phoenix.compile.WhereCompiler.compile(WhereCompiler.java:100)
at org.apache.phoenix.compile.QueryCompiler.compileSingleFlatQuery(QueryCompiler.java:559)
at org.apache.phoenix.compile.QueryCompiler.compileSingleQuery(QueryCompiler.java:510)
at org.apache.phoenix.compile.QueryCompiler.compileSelect(QueryCompiler.java:205)
at org.apache.phoenix.compile.QueryCompiler.compile(QueryCompiler.java:157)
at org.apache.phoenix.optimize.QueryOptimizer.addPlan(QueryOptimizer.java:236)
at org.apache.phoenix.optimize.QueryOptimizer.getApplicablePlans(QueryOptimizer.java:146)
at org.apache.phoenix.optimize.QueryOptimizer.optimize(QueryOptimizer.java:94)
at org.apache.phoenix.optimize.QueryOptimizer.optimize(QueryOptimizer.java:80)
at org.apache.phoenix.execute.BaseQueryPlan.getExplainPlan(BaseQueryPlan.java:484)
at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableExplainStatement.compilePlan(PhoenixStatement.java:464)
at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableExplainStatement.compilePlan(PhoenixStatement.java:443)
at org.apache.phoenix.jdbc.PhoenixStatement$1.call(PhoenixStatement.java:271)
at org.apache.phoenix.jdbc.PhoenixStatement$1.call(PhoenixStatement.java:266)
at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
at org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:265)
at org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:1408)
at org.apache.phoenix.query.QueryPlanTest.testExplainPlan(QueryPlanTest.java:190)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)