Fix index estimation on MATCH statement execution planning
@@ -60,6 +60,7 @@ public class OWhereClause extends SimpleNode {
* estimates how many items of this class will be returned applying this filter
*
* @param oClass
+ *
* @return an estimation of the number of records of this class returned applying this filter, 0 if and only if sure that no
* records are returned
*/
@@ -116,11 +117,16 @@ public class OWhereClause extends SimpleNode {
key = new OCompositeKey();
for (int i = 0; i < nMatchingKeys; i++) {
Object keyValue = convert(conditions.get(definitionFields.get(i)), definition.getTypes()[i]);
- ((OCompositeKey) key).addKey(conditions.get(definitionFields.get(i)));
+ ((OCompositeKey) key).addKey(keyValue);
}
}
if (key != null) {
- Object result = index.get(key);
+ Object result = null;
+ if (conditions.size() == definitionFields.size()) {
+ result = index.get(key);
+ } else if (index.supportsOrderedIterations()) {
+ result = index.iterateEntriesBetween(key, true, key, true, true);
+ }
if (result instanceof OIdentifiable) {
return 1;
}
@@ -130,6 +136,17 @@ public class OWhereClause extends SimpleNode {
if (result instanceof OSizeable) {
return ((OSizeable) result).size();
}
+ if (result instanceof Iterable) {
+ result = ((Iterable) result).iterator();
+ }
+ if (result instanceof Iterator) {
+ int i = 0;
+ while (((Iterator) result).hasNext()) {
+ ((Iterator) result).next();
+ i++;
+ }
+ return i;
+ }
}
return Long.MAX_VALUE;
}
