Permalink
Browse files

New range index: fixing tests and test suite.

  • Loading branch information...
1 parent d336126 commit 2f815e197a2114ed51cb1cbbbb8bdf8d6d91c9ac @wolfgangmm wolfgangmm committed Sep 14, 2013
@@ -639,30 +639,6 @@ public boolean acceptsDocsOutOfOrder() {
}
}
- private class SearchFieldVisitor extends StoredFieldVisitor {
-
- private int docId;
- private NodeId nodeId;
-
- @Override
- public void intField(FieldInfo fieldInfo, int value) throws IOException {
- this.docId = value;
- }
-
- @Override
- public void binaryField(FieldInfo fieldInfo, byte[] value) throws IOException {
- int units = ByteConversion.byteToShort(value, 0);
- this.nodeId = index.getBrokerPool().getNodeFactory().createFromData(units, value, 2);
- }
-
- @Override
- public Status needsField(FieldInfo fieldInfo) throws IOException {
- if (fieldInfo.name.equals(FIELD_DOC_ID) || fieldInfo.name.equals(FIELD_NODE_ID))
- return Status.YES;
- return Status.STOP;
- }
- }
-
/**
* Check index configurations for all collection in the given DocumentSet and return
* a list of QNames, which have indexes defined on them.
@@ -167,6 +167,8 @@ public void setArguments(List<Expression> arguments) throws XPathException {
@Override
public void analyze(AnalyzeContextInfo contextInfo) throws XPathException {
super.analyze(new AnalyzeContextInfo(contextInfo));
+
+ this.contextId = contextInfo.getContextId();
}
@Override
@@ -206,7 +208,6 @@ public NodeSet preSelect(Sequence contextSequence, boolean useContext) throws XP
DocumentSet docs = contextSequence.getDocumentSet();
RangeIndexWorker index = (RangeIndexWorker) context.getBroker().getIndexController().getWorkerByIndexId(RangeIndex.ID);
-
try {
preselectResult = index.queryField(getExpressionId(), docs, useContext ? contextSequence.toNodeSet() : null, fieldSeq, keys, operators, NodeSet.DESCENDANT);
} catch (IOException e) {
@@ -217,6 +218,7 @@ public NodeSet preSelect(Sequence contextSequence, boolean useContext) throws XP
if( context.getProfiler().traceFunctions() ) {
context.getProfiler().traceIndexUsage( context, "new-range", this, PerformanceStats.OPTIMIZED_INDEX, System.currentTimeMillis() - start );
}
+ //preselectResult.setSelfAsContext(getContextId());
return preselectResult;
}
@@ -273,6 +275,9 @@ public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathExc
try {
result = index.queryField(getExpressionId(), docs, contextSet, fields, keys, operators, NodeSet.DESCENDANT);
+ if (contextSet != null) {
+ result = result.selectAncestorDescendant(contextSet, NodeSet.DESCENDANT, true, getContextId(), true);
+ }
} catch (IOException e) {
throw new XPathException(this, e.getMessage());
}
@@ -283,7 +288,7 @@ public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathExc
// LOG.info("eval plain took " + (System.currentTimeMillis() - start));
} else {
long start = System.currentTimeMillis();
- result = preselectResult.selectAncestorDescendant(contextSequence.toNodeSet(), NodeSet.ANCESTOR, true, getExpressionId(), true);
+ result = preselectResult.selectAncestorDescendant(contextSequence.toNodeSet(), NodeSet.DESCENDANT, true, getContextId(), true);
LOG.info("eval took " + (System.currentTimeMillis() - start));
}
return result;
@@ -71,7 +71,7 @@ public boolean rewriteLocationStep(LocationStep locationStep) throws XPathExcept
List<LocationStep> steps = getStepsToOptimize(innerExpr);
if (steps == null) {
// no optimizable steps found
- break;
+ continue;
}
// compute left hand path
NodePath innerPath = toNodePath(steps);
@@ -137,7 +137,7 @@ private boolean tryRewriteToFields(LocationStep locationStep, RewritableExpressi
// find a range index configuration matching the full path to the predicate expression
RangeIndexConfigElement rice = findConfiguration(path, true);
// found index configuration with sub-fields
- if (rice != null && rice.isComplex() && rice.getNodePath().match(contextPath)) {
+ if (rice != null && rice.isComplex() && rice.getNodePath().match(contextPath) && findConfiguration(path, false) == null) {
// check for a matching sub-path and retrieve field information
RangeIndexConfigField field = ((ComplexRangeIndexConfigElement) rice).getField(path);
if (field != null) {
@@ -255,7 +255,8 @@ private RangeIndexConfigElement findConfiguration(NodePath path, boolean complex
for (Object configObj : configs) {
final RangeIndexConfig config = (RangeIndexConfig) configObj;
final RangeIndexConfigElement rice = config.find(path);
- if (rice != null && (!complex || rice.isComplex())) {
+ if (rice != null && ((complex && rice.isComplex()) ||
+ (!complex && !rice.isComplex()))) {
return rice;
}
}
View
No changes.
@@ -342,8 +342,8 @@ function ot:eq-field-multi($city as xs:string, $street as xs:string) {
declare
%test:stats
%test:args("Rüsselsheim", "Elefantenweg 67")
- %test:assertXPath("empty($result//stats:index[@type = 'new-range'][@optimization = 2])")
-function ot:no-optimize-mixed-op-field($city as xs:string, $street as xs:string) {
+ %test:assertXPath("$result//stats:index[@type = 'new-range'][@optimization = 2]")
+function ot:optimize-mixed-op-field($city as xs:string, $street as xs:string) {
collection($ot:COLLECTION)//address[city > $city][street = $street]
};
@@ -385,13 +385,6 @@ function ot:optimize-lt-field-nested($email as xs:string) {
collection($ot:COLLECTION)//address[contact/email < $email]
};
-declare
- %test:args("berta@milchview.org")
- %test:assertEquals(1)
-function ot:optimize-lt-field-nested($email as xs:string) {
- count(collection($ot:COLLECTION)//address[contact/email < $email])
-};
-
declare
%test:args("main", "official", "Hofthiergarten")
%test:assertEquals("Hofthiergarten")
View
No changes.
@@ -0,0 +1,12 @@
+package xquery.range;
+
+
+import xquery.TestRunner;
+
+public class RunTests extends TestRunner {
+
+ @Override
+ protected String getDirectory() {
+ return "extensions/indexes/range/test/src/xquery";
+ }
+}
@@ -2,5 +2,12 @@ xquery version "3.0";
import module namespace test="http://exist-db.org/xquery/xqsuite"
at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
+import module namespace rt="http://exist-db.org/xquery/range/test/fields" at "file:extensions/indexes/range/test/src/xquery/fields.xql";
+import module namespace ot="http://exist-db.org/xquery/range/optimizer/test" at "file:extensions/indexes/range/test/src/xquery/optimizer.xql";
+import module namespace rtt="http://exist-db.org/xquery/range/test" at "file:extensions/indexes/range/test/src/xquery/range.xql";
-test:suite(inspect:module-functions(xs:anyURI("file:extensions/indexes/range/test/src/xquery/range.xql")))
+test:suite((
+ util:list-functions(xs:anyURI("http://exist-db.org/xquery/range/test")),
+ util:list-functions(xs:anyURI("http://exist-db.org/xquery/range/test/fields")),
+ util:list-functions(xs:anyURI("http://exist-db.org/xquery/range/optimizer/test"))
+))

0 comments on commit 2f815e1

Please sign in to comment.