summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2007-08-03 01:52:24 +0000
committerBrian S. O'Neill <bronee@gmail.com>2007-08-03 01:52:24 +0000
commit078be4acf8c34a96783c06f093ce11ff7551eeda (patch)
treeaf025f3e9f835a8e6f71330501b29efa5f41cd44 /src
parent42eecb8f615abcb1a38fb42dbc9ac9fbe4e09686 (diff)
Fixed query engine rule which sometimes favored index with incorrect ordering.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/amazon/carbonado/qe/CompositeScore.java28
-rw-r--r--src/main/java/com/amazon/carbonado/qe/FilteringScore.java18
2 files changed, 33 insertions, 13 deletions
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<S extends Storable> {
// 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<S extends Storable> {
result = OrderingScore.fullComparator()
.compare(first.getOrderingScore(), second.getOrderingScore());
+ comparedOrdering = true;
if (result != 0) {
return result;
@@ -291,6 +293,32 @@ public class CompositeScore<S extends Storable> {
}
}
+ 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<S extends Storable> {
/**
* 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<FilteringScore<?>> fullComparator() {
return Full.INSTANCE;
@@ -885,14 +885,6 @@ public class FilteringScore<S extends Storable> {
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;
}
}