From 60b4fa0c1cfacc9ad484c08fbbd0de7b69ea27ca Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Fri, 18 May 2012 21:10:12 +0000 Subject: Adjusted optimization of open ended range queries. --- .../com/amazon/carbonado/qe/FilteringScore.java | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/amazon/carbonado/qe/FilteringScore.java b/src/main/java/com/amazon/carbonado/qe/FilteringScore.java index 5b76a6d..57c16a1 100644 --- a/src/main/java/com/amazon/carbonado/qe/FilteringScore.java +++ b/src/main/java/com/amazon/carbonado/qe/FilteringScore.java @@ -823,10 +823,21 @@ public class FilteringScore { return 1; } - // Compare range match. (index can have at most one range match) - if (first.hasRangeMatch()) { - if (second.hasRangeMatch()) { - // Both have range match, favor clustered index. + // Compare ranges. Favor ranges that help find the start. + boolean firstPartialRange = first.hasRangeStart(); + boolean secondPartialRange = second.hasRangeStart(); + + if (first.shouldReverseRange()) { + firstPartialRange = first.hasRangeEnd(); + } + + if (second.shouldReverseRange()) { + secondPartialRange = second.hasRangeEnd(); + } + + if (firstPartialRange) { + if (secondPartialRange) { + // Both have ranges, favor clustered index. if (first.isIndexClustered()) { if (!second.isIndexClustered()) { return -1; @@ -837,7 +848,8 @@ public class FilteringScore { } else { return -1; } - } else if (second.hasRangeMatch()) { + + } else if (secondPartialRange) { return 1; } -- cgit v1.2.3