From: Wolfgang M. M. <wol...@us...> - 2004-05-05 18:05:54
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/xquery In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11582/src/org/exist/xquery Modified Files: Variable.java LocationStep.java Expression.java VariableReference.java AbstractExpression.java ForExpr.java XQueryContext.java PathExpr.java Log Message: Some optimizations to speed up the evaluation of path expressions inside return clauses: the for expression now passes the current context document set to the bound variable, so path expressions accessing the variable can use this information to get a hint about the total set of documents to expect. This information is used by class LocationStep to pre-load matching element nodes - not only for the current document, but for all documents that might be required for subsequent iterations. Index: LocationStep.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/LocationStep.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** LocationStep.java 3 May 2004 13:08:45 -0000 1.5 --- LocationStep.java 5 May 2004 18:05:41 -0000 1.6 *************** *** 196,200 **** ((VirtualNodeSet) result).setInPredicate(inPredicate); } else { ! DocumentSet docs = contextSet.getDocumentSet(); if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) { currentDocs = docs; --- 196,201 ---- ((VirtualNodeSet) result).setInPredicate(inPredicate); } else { ! // DocumentSet docs = contextSet.getDocumentSet(); ! DocumentSet docs = getDocumentSet(contextSet); if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) { currentDocs = docs; *************** *** 209,213 **** NodeSet.DESCENDANT, inPredicate); - } else { result = --- 210,213 ---- *************** *** 230,234 **** return vset; } else { ! DocumentSet docs = contextSet.getDocumentSet(); if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) { currentDocs = docs; --- 230,235 ---- return vset; } else { ! // DocumentSet docs = contextSet.getDocumentSet(); ! DocumentSet docs = getDocumentSet(contextSet); if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) { currentDocs = docs; *************** *** 259,263 **** return vset; } else { ! DocumentSet docs = contextSet.getDocumentSet(); if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) { currentDocs = docs; --- 260,265 ---- return vset; } else { ! DocumentSet docs = getDocumentSet(contextSet); ! // DocumentSet docs = contextSet.getDocumentSet(); if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) { currentDocs = docs; *************** *** 288,292 **** NodeSet result; if (!test.isWildcardTest()) { ! DocumentSet docs = contextSet.getDocumentSet(); if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) { currentDocs = docs; --- 290,295 ---- NodeSet result; if (!test.isWildcardTest()) { ! DocumentSet docs = getDocumentSet(contextSet); ! // DocumentSet docs = contextSet.getDocumentSet(); if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) { currentDocs = docs; *************** *** 334,338 **** NodeSet result = NodeSet.EMPTY_SET; if(!test.isWildcardTest()) { ! DocumentSet docs = contextSet.getDocumentSet(); if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) { currentDocs = docs; --- 337,342 ---- NodeSet result = NodeSet.EMPTY_SET; if(!test.isWildcardTest()) { ! DocumentSet docs = getDocumentSet(contextSet); ! // DocumentSet docs = contextSet.getDocumentSet(); if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) { currentDocs = docs; *************** *** 352,356 **** NodeSet result; if (!test.isWildcardTest()) { ! DocumentSet docs = contextSet.getDocumentSet(); if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) { currentDocs = docs; --- 356,361 ---- NodeSet result; if (!test.isWildcardTest()) { ! // DocumentSet docs = contextSet.getDocumentSet(); ! DocumentSet docs = getDocumentSet(contextSet); if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) { currentDocs = docs; *************** *** 390,393 **** --- 395,405 ---- } + protected DocumentSet getDocumentSet(NodeSet contextSet) { + DocumentSet ds = getContextDocSet(); + if(ds == null) + ds = contextSet.getDocumentSet(); + return ds; + } + /* (non-Javadoc) * @see org.exist.xpath.Step#resetState() Index: Variable.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/Variable.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Variable.java 29 Jan 2004 15:06:41 -0000 1.1 --- Variable.java 5 May 2004 18:05:41 -0000 1.2 *************** *** 23,26 **** --- 23,27 ---- package org.exist.xquery; + import org.exist.dom.DocumentSet; import org.exist.dom.QName; import org.exist.xquery.value.Sequence; *************** *** 37,41 **** private int positionInStack = 0; private int cardinality = Cardinality.ZERO_OR_MORE; ! /** * --- 38,42 ---- private int positionInStack = 0; private int cardinality = Cardinality.ZERO_OR_MORE; ! private DocumentSet contextDocs = null; /** * *************** *** 79,81 **** --- 80,90 ---- positionInStack = position; } + + public DocumentSet getContextDocs() { + return contextDocs; + } + + public void setContextDocs(DocumentSet docs) { + this.contextDocs = docs; + } } Index: AbstractExpression.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/AbstractExpression.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AbstractExpression.java 21 Feb 2004 17:56:40 -0000 1.2 --- AbstractExpression.java 5 May 2004 18:05:41 -0000 1.3 *************** *** 22,25 **** --- 22,26 ---- package org.exist.xquery; + import org.exist.dom.DocumentSet; import org.exist.dom.NodeProxy; import org.exist.xquery.parser.XQueryAST; *************** *** 34,37 **** --- 35,40 ---- protected XQueryAST astNode = null; + protected DocumentSet contextDocSet = null; + public AbstractExpression(XQueryContext context) { this.context = context; *************** *** 88,91 **** --- 91,106 ---- } + + /* (non-Javadoc) + * @see org.exist.xquery.Expression#setContextDocSet(org.exist.dom.DocumentSet) + */ + public void setContextDocSet(DocumentSet contextSet) { + this.contextDocSet = contextSet; + } + + public DocumentSet getContextDocSet() { + return contextDocSet; + } + public void setASTNode(XQueryAST ast) { this.astNode = ast; Index: ForExpr.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/ForExpr.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ForExpr.java 17 Feb 2004 15:04:58 -0000 1.2 --- ForExpr.java 5 May 2004 18:05:41 -0000 1.3 *************** *** 23,27 **** --- 23,29 ---- package org.exist.xquery; + import org.exist.dom.DocumentSet; import org.exist.dom.NodeProxy; + import org.exist.dom.NodeSet; import org.exist.dom.QName; import org.exist.xquery.value.IntegerValue; *************** *** 72,76 **** --- 74,83 ---- // evaluate the "in" expression Sequence in = inputSequence.eval(null, null); + // assign to the bound variable var.setValue(in); + if(in instanceof NodeSet) { + DocumentSet contextDocs = ((NodeSet)in).getDocumentSet(); + var.setContextDocs(contextDocs); + } if(whereExpr != null) { whereExpr.setInPredicate(true); *************** *** 86,90 **** in = applyWhereExpression(in); } ! if(resultSequence == null) { if(orderSpecs != null) --- 93,98 ---- in = applyWhereExpression(in); } ! // if there's an order by clause, wrap the result into ! // an OrderedValueSequence if(resultSequence == null) { if(orderSpecs != null) Index: XQueryContext.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/XQueryContext.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** XQueryContext.java 3 May 2004 12:51:53 -0000 1.12 --- XQueryContext.java 5 May 2004 18:05:41 -0000 1.13 *************** *** 100,104 **** */ private DocumentSet staticDocuments = null; ! private DBBroker broker; --- 100,104 ---- */ private DocumentSet staticDocuments = null; ! private DBBroker broker; *************** *** 306,310 **** return staticDocuments; } ! public void reset() { builder = null; --- 306,310 ---- return staticDocuments; } ! public void reset() { builder = null; Index: Expression.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/Expression.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Expression.java 21 Feb 2004 17:56:39 -0000 1.2 --- Expression.java 5 May 2004 18:05:41 -0000 1.3 *************** *** 22,25 **** --- 22,26 ---- package org.exist.xquery; + import org.exist.dom.DocumentSet; import org.exist.xquery.parser.XQueryAST; import org.exist.xquery.value.Item; *************** *** 128,131 **** --- 129,134 ---- public String pprint(); + public void setContextDocSet(DocumentSet contextSet); + public XQueryAST getASTNode(); Index: VariableReference.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/VariableReference.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** VariableReference.java 21 Feb 2004 17:56:39 -0000 1.3 --- VariableReference.java 5 May 2004 18:05:41 -0000 1.4 *************** *** 116,119 **** --- 116,128 ---- } + public Variable getVariable() { + try { + Variable var = context.resolveVariable(qname); + return var; + } catch (XPathException e) { + return null; + } + } + /* (non-Javadoc) * @see org.exist.xpath.AbstractExpression#resetState() Index: PathExpr.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/PathExpr.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PathExpr.java 16 Apr 2004 14:44:24 -0000 1.3 --- PathExpr.java 5 May 2004 18:05:41 -0000 1.4 *************** *** 26,30 **** import org.apache.log4j.Logger; - import org.exist.dom.DocumentImpl; import org.exist.dom.DocumentSet; import org.exist.dom.NodeSet; --- 26,29 ---- *************** *** 46,50 **** protected static Logger LOG = Logger.getLogger( PathExpr.class ); ! protected DocumentSet inputDocumentSet = new DocumentSet(); protected boolean keepVirtual = false; protected LinkedList steps = new LinkedList(); --- 45,49 ---- protected static Logger LOG = Logger.getLogger( PathExpr.class ); ! protected boolean keepVirtual = false; protected LinkedList steps = new LinkedList(); *************** *** 79,86 **** } - public void addDocument( DocumentImpl doc ) { - inputDocumentSet.add( doc ); - } - /** * Add another PathExpr to this object's expression list. --- 78,81 ---- *************** *** 113,127 **** r = Sequence.EMPTY_SEQUENCE; } NodeSet set; Item current; - Expression expr; Sequence values; for ( Iterator iter = steps.iterator(); iter.hasNext(); ) { expr = (Expression) iter.next(); if ((expr.getDependencies() & Dependency.CONTEXT_ITEM) != 0) { //LOG.debug("single step mode: " + expr.pprint()); ! if(r.getLength() == 0) r = expr.eval( null, null ); ! else { values = null; if(r.getLength() > 1) --- 108,130 ---- r = Sequence.EMPTY_SEQUENCE; } + DocumentSet contextDocs = null; + Expression expr = (Expression)steps.getFirst(); + if(expr instanceof VariableReference) { + Variable var = ((VariableReference)expr).getVariable(); + if(var != null) + contextDocs = var.getContextDocs(); + } NodeSet set; Item current; Sequence values; for ( Iterator iter = steps.iterator(); iter.hasNext(); ) { expr = (Expression) iter.next(); + if(contextDocs != null) + expr.setContextDocSet(contextDocs); if ((expr.getDependencies() & Dependency.CONTEXT_ITEM) != 0) { //LOG.debug("single step mode: " + expr.pprint()); ! if(r.getLength() == 0) { r = expr.eval( null, null ); ! } else { values = null; if(r.getLength() > 1) *************** *** 150,154 **** public DocumentSet getDocumentSet() { ! return inputDocumentSet; } --- 153,157 ---- public DocumentSet getDocumentSet() { ! return null; } *************** *** 200,207 **** return deps; } - - public void setDocumentSet( DocumentSet docs ) { - this.inputDocumentSet = docs; - } public void setFirstExpression( Expression s ) { --- 203,206 ---- |