From 078be4acf8c34a96783c06f093ce11ff7551eeda Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Fri, 3 Aug 2007 01:52:24 +0000 Subject: Fixed query engine rule which sometimes favored index with incorrect ordering. --- .../com/amazon/carbonado/qe/CompositeScore.java | 28 ++++++++++++++++++++++ .../com/amazon/carbonado/qe/FilteringScore.java | 18 ++++---------- 2 files changed, 33 insertions(+), 13 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/amazon/carbonado/qe/CompositeScore.java b/src/main/java/com/amazon/carbonado/qe/CompositeScore.java index 8194dbb..2e266c1 100644 --- a/src/main/java/com/amazon/carbonado/qe/CompositeScore.java +++ b/src/main/java/com/amazon/carbonado/qe/CompositeScore.java @@ -264,6 +264,7 @@ public class CompositeScore { // If this point is reached, the filtering score has not been // terribly helpful in deciding an index. Check the ordering score. + boolean comparedOrdering = false; if (considerOrdering(firstScore) && considerOrdering(secondScore)) { // Only consider ordering if index is fast (clustered) or if // index is used for any significant filtering. A full scan of @@ -272,6 +273,7 @@ public class CompositeScore { result = OrderingScore.fullComparator() .compare(first.getOrderingScore(), second.getOrderingScore()); + comparedOrdering = true; if (result != 0) { return result; @@ -291,6 +293,32 @@ public class CompositeScore { } } + if (result != 0) { + return result; + } + + // Still no idea which is best. Compare ordering if not already + // done so. + + if (!comparedOrdering) { + result = OrderingScore.fullComparator() + .compare(first.getOrderingScore(), second.getOrderingScore()); + comparedOrdering = true; + + if (result != 0) { + return result; + } + } + + // Finally, just favor index with fewer properties, under the + // assumption that fewer properties means smaller sized records + // that need to be read in. + if (firstScore.getIndexPropertyCount() < secondScore.getIndexPropertyCount()) { + return -1; + } else if (firstScore.getIndexPropertyCount() > secondScore.getIndexPropertyCount()) { + return 1; + } + return result; } diff --git a/src/main/java/com/amazon/carbonado/qe/FilteringScore.java b/src/main/java/com/amazon/carbonado/qe/FilteringScore.java index 2a9f354..3831b3e 100644 --- a/src/main/java/com/amazon/carbonado/qe/FilteringScore.java +++ b/src/main/java/com/amazon/carbonado/qe/FilteringScore.java @@ -234,11 +234,11 @@ public class FilteringScore { /** * Returns a comparator which determines which FilteringScores are - * better. It compares identity matches, range matches, open range matches, - * property arrangement and index cost estimate. It does not matter if the - * scores were evaluated for different indexes or storable types. The - * comparator returns {@code <0} if first score is better, {@code 0} if - * equal, or {@code >0} if second is better. + * better. It compares identity matches, range matches, open range matches + * and property arrangement. It does not matter if the scores were + * evaluated for different indexes or storable types. The comparator + * returns {@code <0} if first score is better, {@code 0} if equal, or + * {@code >0} if second is better. */ public static Comparator> fullComparator() { return Full.INSTANCE; @@ -885,14 +885,6 @@ public class FilteringScore { return 1; } - // Favor index with fewer properties, under the assumption that fewer - // properties means smaller sized records that need to be read in. - if (first.getIndexPropertyCount() < second.getIndexPropertyCount()) { - return -1; - } else if (first.getIndexPropertyCount() > second.getIndexPropertyCount()) { - return 1; - } - return 0; } } -- cgit v1.2.3