Repository: phoenix Updated Branches: refs/heads/4.0 ab2813b66 -> 02d480477
PHOENIX-1298 Queries on fixed width type columns that have an index declared on them don't use that index Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/02d48047 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/02d48047 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/02d48047 Branch: refs/heads/4.0 Commit: 02d480477df04a538b344d228d8067d1cfd107b8 Parents: ab2813b Author: James Taylor <jtay...@salesforce.com> Authored: Sat Sep 27 00:35:54 2014 -0700 Committer: James Taylor <jtay...@salesforce.com> Committed: Sat Sep 27 00:35:54 2014 -0700 ---------------------------------------------------------------------- .../apache/phoenix/compile/WhereOptimizer.java | 19 ++++++++++++++++--- .../java/org/apache/phoenix/query/BaseTest.java | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/02d48047/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java index 22594c9..51da924 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java @@ -476,10 +476,22 @@ public class WhereOptimizer { for (int i = 0; i < childSlots.size(); i++) { KeySlots slots = childSlots.get(i); KeySlot keySlot = slots.iterator().next(); + List<Expression> childExtractNodes = keySlot.getKeyPart().getExtractNodes(); + // Stop if there was a gap in extraction of RVC elements. This is required if the leading + // RVC has not row key columns, as we'll still get childSlots if the RVC has trailing row + // key columns. We can't rule the RVC out completely when the childSlots is less the the + // RVC length, as a partial, *leading* match is optimizable. + if (childExtractNodes.size() != 1 || !childExtractNodes.get(0).equals(rvc.getChildren().get(i))) { + break; + } + int pkPosition = keySlot.getPKPosition(); + if (pkPosition < 0) { // break for non PK columns + break; + } // Continue while we have consecutive pk columns if (position == -1) { - position = initialPosition = keySlot.getPKPosition(); - } else if (keySlot.getPKPosition() != position) { + position = initialPosition = pkPosition; + } else if (pkPosition != position) { break; } position++; @@ -518,6 +530,7 @@ public class WhereOptimizer { if (isDegenerate(slot.getKeyRanges())) { return EMPTY_KEY_SLOTS; } + final List<Expression> extractNodes = Collections.<Expression>singletonList(node); final KeyPart childPart = slot.getKeyPart(); final ImmutableBytesWritable ptr = context.getTempPtr(); return new SingleKeySlot(new KeyPart() { @@ -547,7 +560,7 @@ public class WhereOptimizer { @Override public List<Expression> getExtractNodes() { - return childPart.getExtractNodes(); + return extractNodes; } @Override http://git-wip-us.apache.org/repos/asf/phoenix/blob/02d48047/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java index c7a7c3e..11f394f 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java @@ -1325,7 +1325,7 @@ public abstract class BaseTest { count++; } assertTrue("Could not find " + errorResult + " in expected results: " + expectedResults + " with actual results: " + actualResults, errorResult == null); - assertEquals(count, expectedCount); + assertEquals(expectedCount, count); } public HBaseTestingUtility getUtility() {