← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~paul-lucas/zorba/pjl-misc into lp:zorba

 

Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.

Commit message:
Better iterator tree printing: it's either pure JSON or pure XML.

Requested reviews:
  Paul J. Lucas (paul-lucas)

For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/207355

Better iterator tree printing: it's either pure JSON or pure XML.
-- 
The attached diff has been truncated due to its size.
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/207355
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/codegen/plan_visitor.cpp'
--- src/compiler/codegen/plan_visitor.cpp	2014-02-19 01:53:34 +0000
+++ src/compiler/codegen/plan_visitor.cpp	2014-02-20 05:31:00 +0000
@@ -27,6 +27,7 @@
 
 #include "diagnostics/assert.h"
 #include "util/hashmap32.h"
+#include "util/indent.h"
 #include "util/stl_util.h"
 #include "util/tracer.h"
 
@@ -3812,23 +3813,39 @@
   Zorba_plan_format_t const format = Properties::instance().getPlanFormat();
   if ( result && descr && format ) {
     std::ostream &os = Properties::instance().getDebugStream();
-    os << "Iterator tree for " << descr << ":\n";
     unique_ptr<IterPrinter> printer;
     switch ( format ) {
-      case PLAN_FORMAT_NONE:
-        return result;
       case PLAN_FORMAT_DOT:
         printer.reset( new DOTIterPrinter( os ) );
         break;
       case PLAN_FORMAT_JSON:
+        os << "{\n" << inc_indent
+           << indent << "\"description\": \"" << descr << "\",\n"
+           << indent << "\"iterator-tree\":\n" << inc_indent;
         printer.reset( new JSONIterPrinter( os ) );
         break;
       case PLAN_FORMAT_XML:
+        os << "<iterator-tree description=\"" << descr << "\">\n" << inc_indent;
         printer.reset( new XMLIterPrinter( os ) );
         break;
-    }
+      default: // to silence warning
+        break;
+    } // switch
+
     print_iter_plan( *printer, result );
-    os << std::endl;
+
+    switch ( format ) {
+      case PLAN_FORMAT_DOT:
+        break;
+      case PLAN_FORMAT_JSON:
+        os << dec_indent << dec_indent << indent << "}\n";
+        break;
+      case PLAN_FORMAT_XML:
+        os << dec_indent << indent << "</iterator-tree>\n";
+        break;
+      default: // to silence warning
+        break;
+    } // switch
   }
 
   return result;

=== modified file 'src/runtime/visitors/iterprinter.cpp'
--- src/runtime/visitors/iterprinter.cpp	2014-02-18 19:52:39 +0000
+++ src/runtime/visitors/iterprinter.cpp	2014-02-20 05:31:00 +0000
@@ -22,6 +22,7 @@
 // Zorba
 #include "runtime/visitors/iterprinter.h"
 #include "util/ascii_util.h"
+#include "util/indent.h"
 #include "util/xml_util.h"
 
 using namespace std;
@@ -30,49 +31,55 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-XMLIterPrinter::XMLIterPrinter(ostream& aOStream) :
-  IterPrinter(aOStream),
-  theOpenStart(false)
+IterPrinter::~IterPrinter() {
+  // out-of-line since it's virtual
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+XMLIterPrinter::XMLIterPrinter( ostream &os ) :
+  IterPrinter( os ),
+  theOpenStart( false )
 {
 }
 
+XMLIterPrinter::~XMLIterPrinter() {
+  // out-of-line since it's virtual
+}
+
 void XMLIterPrinter::start() {
 }
 
 void XMLIterPrinter::stop() {
 }
 
-void XMLIterPrinter::startBeginVisit(const string& aName, int) {
-  if (theOpenStart)
-    theOStream << ">\n";
-  printSpaces(2 * theNameStack.size());
-  theOStream << '<' << aName;
-  theNameStack.push(aName);
+void XMLIterPrinter::startBeginVisit( string const &name, int ) {
+  if ( theOpenStart )
+    os_ << ">\n";
+  os_ << indent << '<' << name << inc_indent;
+  theNameStack.push( name );
   theOpenStart = true;
 }
 
-void XMLIterPrinter::endBeginVisit(int) {
-}
-
-void XMLIterPrinter::addAttribute(const string& aName, const string& aValue) {
-  assert(theOpenStart);
-  theOStream << ' ' << aName << "=\"" << aValue << "\"";
-}
-
-void XMLIterPrinter::addAttribute(const string& aName, xs_long aValue) {
-  assert(theOpenStart);
-  theOStream << ' ' << aName << "=\"" << aValue << "\"";
+void XMLIterPrinter::endBeginVisit( int ) {
+}
+
+void XMLIterPrinter::addAttribute( string const &name, string const &value) {
+  assert( theOpenStart );
+  os_ << ' ' << name << "=\"" << value << "\"";
+}
+
+void XMLIterPrinter::addAttribute( string const &name, xs_long value) {
+  assert( theOpenStart );
+  os_ << ' ' << name << "=\"" << value << "\"";
 }
 
 void XMLIterPrinter::startEndVisit() {
-  assert(!theNameStack.empty());
-  if (theOpenStart)
-    theOStream << "/>" << endl;
+  assert( !theNameStack.empty() );
+  if ( theOpenStart )
+    os_ << "/>\n" << dec_indent;
   else
-  {
-    printSpaces(2 * (theNameStack.size() - 1));
-    theOStream << "</" << theNameStack.top() << '>' << endl;
-  }
+    os_ << dec_indent << indent << "</" << theNameStack.top() << ">\n";
   theNameStack.pop();
   theOpenStart = false;
 }
@@ -82,48 +89,42 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-DOTIterPrinter::DOTIterPrinter(ostream& aOStream) :
-  IterPrinter(aOStream),
-  theIndent(0)
-{
+DOTIterPrinter::DOTIterPrinter( ostream &os ) : IterPrinter( os ) {
+}
+
+DOTIterPrinter::~DOTIterPrinter() {
+  // out-of-line since it's virtual
 }
 
 void DOTIterPrinter::start() {
-  theOStream << "digraph {" << endl;
-  theOStream << "node [ color=gray, fontname=\"Arial\" ]" << endl;
+  os_ << indent << "digraph {\n" << inc_indent
+      << indent << "node [ color=gray, fontname=\"Arial\" ]\n";
 }
 
 void DOTIterPrinter::stop() {
-  theOStream << '}' << endl;
-}
-
-void DOTIterPrinter::startBeginVisit(const string& aName, int aAddr) {
-  printSpaces(theIndent);
-  theOStream << aAddr << " [ label=\"" << aName;
-  ++theIndent;
-}
-
-void DOTIterPrinter::endBeginVisit(int aAddr) {
-  --theIndent;
-  printSpaces(theIndent);
-  theOStream << "\"];" << endl;
-  printSpaces(theIndent);
-  if (!theNameStack.empty() && theNameStack.top() != aAddr)
-    theOStream << theNameStack.top() << "->" << aAddr << endl;
-  theNameStack.push(aAddr);
-}
-
-void DOTIterPrinter::addAttribute(const string& aName, const string& aValue) {
-  printSpaces(theIndent);
-  string mvalue( aValue );
-  ascii::replace_all(mvalue, "\"", "\\\"");
-  ascii::replace_all(mvalue, "\n", " \\n ");
-  theOStream << "\\n" << aName << '=' << mvalue;
-}
-
-void DOTIterPrinter::addAttribute(const string& aName, xs_long aValue) {
-  printSpaces(theIndent);
-  theOStream << "\\n" << aName << '=' << aValue;
+  os_ << dec_indent << indent << "}\n";
+}
+
+void DOTIterPrinter::startBeginVisit( string const &name, int addr ) {
+  os_ << indent << addr << " [ label=\"" << name;
+}
+
+void DOTIterPrinter::endBeginVisit( int addr ) {
+  os_ << "\" ];\n";
+  if ( !theNameStack.empty() && theNameStack.top() != addr )
+    os_ << indent << theNameStack.top() << " -> " << addr << endl;
+  theNameStack.push( addr );
+}
+
+void DOTIterPrinter::addAttribute( string const &name, string const &value) {
+  string temp( value );
+  ascii::replace_all( temp, "\"", "\\\"" );
+  ascii::replace_all( temp, "\n", " \\n " );
+  os_ << "\\n" << name << '=' << temp;
+}
+
+void DOTIterPrinter::addAttribute( string const &name, xs_long value) {
+  os_ << indent << "\\n" << name << '=' << value;
 }
 
 void DOTIterPrinter::startEndVisit() {
@@ -135,68 +136,48 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-JSONIterPrinter::JSONIterPrinter(ostream& aOStream) :
-  IterPrinter(aOStream), theIndent(0)
-{
+JSONIterPrinter::JSONIterPrinter( ostream &os ) : IterPrinter( os ) {
+}
+
+JSONIterPrinter::~JSONIterPrinter() {
+  // out-of-line since it's virtual
 }
 
 void JSONIterPrinter::start() {
 }
 
 void JSONIterPrinter::stop() {
-  theOStream << endl;
+  os_ << endl;
 }
 
-void JSONIterPrinter::startBeginVisit(const string& aName, int) {
-  if (!theListStack.empty())
-    theOStream << ',' << endl;
-
-  if (!theListStack.empty() && !theListStack.top()) {
-    printSpaces(2 * theIndent);
-    theOStream << "\"iterators\":" << endl;
-    printSpaces(2 * theIndent);
-    theOStream << '[';
+void JSONIterPrinter::startBeginVisit( string const &name, int ) {
+  if ( !theListStack.empty() )
+    os_ << ',' << endl;
+  if ( !theListStack.empty() && !theListStack.top() ) {
+    os_ << indent << "\"iterators\": [\n" << inc_indent;
     theListStack.pop();
-    theListStack.push(true);
-    theIndent++;
-    theOStream << endl;
+    theListStack.push( true );
   }
-
-  printSpaces(2 * theIndent);
-  theOStream << "{" << endl;
-  printSpaces(2 * (1+theIndent));
-  theOStream << "\"kind\": \"" << aName << "\"";
-  theIndent++;
-  theListStack.push(false);
-}
-
-void JSONIterPrinter::endBeginVisit(int) {
-}
-
-void JSONIterPrinter::addAttribute(const string& aName, const string& aValue) {
-  theOStream << ',' << endl;
-  printSpaces(2 * theIndent);
-  theOStream << "\"" << aName << "\": \"" << aValue << "\"";
-}
-
-void JSONIterPrinter::addAttribute(const string& aName, xs_long aValue) {
-  theOStream << ',' << endl;
-  printSpaces(2 * theIndent);
-  theOStream << "\"" << aName << "\": " << aValue;
+  os_ << indent << "{\n" << inc_indent
+      << indent << "\"kind\": \"" << name << "\"";
+  theListStack.push( false );
+}
+
+void JSONIterPrinter::endBeginVisit( int ) {
+}
+
+void JSONIterPrinter::addAttribute( string const &name, string const &value ) {
+  os_ << ",\n" << indent << "\"" << name << "\": \"" << value << "\"";
+}
+
+void JSONIterPrinter::addAttribute( string const &name, xs_long value ) {
+  os_ << ",\n" << indent << "\"" << name << "\": " << value;
 }
 
 void JSONIterPrinter::startEndVisit() {
-  if (theListStack.top()) {
-    theOStream << endl;
-    printSpaces(2 * (theIndent - 1));
-    theOStream << ']';
-    theIndent--;
-  }
-
-  theOStream << endl;
-  printSpaces(2 * (theIndent - 1));
-  theOStream << '}';
-  theIndent--;
+  if ( theListStack.top() )
+    os_ << '\n' << dec_indent << indent << ']';
+  os_ << '\n' << dec_indent << indent << '}';
   theListStack.pop();
 }
 

=== modified file 'src/runtime/visitors/iterprinter.h'
--- src/runtime/visitors/iterprinter.h	2014-02-18 19:52:39 +0000
+++ src/runtime/visitors/iterprinter.h	2014-02-20 05:31:00 +0000
@@ -17,152 +17,116 @@
 #ifndef ZORBA_VISITORPRINTER_H
 #define ZORBA_VISITORPRINTER_H
 
-#include <string>
+// standard
 #include <ostream>
 #include <stack>
+#include <string>
 
+// Zorba
 #include "common/common.h"
 #include "zorbatypes/schema_types.h"
 
-
-namespace yy 
-{
-  class location;
-}
-
 namespace zorba {
 
-/**
- * Interface to print the PlanIterators.
- */
-class IterPrinter 
-{
+///////////////////////////////////////////////////////////////////////////////
+
+class IterPrinter {
 public:
-  IterPrinter(std::ostream& aOStream) : theOStream(aOStream) {}
-
-  virtual ~IterPrinter() {}
+  IterPrinter( std::ostream &os ) : os_( os ) { }
+  virtual ~IterPrinter();
 
   virtual void start() = 0;
   virtual void stop() = 0;
 
-  virtual void startBeginVisit(const std::string& aName, int aAddr) = 0;
-  virtual void endBeginVisit(int aAddr) = 0;
-
-  virtual void addAttribute(const std::string& aName, const std::string& aValue) = 0;
-
-  virtual void addAttribute(const std::string& aName, xs_long aValue) = 0;
+  virtual void startBeginVisit( std::string const &name, int addr ) = 0;
+  virtual void endBeginVisit( int addr ) = 0;
+
+  virtual void addAttribute( std::string const &name, std::string const &value ) = 0;
+
+  virtual void addAttribute( std::string const &name, xs_long value ) = 0;
 
   virtual void startEndVisit() = 0;
-
   virtual void endEndVisit() = 0;
 
 protected:  
-  std::ostream& theOStream;
-  void printSpaces(size_t aNr) { theOStream << std::string(aNr, ' '); }
-}; /* class VisitorPrinter */
-
-  
-/**
- * Implementation of IterPrinter to print a PlanIterator tree in XML format
- */
-class XMLIterPrinter : public IterPrinter 
-{
+  std::ostream &os_;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+class XMLIterPrinter : public IterPrinter {
+public:
+  XMLIterPrinter( std::ostream& );
+  ~XMLIterPrinter();
+
+  virtual void start();
+  virtual void stop();
+
+  virtual void startBeginVisit( std::string const &name, int addr );
+  virtual void endBeginVisit( int addr );
+
+  virtual void addAttribute( std::string const &name, std::string const &value );
+  virtual void addAttribute( std::string const &name, xs_long value );
+
+  virtual void startEndVisit();
+  virtual void endEndVisit();
+
 private:
+  std::stack<std::string> theNameStack;
   bool theOpenStart;
-  std::stack<std::string> theNameStack;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+class DOTIterPrinter : public IterPrinter {
+public:
+  DOTIterPrinter( std::ostream& );
+  ~DOTIterPrinter();
       
-public:
-  XMLIterPrinter(std::ostream& aOStream);
-
-  virtual ~XMLIterPrinter(){}
-
-  virtual void start();
-
-  virtual void stop();
-
-  virtual void startBeginVisit(const std::string& aName, int aAddr);
-
-  virtual void endBeginVisit(int aAddr);
-
-  virtual void addAttribute(const std::string& aName, const std::string& aValue);
-
-  virtual void addAttribute(const std::string& aName, xs_long aValue);
-
-  virtual void startEndVisit();
-
-  virtual void endEndVisit();
-}; /* class XMLVisitorPrinter */
-
-
-/**
- * Implementation of IterPrinter to print a PlanIterator tree in DOT format
- */
-class DOTIterPrinter : public IterPrinter 
-{
+  void start();
+  void stop();
+
+  void startBeginVisit( std::string const &name, int addr );
+  void endBeginVisit( int addr );
+
+  void addAttribute( std::string const &name, std::string const &value );
+  void addAttribute( std::string const &name, xs_long value );
+
+  void startEndVisit();
+  void endEndVisit();
+
 private:
   std::stack<int> theNameStack;
-  uint32_t        theIndent;
-      
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+class JSONIterPrinter : public IterPrinter {
 public:
-  DOTIterPrinter(std::ostream& aOStream);
-
-  virtual ~DOTIterPrinter(){}
-      
-  virtual void start();
-
-  virtual void stop();
-
-  virtual void startBeginVisit(const std::string& aName, int aAddr);
-
-  virtual void endBeginVisit(int aAddr);
-
-  virtual void addAttribute(const std::string& aName, const std::string& aValue);
-
-  virtual void addAttribute(const std::string& aName, xs_long aValue);
-
-  virtual void startEndVisit();
-
-  virtual void endEndVisit();
-  
-}; /* class DOTVisitorPrinter */
-
-/**
- * Implementation of IterPrinter to print a PlanIterator tree in JSON format
- */
-class JSONIterPrinter : public IterPrinter
-{
+  JSONIterPrinter( std::ostream& );
+  ~JSONIterPrinter();
+
+  void start();
+  void stop();
+
+  void startBeginVisit( std::string const &name, int addr );
+  void endBeginVisit( int addr );
+
+  void addAttribute( std::string const &name, std::string const &value );
+  void addAttribute( std::string const &name, xs_long value );
+
+  void startEndVisit();
+  void endEndVisit();
+
 private:
-  uint32_t        theIndent;
   std::stack<bool> theListStack;
-
-public:
-  JSONIterPrinter(std::ostream& aOStream);
-
-  virtual ~JSONIterPrinter(){}
-
-  virtual void start();
-
-  virtual void stop();
-
-  virtual void startBeginVisit(const std::string& aName, int aAddr);
-
-  virtual void endBeginVisit(int aAddr);
-
-  virtual void addAttribute(const std::string& aName, const std::string& aValue);
-
-  virtual void addAttribute(const std::string& aName, xs_long aValue);
-
-  virtual void startEndVisit();
-
-  virtual void endEndVisit();
-}; /* class JSONVisitorPrinter */
-
-
-
-} /* namespace zorba */
-
-#endif
-
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+} // namespace zorba
+
+#endif /* ZORBA_VISITORPRINTER_H */
 /*
  * Local variables:
  * mode: c++

=== modified file 'test/iterplans/update_iter_plans'
--- test/iterplans/update_iter_plans	2013-07-11 06:54:25 +0000
+++ test/iterplans/update_iter_plans	2014-02-20 05:31:00 +0000
@@ -1,7 +1,17 @@
-#!/bin/bash
+#! /bin/bash
+
+# uncomment for dry run
+#ECHO=echo
+
 BUILDDIR=$1
 test -e "$BUILDDIR" || { echo "Arguments: BUILD_DIR"; exit 1; }
+
 D=$BUILDDIR/test/iterplans
-for f in `cd $D; find . -name *.iter`; do
- cp $D/$f `dirname $0`/iterplans/$f
+
+for src_file in `cd $D; find . -name *.spec`
+do
+  dst_file=${src_file%.spec}.iter
+  $ECHO cp $D/$src_file $dst_file
 done
+
+# vim:set et sw=2 ts=2:

=== modified file 'test/iterplans/zorba/collections/count_dynamic_zorba_collection.iter'
--- test/iterplans/zorba/collections/count_dynamic_zorba_collection.iter	2013-03-24 20:40:03 +0000
+++ test/iterplans/zorba/collections/count_dynamic_zorba_collection.iter	2014-02-20 05:31:00 +0000
@@ -1,19 +1,19 @@
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="coll">
-    <SingletonIterator value="xs:QName(,,collection)"/>
-  </CtxVarDeclareIterator>
+<iterator-tree description="main query">
   <SequentialIterator>
-    <ApplyIterator>
-      <ZorbaCreateCollectionIterator>
-        <CtxVarIterator varid="4" varname="coll" varkind="global"/>
-      </ZorbaCreateCollectionIterator>
-    </ApplyIterator>
-    <FnCountIterator>
-      <ZorbaCollectionIterator>
-        <CtxVarIterator varid="4" varname="coll" varkind="global"/>
-      </ZorbaCollectionIterator>
-    </FnCountIterator>
+    <CtxVarDeclareIterator varid="4" varname="coll">
+      <SingletonIterator value="xs:QName(,,collection)"/>
+    </CtxVarDeclareIterator>
+    <SequentialIterator>
+      <ApplyIterator>
+        <ZorbaCreateCollectionIterator>
+          <CtxVarIterator varid="4" varname="coll" varkind="global"/>
+        </ZorbaCreateCollectionIterator>
+      </ApplyIterator>
+      <FnCountIterator>
+        <ZorbaCollectionIterator>
+          <CtxVarIterator varid="4" varname="coll" varkind="global"/>
+        </ZorbaCollectionIterator>
+      </FnCountIterator>
+    </SequentialIterator>
   </SequentialIterator>
-</SequentialIterator>
-
+</iterator-tree>

=== modified file 'test/iterplans/zorba/collections/count_static_zorba_collection.iter'
--- test/iterplans/zorba/collections/count_static_zorba_collection.iter	2013-03-24 20:40:03 +0000
+++ test/iterplans/zorba/collections/count_static_zorba_collection.iter	2014-02-20 05:31:00 +0000
@@ -1,37 +1,37 @@
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="ns:collection_1">
-    <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,collection_1)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="5" varname="ns:collection_2">
-    <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,collection_2)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="6" varname="ns:http">
-    <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,http)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="7" varname="ns:test1">
-    <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,test1)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="8" varname="ns:test2">
-    <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,test2)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="9" varname="ns:test3">
-    <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,test3)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="10" varname="coll">
-    <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,test1)"/>
-  </CtxVarDeclareIterator>
+<iterator-tree description="main query">
   <SequentialIterator>
-    <ApplyIterator>
-      <ZorbaCreateCollectionIterator>
-        <CtxVarIterator varid="10" varname="coll" varkind="global"/>
-      </ZorbaCreateCollectionIterator>
-    </ApplyIterator>
-    <FnCountIterator>
-      <ZorbaCollectionIterator>
-        <CtxVarIterator varid="10" varname="coll" varkind="global"/>
-      </ZorbaCollectionIterator>
-    </FnCountIterator>
+    <CtxVarDeclareIterator varid="4" varname="ns:collection_1">
+      <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,collection_1)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="5" varname="ns:collection_2">
+      <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,collection_2)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="6" varname="ns:http">
+      <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,http)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="7" varname="ns:test1">
+      <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,test1)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="8" varname="ns:test2">
+      <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,test2)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="9" varname="ns:test3">
+      <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,test3)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="10" varname="coll">
+      <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,test1)"/>
+    </CtxVarDeclareIterator>
+    <SequentialIterator>
+      <ApplyIterator>
+        <ZorbaCreateCollectionIterator>
+          <CtxVarIterator varid="10" varname="coll" varkind="global"/>
+        </ZorbaCreateCollectionIterator>
+      </ApplyIterator>
+      <FnCountIterator>
+        <ZorbaCollectionIterator>
+          <CtxVarIterator varid="10" varname="coll" varkind="global"/>
+        </ZorbaCollectionIterator>
+      </FnCountIterator>
+    </SequentialIterator>
   </SequentialIterator>
-</SequentialIterator>
-
+</iterator-tree>

=== modified file 'test/iterplans/zorba/collections/count_w3c_collection.iter'
--- test/iterplans/zorba/collections/count_w3c_collection.iter	2013-10-09 02:40:46 +0000
+++ test/iterplans/zorba/collections/count_w3c_collection.iter	2014-02-20 05:31:00 +0000
@@ -1,29 +1,29 @@
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="coll">
-    <SingletonIterator value="xs:string(http://zorba.io/collection)"/>
-  </CtxVarDeclareIterator>
+<iterator-tree description="main query">
   <SequentialIterator>
-    <ApplyIterator>
-      <UDFunctionCallIterator function="ddl:create">
-        <CtxVarIterator varid="4" varname="coll" varkind="global"/>
-      </UDFunctionCallIterator>
-    </ApplyIterator>
-    <FnCountIterator>
-      <FnCollectionIterator>
-        <CtxVarIterator varid="4" varname="coll" varkind="global"/>
-      </FnCollectionIterator>
-    </FnCountIterator>
+    <CtxVarDeclareIterator varid="4" varname="coll">
+      <SingletonIterator value="xs:string(http://zorba.io/collection)"/>
+    </CtxVarDeclareIterator>
+    <SequentialIterator>
+      <ApplyIterator>
+        <UDFunctionCallIterator function="ddl:create">
+          <CtxVarIterator varid="4" varname="coll" varkind="global"/>
+        </UDFunctionCallIterator>
+      </ApplyIterator>
+      <FnCountIterator>
+        <FnCollectionIterator>
+          <CtxVarIterator varid="4" varname="coll" varkind="global"/>
+        </FnCollectionIterator>
+      </FnCountIterator>
+    </SequentialIterator>
   </SequentialIterator>
-</SequentialIterator>
-
-Iterator tree for ddl:create:
-<ZorbaCreateCollectionIterator>
-  <FunctionTraceIterator>
-    <QNameIterator>
-      <LetVarIterator varname="uri"/>
-      <SingletonIterator value="xs:string(zorba-internal-name-for-w3c-collections)"/>
-    </QNameIterator>
-  </FunctionTraceIterator>
-</ZorbaCreateCollectionIterator>
-
+</iterator-tree>
+<iterator-tree description="ddl:create">
+  <ZorbaCreateCollectionIterator>
+    <FunctionTraceIterator>
+      <QNameIterator>
+        <LetVarIterator varname="uri"/>
+        <SingletonIterator value="xs:string(zorba-internal-name-for-w3c-collections)"/>
+      </QNameIterator>
+    </FunctionTraceIterator>
+  </ZorbaCreateCollectionIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/collections/no_copy_01.iter'
--- test/iterplans/zorba/collections/no_copy_01.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/collections/no_copy_01.iter	2014-02-20 05:31:00 +0000
@@ -1,61 +1,61 @@
-Iterator tree for main query:
-<SequentialIterator>
-  <ApplyIterator>
-    <ZorbaCreateCollectionIterator>
-      <SingletonIterator value="xs:QName(http://www.w3.org/2005/xquery-local-functions,local,bar)"/>
-    </ZorbaCreateCollectionIterator>
-  </ApplyIterator>
-  <FnConcatIterator>
-    <MaterializeIterator>
-      <FLWORIterator>
-        <ForVariable name="n">
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,a)"/>
-          </ElementIterator>
-        </ForVariable>
-        <MaterializeClause>
-          <MaterializeForVariable inputVar="n : "/>
-        </MaterializeClause>
-        <ReturnClause>
-          <IsSameNodeIterator>
-            <ForVarIterator varname="n"/>
-            <MaterializeIterator>
-              <TreatIterator type="[NodeXQType anyNode content=[XQType ANY_TYPE_KIND*]]" quant="?">
-                <ZorbaApplyInsertLastIterator is-dynamic="true" need-to-copy="true">
-                  <SingletonIterator value="xs:QName(http://www.w3.org/2005/xquery-local-functions,local,bar)"/>
-                  <ForVarIterator varname="n"/>
-                </ZorbaApplyInsertLastIterator>
-              </TreatIterator>
-            </MaterializeIterator>
-          </IsSameNodeIterator>
-        </ReturnClause>
-      </FLWORIterator>
-    </MaterializeIterator>
-    <MaterializeIterator>
-      <FLWORIterator>
-        <ForVariable name="n">
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,a)"/>
-          </ElementIterator>
-        </ForVariable>
-        <MaterializeClause>
-          <MaterializeForVariable inputVar="n : "/>
-        </MaterializeClause>
-        <ReturnClause>
-          <IsSameNodeIterator>
-            <ForVarIterator varname="n"/>
-            <MaterializeIterator>
-              <TreatIterator type="[NodeXQType anyNode content=[XQType ANY_TYPE_KIND*]]" quant="?">
-                <ZorbaApplyInsertLastIterator is-dynamic="true">
-                  <SingletonIterator value="xs:QName(http://www.w3.org/2005/xquery-local-functions,local,bar)"/>
-                  <ForVarIterator varname="n"/>
-                </ZorbaApplyInsertLastIterator>
-              </TreatIterator>
-            </MaterializeIterator>
-          </IsSameNodeIterator>
-        </ReturnClause>
-      </FLWORIterator>
-    </MaterializeIterator>
-  </FnConcatIterator>
-</SequentialIterator>
-
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <ApplyIterator>
+      <ZorbaCreateCollectionIterator>
+        <SingletonIterator value="xs:QName(http://www.w3.org/2005/xquery-local-functions,local,bar)"/>
+      </ZorbaCreateCollectionIterator>
+    </ApplyIterator>
+    <FnConcatIterator>
+      <MaterializeIterator>
+        <FLWORIterator>
+          <ForVariable name="n">
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,a)"/>
+            </ElementIterator>
+          </ForVariable>
+          <MaterializeClause>
+            <MaterializeForVariable inputVar="n : "/>
+          </MaterializeClause>
+          <ReturnClause>
+            <IsSameNodeIterator>
+              <ForVarIterator varname="n"/>
+              <MaterializeIterator>
+                <TreatIterator type="[NodeXQType anyNode content=[XQType ANY_TYPE_KIND*]]" quant="?">
+                  <ZorbaApplyInsertLastIterator is-dynamic="true" need-to-copy="true">
+                    <SingletonIterator value="xs:QName(http://www.w3.org/2005/xquery-local-functions,local,bar)"/>
+                    <ForVarIterator varname="n"/>
+                  </ZorbaApplyInsertLastIterator>
+                </TreatIterator>
+              </MaterializeIterator>
+            </IsSameNodeIterator>
+          </ReturnClause>
+        </FLWORIterator>
+      </MaterializeIterator>
+      <MaterializeIterator>
+        <FLWORIterator>
+          <ForVariable name="n">
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,a)"/>
+            </ElementIterator>
+          </ForVariable>
+          <MaterializeClause>
+            <MaterializeForVariable inputVar="n : "/>
+          </MaterializeClause>
+          <ReturnClause>
+            <IsSameNodeIterator>
+              <ForVarIterator varname="n"/>
+              <MaterializeIterator>
+                <TreatIterator type="[NodeXQType anyNode content=[XQType ANY_TYPE_KIND*]]" quant="?">
+                  <ZorbaApplyInsertLastIterator is-dynamic="true">
+                    <SingletonIterator value="xs:QName(http://www.w3.org/2005/xquery-local-functions,local,bar)"/>
+                    <ForVarIterator varname="n"/>
+                  </ZorbaApplyInsertLastIterator>
+                </TreatIterator>
+              </MaterializeIterator>
+            </IsSameNodeIterator>
+          </ReturnClause>
+        </FLWORIterator>
+      </MaterializeIterator>
+    </FnConcatIterator>
+  </SequentialIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/dblp/q0.iter'
--- test/iterplans/zorba/dblp/q0.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/dblp/q0.iter	2014-02-20 05:31:00 +0000
@@ -1,182 +1,182 @@
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="input-context"/>
-  <FLWORIterator>
-    <LetVariable name="doc" materialize="true">
-      <FnDocIterator>
-        <PromoteIterator type="xs:string">
-          <FnDataIterator>
-            <CtxVarIterator varid="4" varname="input-context" varkind="global"/>
-          </FnDataIterator>
-        </PromoteIterator>
-      </FnDocIterator>
-    </LetVariable>
-    <LetVariable name="$$opt_temp_1" materialize="true">
-      <HoistIterator>
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,dblp)" typename="*" nill allowed="0">
-          <LetVarIterator varname="doc"/>
-        </ChildAxisIterator>
-      </HoistIterator>
-    </LetVariable>
-    <LetVariable name="$$opt_temp_0" materialize="true">
-      <HoistIterator>
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,dblp)" typename="*" nill allowed="0">
-          <LetVarIterator varname="doc"/>
-        </ChildAxisIterator>
-      </HoistIterator>
-    </LetVariable>
-    <ReturnClause>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,statistics)"/>
-        <FnConcatIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,total)"/>
-            <FnConcatIterator>
-              <ElementIterator>
-                <SingletonIterator value="xs:QName(,,paper)"/>
-                <EnclosedIterator attr_cont="false">
-                  <FnCountIterator>
-                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,inproceedings)" typename="*" nill allowed="0">
-                      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,dblp)" typename="*" nill allowed="0">
-                        <LetVarIterator varname="doc"/>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <CtxVarDeclareIterator varid="4" varname="input-context"/>
+    <FLWORIterator>
+      <LetVariable name="doc" materialize="true">
+        <FnDocIterator>
+          <PromoteIterator type="xs:string">
+            <FnDataIterator>
+              <CtxVarIterator varid="4" varname="input-context" varkind="global"/>
+            </FnDataIterator>
+          </PromoteIterator>
+        </FnDocIterator>
+      </LetVariable>
+      <LetVariable name="$$opt_temp_1" materialize="true">
+        <HoistIterator>
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,dblp)" typename="*" nill allowed="0">
+            <LetVarIterator varname="doc"/>
+          </ChildAxisIterator>
+        </HoistIterator>
+      </LetVariable>
+      <LetVariable name="$$opt_temp_0" materialize="true">
+        <HoistIterator>
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,dblp)" typename="*" nill allowed="0">
+            <LetVarIterator varname="doc"/>
+          </ChildAxisIterator>
+        </HoistIterator>
+      </LetVariable>
+      <ReturnClause>
+        <ElementIterator>
+          <SingletonIterator value="xs:QName(,,statistics)"/>
+          <FnConcatIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,total)"/>
+              <FnConcatIterator>
+                <ElementIterator>
+                  <SingletonIterator value="xs:QName(,,paper)"/>
+                  <EnclosedIterator attr_cont="false">
+                    <FnCountIterator>
+                      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,inproceedings)" typename="*" nill allowed="0">
+                        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,dblp)" typename="*" nill allowed="0">
+                          <LetVarIterator varname="doc"/>
+                        </ChildAxisIterator>
                       </ChildAxisIterator>
-                    </ChildAxisIterator>
-                  </FnCountIterator>
-                </EnclosedIterator>
-              </ElementIterator>
-              <ElementIterator>
-                <SingletonIterator value="xs:QName(,,author)"/>
-                <EnclosedIterator attr_cont="false">
-                  <FnCountIterator>
-                    <FnDistinctValuesIterator>
-                      <FnDataIterator>
-                        <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-                          <LetVarIterator varname="doc"/>
-                        </DescendantAxisIterator>
-                      </FnDataIterator>
-                    </FnDistinctValuesIterator>
-                  </FnCountIterator>
-                </EnclosedIterator>
-              </ElementIterator>
-            </FnConcatIterator>
-          </ElementIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,conferences)"/>
-            <EnclosedIterator attr_cont="false">
-              <FLWORIterator>
-                <ForVariable name="conference">
-                  <FnConcatIterator>
-                    <SingletonIterator value="xs:string(EDBT)"/>
-                    <SingletonIterator value="xs:string(ICDT)"/>
-                    <SingletonIterator value="xs:string(ICDE)"/>
-                    <SingletonIterator value="xs:string(PODS)"/>
-                    <SingletonIterator value="xs:string(VLDB)"/>
-                    <SingletonIterator value="xs:string(SIGMOD Conference)"/>
-                  </FnConcatIterator>
-                </ForVariable>
-                <ReturnClause>
-                  <ElementIterator>
-                    <SingletonIterator value="xs:QName(,,conference)"/>
+                    </FnCountIterator>
+                  </EnclosedIterator>
+                </ElementIterator>
+                <ElementIterator>
+                  <SingletonIterator value="xs:QName(,,author)"/>
+                  <EnclosedIterator attr_cont="false">
+                    <FnCountIterator>
+                      <FnDistinctValuesIterator>
+                        <FnDataIterator>
+                          <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                            <LetVarIterator varname="doc"/>
+                          </DescendantAxisIterator>
+                        </FnDataIterator>
+                      </FnDistinctValuesIterator>
+                    </FnCountIterator>
+                  </EnclosedIterator>
+                </ElementIterator>
+              </FnConcatIterator>
+            </ElementIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,conferences)"/>
+              <EnclosedIterator attr_cont="false">
+                <FLWORIterator>
+                  <ForVariable name="conference">
                     <FnConcatIterator>
-                      <ElementIterator>
-                        <SingletonIterator value="xs:QName(,,name)"/>
-                        <EnclosedIterator attr_cont="false">
-                          <ForVarIterator varname="conference"/>
-                        </EnclosedIterator>
-                      </ElementIterator>
-                      <ElementIterator>
-                        <SingletonIterator value="xs:QName(,,paper)"/>
-                        <EnclosedIterator attr_cont="false">
-                          <FnCountIterator>
-                            <FLWORIterator>
-                              <ForVariable name="$$context-item">
-                                <UnhoistIterator>
-                                  <LetVarIterator varname="$$opt_temp_0"/>
-                                </UnhoistIterator>
-                              </ForVariable>
-                              <ForVariable name="$$context-item">
-                                <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,inproceedings)" typename="*" nill allowed="0">
-                                  <ForVarIterator varname="$$context-item"/>
-                                </ChildAxisIterator>
-                              </ForVariable>
-                              <WhereClause>
-                                <CompareIterator>
-                                  <FnDataIterator>
-                                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,booktitle)" typename="*" nill allowed="0">
-                                      <ForVarIterator varname="$$context-item"/>
-                                    </ChildAxisIterator>
-                                  </FnDataIterator>
-                                  <ForVarIterator varname="conference"/>
-                                </CompareIterator>
-                              </WhereClause>
-                              <ReturnClause>
-                                <SingletonIterator value="xs:boolean(true)"/>
-                              </ReturnClause>
-                            </FLWORIterator>
-                          </FnCountIterator>
-                        </EnclosedIterator>
-                      </ElementIterator>
-                      <ElementIterator>
-                        <SingletonIterator value="xs:QName(,,author)"/>
-                        <EnclosedIterator attr_cont="false">
-                          <FnCountIterator>
-                            <FnDistinctValuesIterator>
-                              <FnDataIterator>
-                                <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-                                  <FLWORIterator>
-                                    <ForVariable name="$$context-item">
-                                      <UnhoistIterator>
-                                        <LetVarIterator varname="$$opt_temp_1"/>
-                                      </UnhoistIterator>
-                                    </ForVariable>
-                                    <ForVariable name="$$context-item">
-                                      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,inproceedings)" typename="*" nill allowed="0">
+                      <SingletonIterator value="xs:string(EDBT)"/>
+                      <SingletonIterator value="xs:string(ICDT)"/>
+                      <SingletonIterator value="xs:string(ICDE)"/>
+                      <SingletonIterator value="xs:string(PODS)"/>
+                      <SingletonIterator value="xs:string(VLDB)"/>
+                      <SingletonIterator value="xs:string(SIGMOD Conference)"/>
+                    </FnConcatIterator>
+                  </ForVariable>
+                  <ReturnClause>
+                    <ElementIterator>
+                      <SingletonIterator value="xs:QName(,,conference)"/>
+                      <FnConcatIterator>
+                        <ElementIterator>
+                          <SingletonIterator value="xs:QName(,,name)"/>
+                          <EnclosedIterator attr_cont="false">
+                            <ForVarIterator varname="conference"/>
+                          </EnclosedIterator>
+                        </ElementIterator>
+                        <ElementIterator>
+                          <SingletonIterator value="xs:QName(,,paper)"/>
+                          <EnclosedIterator attr_cont="false">
+                            <FnCountIterator>
+                              <FLWORIterator>
+                                <ForVariable name="$$context-item">
+                                  <UnhoistIterator>
+                                    <LetVarIterator varname="$$opt_temp_0"/>
+                                  </UnhoistIterator>
+                                </ForVariable>
+                                <ForVariable name="$$context-item">
+                                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,inproceedings)" typename="*" nill allowed="0">
+                                    <ForVarIterator varname="$$context-item"/>
+                                  </ChildAxisIterator>
+                                </ForVariable>
+                                <WhereClause>
+                                  <CompareIterator>
+                                    <FnDataIterator>
+                                      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,booktitle)" typename="*" nill allowed="0">
                                         <ForVarIterator varname="$$context-item"/>
                                       </ChildAxisIterator>
-                                    </ForVariable>
-                                    <WhereClause>
-                                      <CompareIterator>
-                                        <FnDataIterator>
-                                          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,booktitle)" typename="*" nill allowed="0">
-                                            <ForVarIterator varname="$$context-item"/>
-                                          </ChildAxisIterator>
-                                        </FnDataIterator>
-                                        <ForVarIterator varname="conference"/>
-                                      </CompareIterator>
-                                    </WhereClause>
-                                    <ReturnClause>
-                                      <ForVarIterator varname="$$context-item"/>
-                                    </ReturnClause>
-                                  </FLWORIterator>
-                                </ChildAxisIterator>
-                              </FnDataIterator>
-                            </FnDistinctValuesIterator>
-                          </FnCountIterator>
-                        </EnclosedIterator>
-                      </ElementIterator>
-                    </FnConcatIterator>
-                  </ElementIterator>
-                </ReturnClause>
-              </FLWORIterator>
-            </EnclosedIterator>
-          </ElementIterator>
-        </FnConcatIterator>
-      </ElementIterator>
-    </ReturnClause>
-  </FLWORIterator>
-</SequentialIterator>
-
+                                    </FnDataIterator>
+                                    <ForVarIterator varname="conference"/>
+                                  </CompareIterator>
+                                </WhereClause>
+                                <ReturnClause>
+                                  <SingletonIterator value="xs:boolean(true)"/>
+                                </ReturnClause>
+                              </FLWORIterator>
+                            </FnCountIterator>
+                          </EnclosedIterator>
+                        </ElementIterator>
+                        <ElementIterator>
+                          <SingletonIterator value="xs:QName(,,author)"/>
+                          <EnclosedIterator attr_cont="false">
+                            <FnCountIterator>
+                              <FnDistinctValuesIterator>
+                                <FnDataIterator>
+                                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                                    <FLWORIterator>
+                                      <ForVariable name="$$context-item">
+                                        <UnhoistIterator>
+                                          <LetVarIterator varname="$$opt_temp_1"/>
+                                        </UnhoistIterator>
+                                      </ForVariable>
+                                      <ForVariable name="$$context-item">
+                                        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,inproceedings)" typename="*" nill allowed="0">
+                                          <ForVarIterator varname="$$context-item"/>
+                                        </ChildAxisIterator>
+                                      </ForVariable>
+                                      <WhereClause>
+                                        <CompareIterator>
+                                          <FnDataIterator>
+                                            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,booktitle)" typename="*" nill allowed="0">
+                                              <ForVarIterator varname="$$context-item"/>
+                                            </ChildAxisIterator>
+                                          </FnDataIterator>
+                                          <ForVarIterator varname="conference"/>
+                                        </CompareIterator>
+                                      </WhereClause>
+                                      <ReturnClause>
+                                        <ForVarIterator varname="$$context-item"/>
+                                      </ReturnClause>
+                                    </FLWORIterator>
+                                  </ChildAxisIterator>
+                                </FnDataIterator>
+                              </FnDistinctValuesIterator>
+                            </FnCountIterator>
+                          </EnclosedIterator>
+                        </ElementIterator>
+                      </FnConcatIterator>
+                    </ElementIterator>
+                  </ReturnClause>
+                </FLWORIterator>
+              </EnclosedIterator>
+            </ElementIterator>
+          </FnConcatIterator>
+        </ElementIterator>
+      </ReturnClause>
+    </FLWORIterator>
+  </SequentialIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/error/trace1.iter'
--- test/iterplans/zorba/error/trace1.iter	2013-02-07 17:24:36 +0000
+++ test/iterplans/zorba/error/trace1.iter	2014-02-20 05:31:00 +0000
@@ -1,8 +1,8 @@
-Iterator tree for main query:
-<FunctionTraceIterator>
-  <TraceIterator>
-    <SingletonIterator value="xs:integer(3)"/>
-    <SingletonIterator value="xs:string(foo)"/>
-  </TraceIterator>
-</FunctionTraceIterator>
-
+<iterator-tree description="main query">
+  <FunctionTraceIterator>
+    <TraceIterator>
+      <SingletonIterator value="xs:integer(3)"/>
+      <SingletonIterator value="xs:string(foo)"/>
+    </TraceIterator>
+  </FunctionTraceIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/flwor/flwor24.iter'
--- test/iterplans/zorba/flwor/flwor24.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/flwor/flwor24.iter	2014-02-20 05:31:00 +0000
@@ -1,56 +1,56 @@
-Iterator tree for const-folded expr:
-<FunctionTraceIterator>
-  <FnConcatIterator/>
-</FunctionTraceIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="xmlcontents">
-    <UDFunctionCallIterator function="fetch:content">
-      <SingletonIterator value="xs:string($RBKT_SRC_DIR/Queries/zorba/flwor/flwor24.xml)"/>
-    </UDFunctionCallIterator>
-  </CtxVarDeclareIterator>
-  <FLWORIterator>
-    <ForVariable name="w">
-      <FnZorbaParseXmlFragmentIterator>
-        <PromoteIterator type="xs:string">
-          <FnDataIterator>
-            <CtxVarIterator varid="4" varname="xmlcontents" varkind="local"/>
-          </FnDataIterator>
-        </PromoteIterator>
-        <TreatIterator type="[NodeXQType elementNode nametest=[uri: http://zorba.io/modules/xml-options, local: options] content=[XQType ANY_TYPE_KIND*]]" quant="?">
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(http://zorba.io/modules/xml-options,opt,options)"/>
+<iterator-tree description="const-folded expr">
+  <FunctionTraceIterator>
+    <FnConcatIterator/>
+  </FunctionTraceIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <CtxVarDeclareIterator varid="4" varname="xmlcontents">
+      <UDFunctionCallIterator function="fetch:content">
+        <SingletonIterator value="xs:string($RBKT_SRC_DIR/Queries/zorba/flwor/flwor24.xml)"/>
+      </UDFunctionCallIterator>
+    </CtxVarDeclareIterator>
+    <FLWORIterator>
+      <ForVariable name="w">
+        <FnZorbaParseXmlFragmentIterator>
+          <PromoteIterator type="xs:string">
+            <FnDataIterator>
+              <CtxVarIterator varid="4" varname="xmlcontents" varkind="local"/>
+            </FnDataIterator>
+          </PromoteIterator>
+          <TreatIterator type="[NodeXQType elementNode nametest=[uri: http://zorba.io/modules/xml-options, local: options] content=[XQType ANY_TYPE_KIND*]]" quant="?">
             <ElementIterator>
-              <SingletonIterator value="xs:QName(http://zorba.io/modules/xml-options,opt,parse-external-parsed-entity)"/>
-              <AttributeIterator qname="xs:QName(http://zorba.io/modules/xml-options,opt,skip-root-nodes)">
-                <SingletonIterator value="xs:string(1)"/>
-              </AttributeIterator>
+              <SingletonIterator value="xs:QName(http://zorba.io/modules/xml-options,opt,options)"/>
+              <ElementIterator>
+                <SingletonIterator value="xs:QName(http://zorba.io/modules/xml-options,opt,parse-external-parsed-entity)"/>
+                <AttributeIterator qname="xs:QName(http://zorba.io/modules/xml-options,opt,skip-root-nodes)">
+                  <SingletonIterator value="xs:string(1)"/>
+                </AttributeIterator>
+              </ElementIterator>
             </ElementIterator>
-          </ElementIterator>
-        </TreatIterator>
-      </FnZorbaParseXmlFragmentIterator>
-    </ForVariable>
-    <MaterializeClause>
-      <MaterializeForVariable inputVar="w : "/>
-    </MaterializeClause>
-    <ReturnClause>
-      <SequentialIterator>
-        <ApplyIterator>
-          <FnConcatIterator/>
-        </ApplyIterator>
-        <ForVarIterator varname="w"/>
-      </SequentialIterator>
-    </ReturnClause>
-  </FLWORIterator>
-</SequentialIterator>
-
-Iterator tree for fetch:content:
-<FunctionTraceIterator>
-  <FetchContentIterator>
-    <LetVarIterator varname="uri"/>
-    <SingletonIterator value="xs:string(SOME_CONTENT)"/>
-    <SingletonIterator value="xs:string(UTF-8)"/>
-  </FetchContentIterator>
-</FunctionTraceIterator>
-
+          </TreatIterator>
+        </FnZorbaParseXmlFragmentIterator>
+      </ForVariable>
+      <MaterializeClause>
+        <MaterializeForVariable inputVar="w : "/>
+      </MaterializeClause>
+      <ReturnClause>
+        <SequentialIterator>
+          <ApplyIterator>
+            <FnConcatIterator/>
+          </ApplyIterator>
+          <ForVarIterator varname="w"/>
+        </SequentialIterator>
+      </ReturnClause>
+    </FLWORIterator>
+  </SequentialIterator>
+</iterator-tree>
+<iterator-tree description="fetch:content">
+  <FunctionTraceIterator>
+    <FetchContentIterator>
+      <LetVarIterator varname="uri"/>
+      <SingletonIterator value="xs:string(SOME_CONTENT)"/>
+      <SingletonIterator value="xs:string(UTF-8)"/>
+    </FetchContentIterator>
+  </FunctionTraceIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/flwor/flwor25.iter'
--- test/iterplans/zorba/flwor/flwor25.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/flwor/flwor25.iter	2014-02-20 05:31:00 +0000
@@ -1,56 +1,56 @@
-Iterator tree for const-folded expr:
-<FunctionTraceIterator>
-  <FnConcatIterator/>
-</FunctionTraceIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="xmlcontents">
-    <UDFunctionCallIterator function="fetch:content">
-      <SingletonIterator value="xs:string($RBKT_SRC_DIR/Queries/zorba/flwor/flwor24.xml)"/>
-    </UDFunctionCallIterator>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="5" varname="contents">
-    <FnZorbaParseXmlFragmentIterator>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <CtxVarIterator varid="4" varname="xmlcontents" varkind="local"/>
-        </FnDataIterator>
-      </PromoteIterator>
-      <TreatIterator type="[NodeXQType elementNode nametest=[uri: http://zorba.io/modules/xml-options, local: options] content=[XQType ANY_TYPE_KIND*]]" quant="?">
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(http://zorba.io/modules/xml-options,opt,options)"/>
+<iterator-tree description="const-folded expr">
+  <FunctionTraceIterator>
+    <FnConcatIterator/>
+  </FunctionTraceIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <CtxVarDeclareIterator varid="4" varname="xmlcontents">
+      <UDFunctionCallIterator function="fetch:content">
+        <SingletonIterator value="xs:string($RBKT_SRC_DIR/Queries/zorba/flwor/flwor24.xml)"/>
+      </UDFunctionCallIterator>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="5" varname="contents">
+      <FnZorbaParseXmlFragmentIterator>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <CtxVarIterator varid="4" varname="xmlcontents" varkind="local"/>
+          </FnDataIterator>
+        </PromoteIterator>
+        <TreatIterator type="[NodeXQType elementNode nametest=[uri: http://zorba.io/modules/xml-options, local: options] content=[XQType ANY_TYPE_KIND*]]" quant="?">
           <ElementIterator>
-            <SingletonIterator value="xs:QName(http://zorba.io/modules/xml-options,opt,parse-external-parsed-entity)"/>
-            <AttributeIterator qname="xs:QName(http://zorba.io/modules/xml-options,opt,skip-root-nodes)">
-              <SingletonIterator value="xs:string(1)"/>
-            </AttributeIterator>
+            <SingletonIterator value="xs:QName(http://zorba.io/modules/xml-options,opt,options)"/>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(http://zorba.io/modules/xml-options,opt,parse-external-parsed-entity)"/>
+              <AttributeIterator qname="xs:QName(http://zorba.io/modules/xml-options,opt,skip-root-nodes)">
+                <SingletonIterator value="xs:string(1)"/>
+              </AttributeIterator>
+            </ElementIterator>
           </ElementIterator>
-        </ElementIterator>
-      </TreatIterator>
-    </FnZorbaParseXmlFragmentIterator>
-  </CtxVarDeclareIterator>
-  <FLWORIterator>
-    <ForVariable name="w">
-      <CtxVarIterator varid="5" varname="contents" varkind="local"/>
-    </ForVariable>
-    <ReturnClause>
-      <SequentialIterator>
-        <ApplyIterator>
-          <FnConcatIterator/>
-        </ApplyIterator>
-        <ForVarIterator varname="w"/>
-      </SequentialIterator>
-    </ReturnClause>
-  </FLWORIterator>
-</SequentialIterator>
-
-Iterator tree for fetch:content:
-<FunctionTraceIterator>
-  <FetchContentIterator>
-    <LetVarIterator varname="uri"/>
-    <SingletonIterator value="xs:string(SOME_CONTENT)"/>
-    <SingletonIterator value="xs:string(UTF-8)"/>
-  </FetchContentIterator>
-</FunctionTraceIterator>
-
+        </TreatIterator>
+      </FnZorbaParseXmlFragmentIterator>
+    </CtxVarDeclareIterator>
+    <FLWORIterator>
+      <ForVariable name="w">
+        <CtxVarIterator varid="5" varname="contents" varkind="local"/>
+      </ForVariable>
+      <ReturnClause>
+        <SequentialIterator>
+          <ApplyIterator>
+            <FnConcatIterator/>
+          </ApplyIterator>
+          <ForVarIterator varname="w"/>
+        </SequentialIterator>
+      </ReturnClause>
+    </FLWORIterator>
+  </SequentialIterator>
+</iterator-tree>
+<iterator-tree description="fetch:content">
+  <FunctionTraceIterator>
+    <FetchContentIterator>
+      <LetVarIterator varname="uri"/>
+      <SingletonIterator value="xs:string(SOME_CONTENT)"/>
+      <SingletonIterator value="xs:string(UTF-8)"/>
+    </FetchContentIterator>
+  </FunctionTraceIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/flwor/flwor26.iter'
--- test/iterplans/zorba/flwor/flwor26.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/flwor/flwor26.iter	2014-02-20 05:31:00 +0000
@@ -1,66 +1,66 @@
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="coll">
-    <SingletonIterator value="xs:QName(http://zorba.io/modules/store/dynamic/collections/ddl,ddl,coll1)"/>
-  </CtxVarDeclareIterator>
+<iterator-tree description="main query">
   <SequentialIterator>
-    <ApplyIterator>
-      <ZorbaCreateCollectionIterator>
-        <CtxVarIterator varid="4" varname="coll" varkind="global"/>
-      </ZorbaCreateCollectionIterator>
-    </ApplyIterator>
-    <ApplyIterator>
-      <ZorbaInsertLastIterator is-dynamic="true" need-to-copy="true">
-        <CtxVarIterator varid="4" varname="coll" varkind="global"/>
-        <FnConcatIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,a)"/>
-          </ElementIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,c)"/>
-          </ElementIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,b)"/>
-          </ElementIterator>
-        </FnConcatIterator>
-      </ZorbaInsertLastIterator>
-    </ApplyIterator>
-    <FLWORIterator>
-      <ForVariable name="w">
-        <ZorbaCollectionIterator>
-          <CtxVarIterator varid="4" varname="coll" varkind="global"/>
-        </ZorbaCollectionIterator>
-      </ForVariable>
-      <ReturnClause>
-        <SequentialIterator>
-          <ApplyIterator>
-            <FunctionTraceIterator>
-              <IfThenElseIterator>
-                <TypedValueCompareIterator_INTEGER>
-                  <ForVarIterator varname="pos"/>
-                  <SingletonIterator value="xs:integer(1)"/>
-                </TypedValueCompareIterator_INTEGER>
-                <ApplyIterator>
-                  <ZorbaInsertLastIterator is-dynamic="true" need-to-copy="true">
-                    <CtxVarIterator varid="4" varname="coll" varkind="global"/>
-                    <ElementIterator>
-                      <SingletonIterator value="xs:QName(,,d)"/>
-                      <EnclosedIterator attr_cont="false">
-                        <ForVarIterator varname="pos"/>
-                      </EnclosedIterator>
-                    </ElementIterator>
-                  </ZorbaInsertLastIterator>
-                </ApplyIterator>
-                <ApplyIterator>
-                  <FnConcatIterator/>
-                </ApplyIterator>
-              </IfThenElseIterator>
-            </FunctionTraceIterator>
-          </ApplyIterator>
-          <ForVarIterator varname="w"/>
-        </SequentialIterator>
-      </ReturnClause>
-    </FLWORIterator>
+    <CtxVarDeclareIterator varid="4" varname="coll">
+      <SingletonIterator value="xs:QName(http://zorba.io/modules/store/dynamic/collections/ddl,ddl,coll1)"/>
+    </CtxVarDeclareIterator>
+    <SequentialIterator>
+      <ApplyIterator>
+        <ZorbaCreateCollectionIterator>
+          <CtxVarIterator varid="4" varname="coll" varkind="global"/>
+        </ZorbaCreateCollectionIterator>
+      </ApplyIterator>
+      <ApplyIterator>
+        <ZorbaInsertLastIterator is-dynamic="true" need-to-copy="true">
+          <CtxVarIterator varid="4" varname="coll" varkind="global"/>
+          <FnConcatIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,a)"/>
+            </ElementIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,c)"/>
+            </ElementIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,b)"/>
+            </ElementIterator>
+          </FnConcatIterator>
+        </ZorbaInsertLastIterator>
+      </ApplyIterator>
+      <FLWORIterator>
+        <ForVariable name="w">
+          <ZorbaCollectionIterator>
+            <CtxVarIterator varid="4" varname="coll" varkind="global"/>
+          </ZorbaCollectionIterator>
+        </ForVariable>
+        <ReturnClause>
+          <SequentialIterator>
+            <ApplyIterator>
+              <FunctionTraceIterator>
+                <IfThenElseIterator>
+                  <TypedValueCompareIterator_INTEGER>
+                    <ForVarIterator varname="pos"/>
+                    <SingletonIterator value="xs:integer(1)"/>
+                  </TypedValueCompareIterator_INTEGER>
+                  <ApplyIterator>
+                    <ZorbaInsertLastIterator is-dynamic="true" need-to-copy="true">
+                      <CtxVarIterator varid="4" varname="coll" varkind="global"/>
+                      <ElementIterator>
+                        <SingletonIterator value="xs:QName(,,d)"/>
+                        <EnclosedIterator attr_cont="false">
+                          <ForVarIterator varname="pos"/>
+                        </EnclosedIterator>
+                      </ElementIterator>
+                    </ZorbaInsertLastIterator>
+                  </ApplyIterator>
+                  <ApplyIterator>
+                    <FnConcatIterator/>
+                  </ApplyIterator>
+                </IfThenElseIterator>
+              </FunctionTraceIterator>
+            </ApplyIterator>
+            <ForVarIterator varname="w"/>
+          </SequentialIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </SequentialIterator>
   </SequentialIterator>
-</SequentialIterator>
-
+</iterator-tree>

=== modified file 'test/iterplans/zorba/flwor/flwor27.iter'
--- test/iterplans/zorba/flwor/flwor27.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/flwor/flwor27.iter	2014-02-20 05:31:00 +0000
@@ -1,63 +1,63 @@
-Iterator tree for const-folded expr:
-<FunctionTraceIterator>
-  <FnConcatIterator/>
-</FunctionTraceIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="xmlcontents">
-    <UDFunctionCallIterator function="fetch:content">
-      <SingletonIterator value="xs:string($RBKT_SRC_DIR/Queries/zorba/flwor/flwor24.xml)"/>
-    </UDFunctionCallIterator>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="5" varname="contents">
-    <FnZorbaParseXmlFragmentIterator>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <CtxVarIterator varid="4" varname="xmlcontents" varkind="local"/>
-        </FnDataIterator>
-      </PromoteIterator>
-      <TreatIterator type="[NodeXQType elementNode nametest=[uri: http://zorba.io/modules/xml-options, local: options] content=[XQType ANY_TYPE_KIND*]]" quant="?">
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(http://zorba.io/modules/xml-options,opt,options)"/>
+<iterator-tree description="const-folded expr">
+  <FunctionTraceIterator>
+    <FnConcatIterator/>
+  </FunctionTraceIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <CtxVarDeclareIterator varid="4" varname="xmlcontents">
+      <UDFunctionCallIterator function="fetch:content">
+        <SingletonIterator value="xs:string($RBKT_SRC_DIR/Queries/zorba/flwor/flwor24.xml)"/>
+      </UDFunctionCallIterator>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="5" varname="contents">
+      <FnZorbaParseXmlFragmentIterator>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <CtxVarIterator varid="4" varname="xmlcontents" varkind="local"/>
+          </FnDataIterator>
+        </PromoteIterator>
+        <TreatIterator type="[NodeXQType elementNode nametest=[uri: http://zorba.io/modules/xml-options, local: options] content=[XQType ANY_TYPE_KIND*]]" quant="?">
           <ElementIterator>
-            <SingletonIterator value="xs:QName(http://zorba.io/modules/xml-options,opt,parse-external-parsed-entity)"/>
-            <AttributeIterator qname="xs:QName(http://zorba.io/modules/xml-options,opt,skip-root-nodes)">
-              <SingletonIterator value="xs:string(1)"/>
-            </AttributeIterator>
+            <SingletonIterator value="xs:QName(http://zorba.io/modules/xml-options,opt,options)"/>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(http://zorba.io/modules/xml-options,opt,parse-external-parsed-entity)"/>
+              <AttributeIterator qname="xs:QName(http://zorba.io/modules/xml-options,opt,skip-root-nodes)">
+                <SingletonIterator value="xs:string(1)"/>
+              </AttributeIterator>
+            </ElementIterator>
           </ElementIterator>
-        </ElementIterator>
-      </TreatIterator>
-    </FnZorbaParseXmlFragmentIterator>
-  </CtxVarDeclareIterator>
-  <FLWORIterator>
-    <ForVariable name="w">
-      <CtxVarIterator varid="5" varname="contents" varkind="local"/>
-    </ForVariable>
-    <OrderBySpec>
-      <FnLocalNameIterator>
-        <TreatIterator type="[NodeXQType anyNode content=[XQType ANY_TYPE_KIND*]]" quant="?">
+        </TreatIterator>
+      </FnZorbaParseXmlFragmentIterator>
+    </CtxVarDeclareIterator>
+    <FLWORIterator>
+      <ForVariable name="w">
+        <CtxVarIterator varid="5" varname="contents" varkind="local"/>
+      </ForVariable>
+      <OrderBySpec>
+        <FnLocalNameIterator>
+          <TreatIterator type="[NodeXQType anyNode content=[XQType ANY_TYPE_KIND*]]" quant="?">
+            <ForVarIterator varname="w"/>
+          </TreatIterator>
+        </FnLocalNameIterator>
+      </OrderBySpec>
+      <ReturnClause>
+        <SequentialIterator>
+          <ApplyIterator>
+            <FnConcatIterator/>
+          </ApplyIterator>
           <ForVarIterator varname="w"/>
-        </TreatIterator>
-      </FnLocalNameIterator>
-    </OrderBySpec>
-    <ReturnClause>
-      <SequentialIterator>
-        <ApplyIterator>
-          <FnConcatIterator/>
-        </ApplyIterator>
-        <ForVarIterator varname="w"/>
-      </SequentialIterator>
-    </ReturnClause>
-  </FLWORIterator>
-</SequentialIterator>
-
-Iterator tree for fetch:content:
-<FunctionTraceIterator>
-  <FetchContentIterator>
-    <LetVarIterator varname="uri"/>
-    <SingletonIterator value="xs:string(SOME_CONTENT)"/>
-    <SingletonIterator value="xs:string(UTF-8)"/>
-  </FetchContentIterator>
-</FunctionTraceIterator>
-
+        </SequentialIterator>
+      </ReturnClause>
+    </FLWORIterator>
+  </SequentialIterator>
+</iterator-tree>
+<iterator-tree description="fetch:content">
+  <FunctionTraceIterator>
+    <FetchContentIterator>
+      <LetVarIterator varname="uri"/>
+      <SingletonIterator value="xs:string(SOME_CONTENT)"/>
+      <SingletonIterator value="xs:string(UTF-8)"/>
+    </FetchContentIterator>
+  </FunctionTraceIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/flwor/flwor28.iter'
--- test/iterplans/zorba/flwor/flwor28.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/flwor/flwor28.iter	2014-02-20 05:31:00 +0000
@@ -1,57 +1,57 @@
-Iterator tree for const-folded expr:
-<FunctionTraceIterator>
-  <FnConcatIterator/>
-</FunctionTraceIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="coll">
-    <SingletonIterator value="xs:QName(http://zorba.io/modules/store/dynamic/collections/ddl,ddl,coll1)"/>
-  </CtxVarDeclareIterator>
+<iterator-tree description="const-folded expr">
+  <FunctionTraceIterator>
+    <FnConcatIterator/>
+  </FunctionTraceIterator>
+</iterator-tree>
+<iterator-tree description="main query">
   <SequentialIterator>
-    <ApplyIterator>
-      <ZorbaCreateCollectionIterator>
-        <CtxVarIterator varid="4" varname="coll" varkind="global"/>
-      </ZorbaCreateCollectionIterator>
-    </ApplyIterator>
-    <ApplyIterator>
-      <ZorbaInsertLastIterator is-dynamic="true" need-to-copy="true">
-        <CtxVarIterator varid="4" varname="coll" varkind="global"/>
-        <FnConcatIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,a)"/>
-          </ElementIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,c)"/>
-          </ElementIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,b)"/>
-          </ElementIterator>
-        </FnConcatIterator>
-      </ZorbaInsertLastIterator>
-    </ApplyIterator>
-    <FLWORIterator>
-      <ForVariable name="w">
-        <ZorbaCollectionIterator>
-          <CtxVarIterator varid="4" varname="coll" varkind="global"/>
-        </ZorbaCollectionIterator>
-      </ForVariable>
-      <OrderBySpec>
-        <FnLocalNameIterator>
-          <TreatIterator type="[NodeXQType anyNode content=[XQType ANY_TYPE_KIND*]]" quant="?">
+    <CtxVarDeclareIterator varid="4" varname="coll">
+      <SingletonIterator value="xs:QName(http://zorba.io/modules/store/dynamic/collections/ddl,ddl,coll1)"/>
+    </CtxVarDeclareIterator>
+    <SequentialIterator>
+      <ApplyIterator>
+        <ZorbaCreateCollectionIterator>
+          <CtxVarIterator varid="4" varname="coll" varkind="global"/>
+        </ZorbaCreateCollectionIterator>
+      </ApplyIterator>
+      <ApplyIterator>
+        <ZorbaInsertLastIterator is-dynamic="true" need-to-copy="true">
+          <CtxVarIterator varid="4" varname="coll" varkind="global"/>
+          <FnConcatIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,a)"/>
+            </ElementIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,c)"/>
+            </ElementIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,b)"/>
+            </ElementIterator>
+          </FnConcatIterator>
+        </ZorbaInsertLastIterator>
+      </ApplyIterator>
+      <FLWORIterator>
+        <ForVariable name="w">
+          <ZorbaCollectionIterator>
+            <CtxVarIterator varid="4" varname="coll" varkind="global"/>
+          </ZorbaCollectionIterator>
+        </ForVariable>
+        <OrderBySpec>
+          <FnLocalNameIterator>
+            <TreatIterator type="[NodeXQType anyNode content=[XQType ANY_TYPE_KIND*]]" quant="?">
+              <ForVarIterator varname="w"/>
+            </TreatIterator>
+          </FnLocalNameIterator>
+        </OrderBySpec>
+        <ReturnClause>
+          <SequentialIterator>
+            <ApplyIterator>
+              <FnConcatIterator/>
+            </ApplyIterator>
             <ForVarIterator varname="w"/>
-          </TreatIterator>
-        </FnLocalNameIterator>
-      </OrderBySpec>
-      <ReturnClause>
-        <SequentialIterator>
-          <ApplyIterator>
-            <FnConcatIterator/>
-          </ApplyIterator>
-          <ForVarIterator varname="w"/>
-        </SequentialIterator>
-      </ReturnClause>
-    </FLWORIterator>
+          </SequentialIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </SequentialIterator>
   </SequentialIterator>
-</SequentialIterator>
-
+</iterator-tree>

=== modified file 'test/iterplans/zorba/flwor/flwor_op00.iter'
--- test/iterplans/zorba/flwor/flwor_op00.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/flwor/flwor_op00.iter	2014-02-20 05:31:00 +0000
@@ -1,27 +1,27 @@
-Iterator tree for main query:
-<FLWORIterator>
-  <ForVariable name="x">
-    <FnConcatIterator>
-      <SingletonIterator value="xs:integer(1)"/>
-      <SingletonIterator value="xs:integer(2)"/>
-      <SingletonIterator value="xs:integer(3)"/>
-      <SingletonIterator value="xs:integer(4)"/>
-      <SingletonIterator value="xs:integer(5)"/>
-      <SingletonIterator value="xs:integer(6)"/>
-      <SingletonIterator value="xs:integer(7)"/>
-      <SingletonIterator value="xs:integer(8)"/>
-      <SingletonIterator value="xs:integer(9)"/>
-      <SingletonIterator value="xs:integer(10)"/>
-    </FnConcatIterator>
-  </ForVariable>
-  <WhereClause>
-    <TypedValueCompareIterator_INTEGER>
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <ForVariable name="x">
+      <FnConcatIterator>
+        <SingletonIterator value="xs:integer(1)"/>
+        <SingletonIterator value="xs:integer(2)"/>
+        <SingletonIterator value="xs:integer(3)"/>
+        <SingletonIterator value="xs:integer(4)"/>
+        <SingletonIterator value="xs:integer(5)"/>
+        <SingletonIterator value="xs:integer(6)"/>
+        <SingletonIterator value="xs:integer(7)"/>
+        <SingletonIterator value="xs:integer(8)"/>
+        <SingletonIterator value="xs:integer(9)"/>
+        <SingletonIterator value="xs:integer(10)"/>
+      </FnConcatIterator>
+    </ForVariable>
+    <WhereClause>
+      <TypedValueCompareIterator_INTEGER>
+        <ForVarIterator varname="x"/>
+        <SingletonIterator value="xs:integer(2)"/>
+      </TypedValueCompareIterator_INTEGER>
+    </WhereClause>
+    <ReturnClause>
       <ForVarIterator varname="x"/>
-      <SingletonIterator value="xs:integer(2)"/>
-    </TypedValueCompareIterator_INTEGER>
-  </WhereClause>
-  <ReturnClause>
-    <ForVarIterator varname="x"/>
-  </ReturnClause>
-</FLWORIterator>
-
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/flwor/flwor_op01.iter'
--- test/iterplans/zorba/flwor/flwor_op01.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/flwor/flwor_op01.iter	2014-02-20 05:31:00 +0000
@@ -1,33 +1,33 @@
-Iterator tree for main query:
-<FLWORIterator>
-  <ForVariable name="x">
-    <FnConcatIterator>
-      <SingletonIterator value="xs:integer(1)"/>
-      <SingletonIterator value="xs:integer(2)"/>
-      <SingletonIterator value="xs:integer(3)"/>
-      <SingletonIterator value="xs:integer(4)"/>
-      <SingletonIterator value="xs:integer(5)"/>
-      <SingletonIterator value="xs:integer(6)"/>
-      <SingletonIterator value="xs:integer(7)"/>
-      <SingletonIterator value="xs:integer(8)"/>
-      <SingletonIterator value="xs:integer(9)"/>
-      <SingletonIterator value="xs:integer(10)"/>
-    </FnConcatIterator>
-  </ForVariable>
-  <WhereClause>
-    <AndIterator>
-      <TypedValueCompareIterator_INTEGER>
-        <ForVarIterator varname="x"/>
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <ForVariable name="x">
+      <FnConcatIterator>
+        <SingletonIterator value="xs:integer(1)"/>
+        <SingletonIterator value="xs:integer(2)"/>
+        <SingletonIterator value="xs:integer(3)"/>
+        <SingletonIterator value="xs:integer(4)"/>
+        <SingletonIterator value="xs:integer(5)"/>
+        <SingletonIterator value="xs:integer(6)"/>
+        <SingletonIterator value="xs:integer(7)"/>
         <SingletonIterator value="xs:integer(8)"/>
-      </TypedValueCompareIterator_INTEGER>
-      <TypedValueCompareIterator_INTEGER>
-        <ForVarIterator varname="x"/>
-        <SingletonIterator value="xs:integer(2)"/>
-      </TypedValueCompareIterator_INTEGER>
-    </AndIterator>
-  </WhereClause>
-  <ReturnClause>
-    <ForVarIterator varname="x"/>
-  </ReturnClause>
-</FLWORIterator>
-
+        <SingletonIterator value="xs:integer(9)"/>
+        <SingletonIterator value="xs:integer(10)"/>
+      </FnConcatIterator>
+    </ForVariable>
+    <WhereClause>
+      <AndIterator>
+        <TypedValueCompareIterator_INTEGER>
+          <ForVarIterator varname="x"/>
+          <SingletonIterator value="xs:integer(8)"/>
+        </TypedValueCompareIterator_INTEGER>
+        <TypedValueCompareIterator_INTEGER>
+          <ForVarIterator varname="x"/>
+          <SingletonIterator value="xs:integer(2)"/>
+        </TypedValueCompareIterator_INTEGER>
+      </AndIterator>
+    </WhereClause>
+    <ReturnClause>
+      <ForVarIterator varname="x"/>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/flwor/flwor_op02.iter'
--- test/iterplans/zorba/flwor/flwor_op02.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/flwor/flwor_op02.iter	2014-02-20 05:31:00 +0000
@@ -1,40 +1,40 @@
-Iterator tree for main query:
-<FLWORIterator>
-  <ForVariable name="x">
-    <FnConcatIterator>
-      <SingletonIterator value="xs:integer(1)"/>
-      <SingletonIterator value="xs:integer(2)"/>
-      <SingletonIterator value="xs:integer(3)"/>
-      <SingletonIterator value="xs:integer(4)"/>
-      <SingletonIterator value="xs:integer(5)"/>
-      <SingletonIterator value="xs:integer(6)"/>
-      <SingletonIterator value="xs:integer(7)"/>
-      <SingletonIterator value="xs:integer(8)"/>
-      <SingletonIterator value="xs:integer(9)"/>
-      <SingletonIterator value="xs:integer(10)"/>
-    </FnConcatIterator>
-  </ForVariable>
-  <WhereClause>
-    <AndIterator>
-      <TypedValueCompareIterator_INTEGER>
-        <ForVarIterator varname="x"/>
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <ForVariable name="x">
+      <FnConcatIterator>
+        <SingletonIterator value="xs:integer(1)"/>
+        <SingletonIterator value="xs:integer(2)"/>
+        <SingletonIterator value="xs:integer(3)"/>
+        <SingletonIterator value="xs:integer(4)"/>
+        <SingletonIterator value="xs:integer(5)"/>
+        <SingletonIterator value="xs:integer(6)"/>
+        <SingletonIterator value="xs:integer(7)"/>
         <SingletonIterator value="xs:integer(8)"/>
-      </TypedValueCompareIterator_INTEGER>
-      <TypedValueCompareIterator_INTEGER>
-        <ForVarIterator varname="x"/>
-        <SingletonIterator value="xs:integer(2)"/>
-      </TypedValueCompareIterator_INTEGER>
-      <TypedValueCompareIterator_INTEGER>
-        <NumArithIterator_ModOperation>
+        <SingletonIterator value="xs:integer(9)"/>
+        <SingletonIterator value="xs:integer(10)"/>
+      </FnConcatIterator>
+    </ForVariable>
+    <WhereClause>
+      <AndIterator>
+        <TypedValueCompareIterator_INTEGER>
+          <ForVarIterator varname="x"/>
+          <SingletonIterator value="xs:integer(8)"/>
+        </TypedValueCompareIterator_INTEGER>
+        <TypedValueCompareIterator_INTEGER>
           <ForVarIterator varname="x"/>
           <SingletonIterator value="xs:integer(2)"/>
-        </NumArithIterator_ModOperation>
-        <SingletonIterator value="xs:integer(0)"/>
-      </TypedValueCompareIterator_INTEGER>
-    </AndIterator>
-  </WhereClause>
-  <ReturnClause>
-    <ForVarIterator varname="x"/>
-  </ReturnClause>
-</FLWORIterator>
-
+        </TypedValueCompareIterator_INTEGER>
+        <TypedValueCompareIterator_INTEGER>
+          <NumArithIterator_ModOperation>
+            <ForVarIterator varname="x"/>
+            <SingletonIterator value="xs:integer(2)"/>
+          </NumArithIterator_ModOperation>
+          <SingletonIterator value="xs:integer(0)"/>
+        </TypedValueCompareIterator_INTEGER>
+      </AndIterator>
+    </WhereClause>
+    <ReturnClause>
+      <ForVarIterator varname="x"/>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9065.iter'
--- test/iterplans/zorba/hashjoins/9065.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9065.iter	2014-02-20 05:31:00 +0000
@@ -1,62 +1,62 @@
-Iterator tree for main query:
-<FLWORIterator>
-  <ForVariable name="b">
-    <FnDocIterator>
-      <SingletonIterator value="xs:string(books.xml)"/>
-    </FnDocIterator>
-  </ForVariable>
-  <LetVariable name="$$opt_temp_1" materialize="true">
-    <HoistIterator>
-      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,title)" typename="*" nill allowed="0">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,bib)" typename="*" nill allowed="0">
-            <ForVarIterator varname="b"/>
-          </ChildAxisIterator>
-        </ChildAxisIterator>
-      </ChildAxisIterator>
-    </HoistIterator>
-  </LetVariable>
-  <ForVariable name="$$opt_temp_0">
-    <HoistIterator>
-      <FnCountIterator>
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <ForVariable name="b">
+      <FnDocIterator>
+        <SingletonIterator value="xs:string(books.xml)"/>
+      </FnDocIterator>
+    </ForVariable>
+    <LetVariable name="$$opt_temp_1" materialize="true">
+      <HoistIterator>
+        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,title)" typename="*" nill allowed="0">
           <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
             <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,bib)" typename="*" nill allowed="0">
               <ForVarIterator varname="b"/>
             </ChildAxisIterator>
           </ChildAxisIterator>
         </ChildAxisIterator>
-      </FnCountIterator>
-    </HoistIterator>
-  </ForVariable>
-  <ForVariable name="er">
-    <OpToIterator>
-      <SingletonIterator value="xs:integer(1)"/>
-      <SingletonIterator value="xs:integer(3)"/>
-    </OpToIterator>
-  </ForVariable>
-  <WhereClause>
-    <TypedValueCompareIterator_INTEGER>
-      <UnhoistIterator>
-        <ForVarIterator varname="$$opt_temp_0"/>
-      </UnhoistIterator>
-      <ForVarIterator varname="er"/>
-    </TypedValueCompareIterator_INTEGER>
-  </WhereClause>
-  <ReturnClause>
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,gruppe)"/>
-      <AttributeIterator qname="xs:QName(,,anzahl)">
-        <EnclosedIterator attr_cont="true">
-          <ForVarIterator varname="er"/>
-        </EnclosedIterator>
-      </AttributeIterator>
-      <EnclosedIterator attr_cont="false">
+      </HoistIterator>
+    </LetVariable>
+    <ForVariable name="$$opt_temp_0">
+      <HoistIterator>
+        <FnCountIterator>
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,bib)" typename="*" nill allowed="0">
+                <ForVarIterator varname="b"/>
+              </ChildAxisIterator>
+            </ChildAxisIterator>
+          </ChildAxisIterator>
+        </FnCountIterator>
+      </HoistIterator>
+    </ForVariable>
+    <ForVariable name="er">
+      <OpToIterator>
+        <SingletonIterator value="xs:integer(1)"/>
+        <SingletonIterator value="xs:integer(3)"/>
+      </OpToIterator>
+    </ForVariable>
+    <WhereClause>
+      <TypedValueCompareIterator_INTEGER>
         <UnhoistIterator>
-          <LetVarIterator varname="$$opt_temp_1"/>
+          <ForVarIterator varname="$$opt_temp_0"/>
         </UnhoistIterator>
-      </EnclosedIterator>
-    </ElementIterator>
-  </ReturnClause>
-</FLWORIterator>
-
+        <ForVarIterator varname="er"/>
+      </TypedValueCompareIterator_INTEGER>
+    </WhereClause>
+    <ReturnClause>
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,gruppe)"/>
+        <AttributeIterator qname="xs:QName(,,anzahl)">
+          <EnclosedIterator attr_cont="true">
+            <ForVarIterator varname="er"/>
+          </EnclosedIterator>
+        </AttributeIterator>
+        <EnclosedIterator attr_cont="false">
+          <UnhoistIterator>
+            <LetVarIterator varname="$$opt_temp_1"/>
+          </UnhoistIterator>
+        </EnclosedIterator>
+      </ElementIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9066.iter'
--- test/iterplans/zorba/hashjoins/9066.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9066.iter	2014-02-20 05:31:00 +0000
@@ -1,46 +1,46 @@
-Iterator tree for main query:
-<FLWORIterator>
-  <ForVariable name="b">
-    <FnDocIterator>
-      <SingletonIterator value="xs:string(books.xml)"/>
-    </FnDocIterator>
-  </ForVariable>
-  <ForVariable name="$$opt_temp_0">
-    <HoistIterator>
-      <FnCountIterator>
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,bib)" typename="*" nill allowed="0">
-              <ForVarIterator varname="b"/>
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <ForVariable name="b">
+      <FnDocIterator>
+        <SingletonIterator value="xs:string(books.xml)"/>
+      </FnDocIterator>
+    </ForVariable>
+    <ForVariable name="$$opt_temp_0">
+      <HoistIterator>
+        <FnCountIterator>
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,bib)" typename="*" nill allowed="0">
+                <ForVarIterator varname="b"/>
+              </ChildAxisIterator>
             </ChildAxisIterator>
           </ChildAxisIterator>
-        </ChildAxisIterator>
-      </FnCountIterator>
-    </HoistIterator>
-  </ForVariable>
-  <ForVariable name="er">
-    <OpToIterator>
-      <SingletonIterator value="xs:integer(1)"/>
-      <SingletonIterator value="xs:integer(3)"/>
-    </OpToIterator>
-  </ForVariable>
-  <WhereClause>
-    <TypedValueCompareIterator_INTEGER>
-      <UnhoistIterator>
-        <ForVarIterator varname="$$opt_temp_0"/>
-      </UnhoistIterator>
-      <ForVarIterator varname="er"/>
-    </TypedValueCompareIterator_INTEGER>
-  </WhereClause>
-  <ReturnClause>
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,gruppe)"/>
-      <AttributeIterator qname="xs:QName(,,anzahl)">
-        <EnclosedIterator attr_cont="true">
-          <ForVarIterator varname="er"/>
-        </EnclosedIterator>
-      </AttributeIterator>
-    </ElementIterator>
-  </ReturnClause>
-</FLWORIterator>
-
+        </FnCountIterator>
+      </HoistIterator>
+    </ForVariable>
+    <ForVariable name="er">
+      <OpToIterator>
+        <SingletonIterator value="xs:integer(1)"/>
+        <SingletonIterator value="xs:integer(3)"/>
+      </OpToIterator>
+    </ForVariable>
+    <WhereClause>
+      <TypedValueCompareIterator_INTEGER>
+        <UnhoistIterator>
+          <ForVarIterator varname="$$opt_temp_0"/>
+        </UnhoistIterator>
+        <ForVarIterator varname="er"/>
+      </TypedValueCompareIterator_INTEGER>
+    </WhereClause>
+    <ReturnClause>
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,gruppe)"/>
+        <AttributeIterator qname="xs:QName(,,anzahl)">
+          <EnclosedIterator attr_cont="true">
+            <ForVarIterator varname="er"/>
+          </EnclosedIterator>
+        </AttributeIterator>
+      </ElementIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9067.iter'
--- test/iterplans/zorba/hashjoins/9067.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9067.iter	2014-02-20 05:31:00 +0000
@@ -1,63 +1,63 @@
-Iterator tree for main query:
-<FLWORIterator>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
-      <OpToIterator>
-        <SingletonIterator value="xs:integer(1)"/>
-        <SingletonIterator value="xs:integer(3)"/>
-      </OpToIterator>
-    </HoistIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_4" materialize="true">
-    <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-      <FLWORIterator>
-        <ForVariable name="$$opt_temp_2">
-          <UnhoistIterator>
-            <LetVarIterator varname="$$opt_temp_0"/>
-          </UnhoistIterator>
-        </ForVariable>
-        <ReturnClause>
-          <ValueIndexEntryBuilderIterator>
-            <ForVarIterator varname="$$opt_temp_2"/>
-            <ForVarIterator varname="$$opt_temp_2"/>
-          </ValueIndexEntryBuilderIterator>
-        </ReturnClause>
-      </FLWORIterator>
-    </CreateInternalIndexIterator>
-  </LetVariable>
-  <ForVariable name="b">
-    <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-      <FnDocIterator>
-        <SingletonIterator value="xs:string(books.xml)"/>
-      </FnDocIterator>
-    </DescendantAxisIterator>
-  </ForVariable>
-  <ForVariable name="$$opt_temp_1">
-    <HoistIterator>
-      <FnCountIterator>
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-          <ForVarIterator varname="b"/>
-        </ChildAxisIterator>
-      </FnCountIterator>
-    </HoistIterator>
-  </ForVariable>
-  <ForVariable name="er">
-    <ProbeIndexPointValueIterator>
-      <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-      <UnhoistIterator>
-        <ForVarIterator varname="$$opt_temp_1"/>
-      </UnhoistIterator>
-    </ProbeIndexPointValueIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,gruppe)"/>
-      <AttributeIterator qname="xs:QName(,,anzahl)">
-        <EnclosedIterator attr_cont="true">
-          <ForVarIterator varname="er"/>
-        </EnclosedIterator>
-      </AttributeIterator>
-    </ElementIterator>
-  </ReturnClause>
-</FLWORIterator>
-
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <LetVariable name="$$opt_temp_0" materialize="true">
+      <HoistIterator>
+        <OpToIterator>
+          <SingletonIterator value="xs:integer(1)"/>
+          <SingletonIterator value="xs:integer(3)"/>
+        </OpToIterator>
+      </HoistIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_4" materialize="true">
+      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+        <FLWORIterator>
+          <ForVariable name="$$opt_temp_2">
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_0"/>
+            </UnhoistIterator>
+          </ForVariable>
+          <ReturnClause>
+            <ValueIndexEntryBuilderIterator>
+              <ForVarIterator varname="$$opt_temp_2"/>
+              <ForVarIterator varname="$$opt_temp_2"/>
+            </ValueIndexEntryBuilderIterator>
+          </ReturnClause>
+        </FLWORIterator>
+      </CreateInternalIndexIterator>
+    </LetVariable>
+    <ForVariable name="b">
+      <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+        <FnDocIterator>
+          <SingletonIterator value="xs:string(books.xml)"/>
+        </FnDocIterator>
+      </DescendantAxisIterator>
+    </ForVariable>
+    <ForVariable name="$$opt_temp_1">
+      <HoistIterator>
+        <FnCountIterator>
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+            <ForVarIterator varname="b"/>
+          </ChildAxisIterator>
+        </FnCountIterator>
+      </HoistIterator>
+    </ForVariable>
+    <ForVariable name="er">
+      <ProbeIndexPointValueIterator>
+        <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+        <UnhoistIterator>
+          <ForVarIterator varname="$$opt_temp_1"/>
+        </UnhoistIterator>
+      </ProbeIndexPointValueIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,gruppe)"/>
+        <AttributeIterator qname="xs:QName(,,anzahl)">
+          <EnclosedIterator attr_cont="true">
+            <ForVarIterator varname="er"/>
+          </EnclosedIterator>
+        </AttributeIterator>
+      </ElementIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9068.iter'
--- test/iterplans/zorba/hashjoins/9068.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9068.iter	2014-02-20 05:31:00 +0000
@@ -1,75 +1,75 @@
-Iterator tree for main query:
-<FLWORIterator>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
-      <OpToIterator>
-        <SingletonIterator value="xs:integer(1)"/>
-        <SingletonIterator value="xs:integer(3)"/>
-      </OpToIterator>
-    </HoistIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_5" materialize="true">
-    <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-      <FLWORIterator>
-        <ForVariable name="$$opt_temp_3">
-          <UnhoistIterator>
-            <LetVarIterator varname="$$opt_temp_0"/>
-          </UnhoistIterator>
-        </ForVariable>
-        <ReturnClause>
-          <ValueIndexEntryBuilderIterator>
-            <ForVarIterator varname="$$opt_temp_3"/>
-            <ForVarIterator varname="$$opt_temp_3"/>
-          </ValueIndexEntryBuilderIterator>
-        </ReturnClause>
-      </FLWORIterator>
-    </CreateInternalIndexIterator>
-  </LetVariable>
-  <ForVariable name="b">
-    <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-      <FnDocIterator>
-        <SingletonIterator value="xs:string(books.xml)"/>
-      </FnDocIterator>
-    </DescendantAxisIterator>
-  </ForVariable>
-  <LetVariable name="$$opt_temp_2" materialize="true">
-    <HoistIterator>
-      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,title)" typename="*" nill allowed="0">
-        <ForVarIterator varname="b"/>
-      </ChildAxisIterator>
-    </HoistIterator>
-  </LetVariable>
-  <ForVariable name="$$opt_temp_1">
-    <HoistIterator>
-      <FnCountIterator>
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <LetVariable name="$$opt_temp_0" materialize="true">
+      <HoistIterator>
+        <OpToIterator>
+          <SingletonIterator value="xs:integer(1)"/>
+          <SingletonIterator value="xs:integer(3)"/>
+        </OpToIterator>
+      </HoistIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_5" materialize="true">
+      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+        <FLWORIterator>
+          <ForVariable name="$$opt_temp_3">
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_0"/>
+            </UnhoistIterator>
+          </ForVariable>
+          <ReturnClause>
+            <ValueIndexEntryBuilderIterator>
+              <ForVarIterator varname="$$opt_temp_3"/>
+              <ForVarIterator varname="$$opt_temp_3"/>
+            </ValueIndexEntryBuilderIterator>
+          </ReturnClause>
+        </FLWORIterator>
+      </CreateInternalIndexIterator>
+    </LetVariable>
+    <ForVariable name="b">
+      <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+        <FnDocIterator>
+          <SingletonIterator value="xs:string(books.xml)"/>
+        </FnDocIterator>
+      </DescendantAxisIterator>
+    </ForVariable>
+    <LetVariable name="$$opt_temp_2" materialize="true">
+      <HoistIterator>
+        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,title)" typename="*" nill allowed="0">
           <ForVarIterator varname="b"/>
         </ChildAxisIterator>
-      </FnCountIterator>
-    </HoistIterator>
-  </ForVariable>
-  <ForVariable name="er">
-    <ProbeIndexPointValueIterator>
-      <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-      <UnhoistIterator>
-        <ForVarIterator varname="$$opt_temp_1"/>
-      </UnhoistIterator>
-    </ProbeIndexPointValueIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,gruppe)"/>
-      <AttributeIterator qname="xs:QName(,,anzahl)">
-        <EnclosedIterator attr_cont="true">
-          <ForVarIterator varname="er"/>
-        </EnclosedIterator>
-      </AttributeIterator>
-      <EnclosedIterator attr_cont="false">
+      </HoistIterator>
+    </LetVariable>
+    <ForVariable name="$$opt_temp_1">
+      <HoistIterator>
+        <FnCountIterator>
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+            <ForVarIterator varname="b"/>
+          </ChildAxisIterator>
+        </FnCountIterator>
+      </HoistIterator>
+    </ForVariable>
+    <ForVariable name="er">
+      <ProbeIndexPointValueIterator>
+        <SingletonIterator value="xs:QName(,,tempIndex0)"/>
         <UnhoistIterator>
-          <LetVarIterator varname="$$opt_temp_2"/>
+          <ForVarIterator varname="$$opt_temp_1"/>
         </UnhoistIterator>
-      </EnclosedIterator>
-    </ElementIterator>
-  </ReturnClause>
-</FLWORIterator>
-
+      </ProbeIndexPointValueIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,gruppe)"/>
+        <AttributeIterator qname="xs:QName(,,anzahl)">
+          <EnclosedIterator attr_cont="true">
+            <ForVarIterator varname="er"/>
+          </EnclosedIterator>
+        </AttributeIterator>
+        <EnclosedIterator attr_cont="false">
+          <UnhoistIterator>
+            <LetVarIterator varname="$$opt_temp_2"/>
+          </UnhoistIterator>
+        </EnclosedIterator>
+      </ElementIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9197.iter'
--- test/iterplans/zorba/hashjoins/9197.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9197.iter	2014-02-20 05:31:00 +0000
@@ -1,68 +1,68 @@
-Iterator tree for main query:
-<ElementIterator>
-  <SingletonIterator value="xs:QName(,,karteikasten)"/>
-  <EnclosedIterator attr_cont="false">
-    <FLWORIterator>
-      <LetVariable name="$$opt_temp_0" materialize="true">
-        <HoistIterator>
-          <OpToIterator>
-            <SingletonIterator value="xs:integer(1)"/>
-            <SingletonIterator value="xs:integer(2)"/>
-          </OpToIterator>
-        </HoistIterator>
-      </LetVariable>
-      <LetVariable name="$$opt_temp_4" materialize="true">
-        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-          <FLWORIterator>
-            <ForVariable name="$$opt_temp_2">
-              <UnhoistIterator>
-                <LetVarIterator varname="$$opt_temp_0"/>
-              </UnhoistIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ValueIndexEntryBuilderIterator>
-                <ForVarIterator varname="$$opt_temp_2"/>
-                <ForVarIterator varname="$$opt_temp_2"/>
-              </ValueIndexEntryBuilderIterator>
-            </ReturnClause>
-          </FLWORIterator>
-        </CreateInternalIndexIterator>
-      </LetVariable>
-      <ForVariable name="book">
-        <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-          <FnDocIterator>
-            <SingletonIterator value="xs:string(books.xml)"/>
-          </FnDocIterator>
-        </DescendantAxisIterator>
-      </ForVariable>
-      <ForVariable name="$$opt_temp_1">
-        <HoistIterator>
-          <FnCountIterator>
-            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-              <ForVarIterator varname="book"/>
-            </ChildAxisIterator>
-          </FnCountIterator>
-        </HoistIterator>
-      </ForVariable>
-      <ForVariable name="anzahl">
-        <ProbeIndexPointValueIterator>
-          <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-          <UnhoistIterator>
-            <ForVarIterator varname="$$opt_temp_1"/>
-          </UnhoistIterator>
-        </ProbeIndexPointValueIterator>
-      </ForVariable>
-      <ReturnClause>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,gruppe)"/>
-          <AttributeIterator qname="xs:QName(,,anzahl)">
-            <EnclosedIterator attr_cont="true">
-              <ForVarIterator varname="anzahl"/>
-            </EnclosedIterator>
-          </AttributeIterator>
-        </ElementIterator>
-      </ReturnClause>
-    </FLWORIterator>
-  </EnclosedIterator>
-</ElementIterator>
-
+<iterator-tree description="main query">
+  <ElementIterator>
+    <SingletonIterator value="xs:QName(,,karteikasten)"/>
+    <EnclosedIterator attr_cont="false">
+      <FLWORIterator>
+        <LetVariable name="$$opt_temp_0" materialize="true">
+          <HoistIterator>
+            <OpToIterator>
+              <SingletonIterator value="xs:integer(1)"/>
+              <SingletonIterator value="xs:integer(2)"/>
+            </OpToIterator>
+          </HoistIterator>
+        </LetVariable>
+        <LetVariable name="$$opt_temp_4" materialize="true">
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <FLWORIterator>
+              <ForVariable name="$$opt_temp_2">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
+                  <ForVarIterator varname="$$opt_temp_2"/>
+                  <ForVarIterator varname="$$opt_temp_2"/>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </FLWORIterator>
+          </CreateInternalIndexIterator>
+        </LetVariable>
+        <ForVariable name="book">
+          <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+            <FnDocIterator>
+              <SingletonIterator value="xs:string(books.xml)"/>
+            </FnDocIterator>
+          </DescendantAxisIterator>
+        </ForVariable>
+        <ForVariable name="$$opt_temp_1">
+          <HoistIterator>
+            <FnCountIterator>
+              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                <ForVarIterator varname="book"/>
+              </ChildAxisIterator>
+            </FnCountIterator>
+          </HoistIterator>
+        </ForVariable>
+        <ForVariable name="anzahl">
+          <ProbeIndexPointValueIterator>
+            <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+            <UnhoistIterator>
+              <ForVarIterator varname="$$opt_temp_1"/>
+            </UnhoistIterator>
+          </ProbeIndexPointValueIterator>
+        </ForVariable>
+        <ReturnClause>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,gruppe)"/>
+            <AttributeIterator qname="xs:QName(,,anzahl)">
+              <EnclosedIterator attr_cont="true">
+                <ForVarIterator varname="anzahl"/>
+              </EnclosedIterator>
+            </AttributeIterator>
+          </ElementIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </EnclosedIterator>
+  </ElementIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9198.iter'
--- test/iterplans/zorba/hashjoins/9198.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9198.iter	2014-02-20 05:31:00 +0000
@@ -1,71 +1,71 @@
-Iterator tree for main query:
-<ElementIterator>
-  <SingletonIterator value="xs:QName(,,karteikasten)"/>
-  <EnclosedIterator attr_cont="false">
-    <FLWORIterator>
-      <LetVariable name="$$opt_temp_0" materialize="true">
-        <HoistIterator>
-          <OpToIterator>
-            <SingletonIterator value="xs:integer(1)"/>
-            <SingletonIterator value="xs:integer(2)"/>
-          </OpToIterator>
-        </HoistIterator>
-      </LetVariable>
-      <LetVariable name="$$opt_temp_4" materialize="true">
-        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-          <FLWORIterator>
-            <ForVariable name="$$opt_temp_2">
-              <UnhoistIterator>
-                <LetVarIterator varname="$$opt_temp_0"/>
-              </UnhoistIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ValueIndexEntryBuilderIterator>
-                <ForVarIterator varname="$$opt_temp_2"/>
-                <ForVarIterator varname="$$opt_temp_2"/>
-              </ValueIndexEntryBuilderIterator>
-            </ReturnClause>
-          </FLWORIterator>
-        </CreateInternalIndexIterator>
-      </LetVariable>
-      <ForVariable name="book">
-        <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-          <FnDocIterator>
-            <SingletonIterator value="xs:string(books.xml)"/>
-          </FnDocIterator>
-        </DescendantAxisIterator>
-      </ForVariable>
-      <ForVariable name="$$opt_temp_1">
-        <HoistIterator>
-          <FnCountIterator>
-            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+<iterator-tree description="main query">
+  <ElementIterator>
+    <SingletonIterator value="xs:QName(,,karteikasten)"/>
+    <EnclosedIterator attr_cont="false">
+      <FLWORIterator>
+        <LetVariable name="$$opt_temp_0" materialize="true">
+          <HoistIterator>
+            <OpToIterator>
+              <SingletonIterator value="xs:integer(1)"/>
+              <SingletonIterator value="xs:integer(2)"/>
+            </OpToIterator>
+          </HoistIterator>
+        </LetVariable>
+        <LetVariable name="$$opt_temp_4" materialize="true">
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <FLWORIterator>
+              <ForVariable name="$$opt_temp_2">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
+                  <ForVarIterator varname="$$opt_temp_2"/>
+                  <ForVarIterator varname="$$opt_temp_2"/>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </FLWORIterator>
+          </CreateInternalIndexIterator>
+        </LetVariable>
+        <ForVariable name="book">
+          <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+            <FnDocIterator>
+              <SingletonIterator value="xs:string(books.xml)"/>
+            </FnDocIterator>
+          </DescendantAxisIterator>
+        </ForVariable>
+        <ForVariable name="$$opt_temp_1">
+          <HoistIterator>
+            <FnCountIterator>
+              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                <ForVarIterator varname="book"/>
+              </ChildAxisIterator>
+            </FnCountIterator>
+          </HoistIterator>
+        </ForVariable>
+        <ForVariable name="anzahl">
+          <ProbeIndexPointValueIterator>
+            <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+            <UnhoistIterator>
+              <ForVarIterator varname="$$opt_temp_1"/>
+            </UnhoistIterator>
+          </ProbeIndexPointValueIterator>
+        </ForVariable>
+        <ReturnClause>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,gruppe)"/>
+            <AttributeIterator qname="xs:QName(,,anzahl)">
+              <EnclosedIterator attr_cont="true">
+                <ForVarIterator varname="anzahl"/>
+              </EnclosedIterator>
+            </AttributeIterator>
+            <EnclosedIterator attr_cont="false">
               <ForVarIterator varname="book"/>
-            </ChildAxisIterator>
-          </FnCountIterator>
-        </HoistIterator>
-      </ForVariable>
-      <ForVariable name="anzahl">
-        <ProbeIndexPointValueIterator>
-          <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-          <UnhoistIterator>
-            <ForVarIterator varname="$$opt_temp_1"/>
-          </UnhoistIterator>
-        </ProbeIndexPointValueIterator>
-      </ForVariable>
-      <ReturnClause>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,gruppe)"/>
-          <AttributeIterator qname="xs:QName(,,anzahl)">
-            <EnclosedIterator attr_cont="true">
-              <ForVarIterator varname="anzahl"/>
             </EnclosedIterator>
-          </AttributeIterator>
-          <EnclosedIterator attr_cont="false">
-            <ForVarIterator varname="book"/>
-          </EnclosedIterator>
-        </ElementIterator>
-      </ReturnClause>
-    </FLWORIterator>
-  </EnclosedIterator>
-</ElementIterator>
-
+          </ElementIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </EnclosedIterator>
+  </ElementIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9199.iter'
--- test/iterplans/zorba/hashjoins/9199.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9199.iter	2014-02-20 05:31:00 +0000
@@ -1,71 +1,71 @@
-Iterator tree for main query:
-<ElementIterator>
-  <SingletonIterator value="xs:QName(,,karteikasten)"/>
-  <EnclosedIterator attr_cont="false">
-    <FLWORIterator>
-      <LetVariable name="$$opt_temp_0" materialize="true">
-        <HoistIterator>
-          <OpToIterator>
-            <SingletonIterator value="xs:integer(1)"/>
-            <SingletonIterator value="xs:integer(2)"/>
-          </OpToIterator>
-        </HoistIterator>
-      </LetVariable>
-      <LetVariable name="$$opt_temp_4" materialize="true">
-        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-          <FLWORIterator>
-            <ForVariable name="$$opt_temp_2">
-              <UnhoistIterator>
-                <LetVarIterator varname="$$opt_temp_0"/>
-              </UnhoistIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ValueIndexEntryBuilderIterator>
-                <ForVarIterator varname="$$opt_temp_2"/>
-                <ForVarIterator varname="$$opt_temp_2"/>
-              </ValueIndexEntryBuilderIterator>
-            </ReturnClause>
-          </FLWORIterator>
-        </CreateInternalIndexIterator>
-      </LetVariable>
-      <ForVariable name="book">
-        <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-          <FnDocIterator>
-            <SingletonIterator value="xs:string(books.xml)"/>
-          </FnDocIterator>
-        </DescendantAxisIterator>
-      </ForVariable>
-      <ForVariable name="$$opt_temp_1">
-        <HoistIterator>
-          <FnCountIterator>
-            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+<iterator-tree description="main query">
+  <ElementIterator>
+    <SingletonIterator value="xs:QName(,,karteikasten)"/>
+    <EnclosedIterator attr_cont="false">
+      <FLWORIterator>
+        <LetVariable name="$$opt_temp_0" materialize="true">
+          <HoistIterator>
+            <OpToIterator>
+              <SingletonIterator value="xs:integer(1)"/>
+              <SingletonIterator value="xs:integer(2)"/>
+            </OpToIterator>
+          </HoistIterator>
+        </LetVariable>
+        <LetVariable name="$$opt_temp_4" materialize="true">
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <FLWORIterator>
+              <ForVariable name="$$opt_temp_2">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
+                  <ForVarIterator varname="$$opt_temp_2"/>
+                  <ForVarIterator varname="$$opt_temp_2"/>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </FLWORIterator>
+          </CreateInternalIndexIterator>
+        </LetVariable>
+        <ForVariable name="book">
+          <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+            <FnDocIterator>
+              <SingletonIterator value="xs:string(books.xml)"/>
+            </FnDocIterator>
+          </DescendantAxisIterator>
+        </ForVariable>
+        <ForVariable name="$$opt_temp_1">
+          <HoistIterator>
+            <FnCountIterator>
+              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                <ForVarIterator varname="book"/>
+              </ChildAxisIterator>
+            </FnCountIterator>
+          </HoistIterator>
+        </ForVariable>
+        <ForVariable name="anzahl">
+          <ProbeIndexPointValueIterator>
+            <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+            <UnhoistIterator>
+              <ForVarIterator varname="$$opt_temp_1"/>
+            </UnhoistIterator>
+          </ProbeIndexPointValueIterator>
+        </ForVariable>
+        <ReturnClause>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,gruppe)"/>
+            <AttributeIterator qname="xs:QName(,,anzahl)">
+              <EnclosedIterator attr_cont="true">
+                <ForVarIterator varname="anzahl"/>
+              </EnclosedIterator>
+            </AttributeIterator>
+            <EnclosedIterator attr_cont="false">
               <ForVarIterator varname="book"/>
-            </ChildAxisIterator>
-          </FnCountIterator>
-        </HoistIterator>
-      </ForVariable>
-      <ForVariable name="anzahl">
-        <ProbeIndexPointValueIterator>
-          <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-          <UnhoistIterator>
-            <ForVarIterator varname="$$opt_temp_1"/>
-          </UnhoistIterator>
-        </ProbeIndexPointValueIterator>
-      </ForVariable>
-      <ReturnClause>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,gruppe)"/>
-          <AttributeIterator qname="xs:QName(,,anzahl)">
-            <EnclosedIterator attr_cont="true">
-              <ForVarIterator varname="anzahl"/>
             </EnclosedIterator>
-          </AttributeIterator>
-          <EnclosedIterator attr_cont="false">
-            <ForVarIterator varname="book"/>
-          </EnclosedIterator>
-        </ElementIterator>
-      </ReturnClause>
-    </FLWORIterator>
-  </EnclosedIterator>
-</ElementIterator>
-
+          </ElementIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </EnclosedIterator>
+  </ElementIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9204.iter'
--- test/iterplans/zorba/hashjoins/9204.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9204.iter	2014-02-20 05:31:00 +0000
@@ -1,75 +1,75 @@
-Iterator tree for main query:
-<FLWORIterator>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
-      <OpToIterator>
-        <SingletonIterator value="xs:integer(1)"/>
-        <SingletonIterator value="xs:integer(2)"/>
-      </OpToIterator>
-    </HoistIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_4" materialize="true">
-    <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-      <FLWORIterator>
-        <ForVariable name="$$opt_temp_2">
-          <UnhoistIterator>
-            <LetVarIterator varname="$$opt_temp_0"/>
-          </UnhoistIterator>
-        </ForVariable>
-        <ReturnClause>
-          <ValueIndexEntryBuilderIterator>
-            <ForVarIterator varname="$$opt_temp_2"/>
-            <ForVarIterator varname="$$opt_temp_2"/>
-          </ValueIndexEntryBuilderIterator>
-        </ReturnClause>
-      </FLWORIterator>
-    </CreateInternalIndexIterator>
-  </LetVariable>
-  <ForVariable name="book">
-    <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-      <FnDocIterator>
-        <SingletonIterator value="xs:string(books.xml)"/>
-      </FnDocIterator>
-    </DescendantAxisIterator>
-  </ForVariable>
-  <ForVariable name="$$opt_temp_1">
-    <HoistIterator>
-      <FnCountIterator>
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-          <ForVarIterator varname="book"/>
-        </ChildAxisIterator>
-      </FnCountIterator>
-    </HoistIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,karteikasten)"/>
-      <EnclosedIterator attr_cont="false">
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <LetVariable name="$$opt_temp_0" materialize="true">
+      <HoistIterator>
+        <OpToIterator>
+          <SingletonIterator value="xs:integer(1)"/>
+          <SingletonIterator value="xs:integer(2)"/>
+        </OpToIterator>
+      </HoistIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_4" materialize="true">
+      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
         <FLWORIterator>
-          <ForVariable name="anzahl">
-            <ProbeIndexPointValueIterator>
-              <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-              <UnhoistIterator>
-                <ForVarIterator varname="$$opt_temp_1"/>
-              </UnhoistIterator>
-            </ProbeIndexPointValueIterator>
+          <ForVariable name="$$opt_temp_2">
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_0"/>
+            </UnhoistIterator>
           </ForVariable>
           <ReturnClause>
-            <ElementIterator>
-              <SingletonIterator value="xs:QName(,,gruppe)"/>
-              <AttributeIterator qname="xs:QName(,,anzahl)">
-                <EnclosedIterator attr_cont="true">
-                  <ForVarIterator varname="anzahl"/>
-                </EnclosedIterator>
-              </AttributeIterator>
-              <EnclosedIterator attr_cont="false">
-                <ForVarIterator varname="book"/>
-              </EnclosedIterator>
-            </ElementIterator>
+            <ValueIndexEntryBuilderIterator>
+              <ForVarIterator varname="$$opt_temp_2"/>
+              <ForVarIterator varname="$$opt_temp_2"/>
+            </ValueIndexEntryBuilderIterator>
           </ReturnClause>
         </FLWORIterator>
-      </EnclosedIterator>
-    </ElementIterator>
-  </ReturnClause>
-</FLWORIterator>
-
+      </CreateInternalIndexIterator>
+    </LetVariable>
+    <ForVariable name="book">
+      <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+        <FnDocIterator>
+          <SingletonIterator value="xs:string(books.xml)"/>
+        </FnDocIterator>
+      </DescendantAxisIterator>
+    </ForVariable>
+    <ForVariable name="$$opt_temp_1">
+      <HoistIterator>
+        <FnCountIterator>
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+            <ForVarIterator varname="book"/>
+          </ChildAxisIterator>
+        </FnCountIterator>
+      </HoistIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,karteikasten)"/>
+        <EnclosedIterator attr_cont="false">
+          <FLWORIterator>
+            <ForVariable name="anzahl">
+              <ProbeIndexPointValueIterator>
+                <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+                <UnhoistIterator>
+                  <ForVarIterator varname="$$opt_temp_1"/>
+                </UnhoistIterator>
+              </ProbeIndexPointValueIterator>
+            </ForVariable>
+            <ReturnClause>
+              <ElementIterator>
+                <SingletonIterator value="xs:QName(,,gruppe)"/>
+                <AttributeIterator qname="xs:QName(,,anzahl)">
+                  <EnclosedIterator attr_cont="true">
+                    <ForVarIterator varname="anzahl"/>
+                  </EnclosedIterator>
+                </AttributeIterator>
+                <EnclosedIterator attr_cont="false">
+                  <ForVarIterator varname="book"/>
+                </EnclosedIterator>
+              </ElementIterator>
+            </ReturnClause>
+          </FLWORIterator>
+        </EnclosedIterator>
+      </ElementIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9206.iter'
--- test/iterplans/zorba/hashjoins/9206.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9206.iter	2014-02-20 05:31:00 +0000
@@ -1,64 +1,64 @@
-Iterator tree for main query:
-<ElementIterator>
-  <SingletonIterator value="xs:QName(,,karteikasten)"/>
-  <EnclosedIterator attr_cont="false">
-    <FLWORIterator>
-      <LetVariable name="$$opt_temp_0" materialize="true">
-        <HoistIterator>
-          <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-            <FnDocIterator>
-              <SingletonIterator value="xs:string(books.xml)"/>
-            </FnDocIterator>
-          </DescendantAxisIterator>
-        </HoistIterator>
-      </LetVariable>
-      <LetVariable name="$$opt_temp_3" materialize="true">
-        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-          <FLWORIterator>
-            <ForVariable name="$$opt_temp_1">
-              <UnhoistIterator>
-                <LetVarIterator varname="$$opt_temp_0"/>
-              </UnhoistIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ValueIndexEntryBuilderIterator>
-                <ForVarIterator varname="$$opt_temp_1"/>
-                <FnCountIterator>
-                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="$$opt_temp_1"/>
-                  </ChildAxisIterator>
-                </FnCountIterator>
-              </ValueIndexEntryBuilderIterator>
-            </ReturnClause>
-          </FLWORIterator>
-        </CreateInternalIndexIterator>
-      </LetVariable>
-      <ForVariable name="anzahl">
-        <OpToIterator>
-          <SingletonIterator value="xs:integer(1)"/>
-          <SingletonIterator value="xs:integer(2)"/>
-        </OpToIterator>
-      </ForVariable>
-      <ForVariable name="book">
-        <ProbeIndexPointValueIterator>
-          <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-          <ForVarIterator varname="anzahl"/>
-        </ProbeIndexPointValueIterator>
-      </ForVariable>
-      <ReturnClause>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,gruppe)"/>
-          <AttributeIterator qname="xs:QName(,,anzahl)">
-            <EnclosedIterator attr_cont="true">
-              <ForVarIterator varname="anzahl"/>
+<iterator-tree description="main query">
+  <ElementIterator>
+    <SingletonIterator value="xs:QName(,,karteikasten)"/>
+    <EnclosedIterator attr_cont="false">
+      <FLWORIterator>
+        <LetVariable name="$$opt_temp_0" materialize="true">
+          <HoistIterator>
+            <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+              <FnDocIterator>
+                <SingletonIterator value="xs:string(books.xml)"/>
+              </FnDocIterator>
+            </DescendantAxisIterator>
+          </HoistIterator>
+        </LetVariable>
+        <LetVariable name="$$opt_temp_3" materialize="true">
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <FLWORIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
+                  <ForVarIterator varname="$$opt_temp_1"/>
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </FLWORIterator>
+          </CreateInternalIndexIterator>
+        </LetVariable>
+        <ForVariable name="anzahl">
+          <OpToIterator>
+            <SingletonIterator value="xs:integer(1)"/>
+            <SingletonIterator value="xs:integer(2)"/>
+          </OpToIterator>
+        </ForVariable>
+        <ForVariable name="book">
+          <ProbeIndexPointValueIterator>
+            <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+            <ForVarIterator varname="anzahl"/>
+          </ProbeIndexPointValueIterator>
+        </ForVariable>
+        <ReturnClause>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,gruppe)"/>
+            <AttributeIterator qname="xs:QName(,,anzahl)">
+              <EnclosedIterator attr_cont="true">
+                <ForVarIterator varname="anzahl"/>
+              </EnclosedIterator>
+            </AttributeIterator>
+            <EnclosedIterator attr_cont="false">
+              <ForVarIterator varname="book"/>
             </EnclosedIterator>
-          </AttributeIterator>
-          <EnclosedIterator attr_cont="false">
-            <ForVarIterator varname="book"/>
-          </EnclosedIterator>
-        </ElementIterator>
-      </ReturnClause>
-    </FLWORIterator>
-  </EnclosedIterator>
-</ElementIterator>
-
+          </ElementIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </EnclosedIterator>
+  </ElementIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9207.iter'
--- test/iterplans/zorba/hashjoins/9207.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9207.iter	2014-02-20 05:31:00 +0000
@@ -1,71 +1,71 @@
-Iterator tree for main query:
-<ElementIterator>
-  <SingletonIterator value="xs:QName(,,karteikasten)"/>
-  <EnclosedIterator attr_cont="false">
-    <FLWORIterator>
-      <LetVariable name="$$opt_temp_0" materialize="true">
-        <HoistIterator>
-          <OpToIterator>
-            <SingletonIterator value="xs:integer(1)"/>
-            <SingletonIterator value="xs:integer(2)"/>
-          </OpToIterator>
-        </HoistIterator>
-      </LetVariable>
-      <LetVariable name="$$opt_temp_4" materialize="true">
-        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-          <FLWORIterator>
-            <ForVariable name="$$opt_temp_2">
-              <UnhoistIterator>
-                <LetVarIterator varname="$$opt_temp_0"/>
-              </UnhoistIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ValueIndexEntryBuilderIterator>
-                <ForVarIterator varname="$$opt_temp_2"/>
-                <ForVarIterator varname="$$opt_temp_2"/>
-              </ValueIndexEntryBuilderIterator>
-            </ReturnClause>
-          </FLWORIterator>
-        </CreateInternalIndexIterator>
-      </LetVariable>
-      <ForVariable name="book">
-        <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-          <FnDocIterator>
-            <SingletonIterator value="xs:string(books.xml)"/>
-          </FnDocIterator>
-        </DescendantAxisIterator>
-      </ForVariable>
-      <ForVariable name="$$opt_temp_1">
-        <HoistIterator>
-          <FnCountIterator>
-            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+<iterator-tree description="main query">
+  <ElementIterator>
+    <SingletonIterator value="xs:QName(,,karteikasten)"/>
+    <EnclosedIterator attr_cont="false">
+      <FLWORIterator>
+        <LetVariable name="$$opt_temp_0" materialize="true">
+          <HoistIterator>
+            <OpToIterator>
+              <SingletonIterator value="xs:integer(1)"/>
+              <SingletonIterator value="xs:integer(2)"/>
+            </OpToIterator>
+          </HoistIterator>
+        </LetVariable>
+        <LetVariable name="$$opt_temp_4" materialize="true">
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <FLWORIterator>
+              <ForVariable name="$$opt_temp_2">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
+                  <ForVarIterator varname="$$opt_temp_2"/>
+                  <ForVarIterator varname="$$opt_temp_2"/>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </FLWORIterator>
+          </CreateInternalIndexIterator>
+        </LetVariable>
+        <ForVariable name="book">
+          <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+            <FnDocIterator>
+              <SingletonIterator value="xs:string(books.xml)"/>
+            </FnDocIterator>
+          </DescendantAxisIterator>
+        </ForVariable>
+        <ForVariable name="$$opt_temp_1">
+          <HoistIterator>
+            <FnCountIterator>
+              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                <ForVarIterator varname="book"/>
+              </ChildAxisIterator>
+            </FnCountIterator>
+          </HoistIterator>
+        </ForVariable>
+        <ForVariable name="anzahl">
+          <ProbeIndexPointValueIterator>
+            <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+            <UnhoistIterator>
+              <ForVarIterator varname="$$opt_temp_1"/>
+            </UnhoistIterator>
+          </ProbeIndexPointValueIterator>
+        </ForVariable>
+        <ReturnClause>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,gruppe)"/>
+            <AttributeIterator qname="xs:QName(,,anzahl)">
+              <EnclosedIterator attr_cont="true">
+                <ForVarIterator varname="anzahl"/>
+              </EnclosedIterator>
+            </AttributeIterator>
+            <EnclosedIterator attr_cont="false">
               <ForVarIterator varname="book"/>
-            </ChildAxisIterator>
-          </FnCountIterator>
-        </HoistIterator>
-      </ForVariable>
-      <ForVariable name="anzahl">
-        <ProbeIndexPointValueIterator>
-          <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-          <UnhoistIterator>
-            <ForVarIterator varname="$$opt_temp_1"/>
-          </UnhoistIterator>
-        </ProbeIndexPointValueIterator>
-      </ForVariable>
-      <ReturnClause>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,gruppe)"/>
-          <AttributeIterator qname="xs:QName(,,anzahl)">
-            <EnclosedIterator attr_cont="true">
-              <ForVarIterator varname="anzahl"/>
             </EnclosedIterator>
-          </AttributeIterator>
-          <EnclosedIterator attr_cont="false">
-            <ForVarIterator varname="book"/>
-          </EnclosedIterator>
-        </ElementIterator>
-      </ReturnClause>
-    </FLWORIterator>
-  </EnclosedIterator>
-</ElementIterator>
-
+          </ElementIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </EnclosedIterator>
+  </ElementIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9210.iter'
--- test/iterplans/zorba/hashjoins/9210.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9210.iter	2014-02-20 05:31:00 +0000
@@ -1,68 +1,68 @@
-Iterator tree for main query:
-<ElementIterator>
-  <SingletonIterator value="xs:QName(,,karteikasten)"/>
-  <EnclosedIterator attr_cont="false">
-    <FLWORIterator>
-      <LetVariable name="$$opt_temp_0" materialize="true">
-        <HoistIterator>
-          <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-            <FnDocIterator>
-              <SingletonIterator value="xs:string(books.xml)"/>
-            </FnDocIterator>
-          </DescendantAxisIterator>
-        </HoistIterator>
-      </LetVariable>
-      <LetVariable name="$$opt_temp_3" materialize="true">
-        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-          <FLWORIterator>
-            <ForVariable name="$$opt_temp_1">
-              <UnhoistIterator>
-                <LetVarIterator varname="$$opt_temp_0"/>
-              </UnhoistIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ValueIndexEntryBuilderIterator>
-                <ForVarIterator varname="$$opt_temp_1"/>
-                <FnCountIterator>
-                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="$$opt_temp_1"/>
-                  </ChildAxisIterator>
-                </FnCountIterator>
-              </ValueIndexEntryBuilderIterator>
-            </ReturnClause>
-          </FLWORIterator>
-        </CreateInternalIndexIterator>
-      </LetVariable>
-      <ForVariable name="anzahl">
-        <OpToIterator>
-          <SingletonIterator value="xs:integer(1)"/>
-          <SingletonIterator value="xs:integer(2)"/>
-        </OpToIterator>
-      </ForVariable>
-      <ReturnClause>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,gruppe)"/>
-          <AttributeIterator qname="xs:QName(,,anzahl)">
-            <EnclosedIterator attr_cont="true">
-              <ForVarIterator varname="anzahl"/>
-            </EnclosedIterator>
-          </AttributeIterator>
-          <EnclosedIterator attr_cont="false">
+<iterator-tree description="main query">
+  <ElementIterator>
+    <SingletonIterator value="xs:QName(,,karteikasten)"/>
+    <EnclosedIterator attr_cont="false">
+      <FLWORIterator>
+        <LetVariable name="$$opt_temp_0" materialize="true">
+          <HoistIterator>
+            <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+              <FnDocIterator>
+                <SingletonIterator value="xs:string(books.xml)"/>
+              </FnDocIterator>
+            </DescendantAxisIterator>
+          </HoistIterator>
+        </LetVariable>
+        <LetVariable name="$$opt_temp_3" materialize="true">
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
             <FLWORIterator>
-              <ForVariable name="book">
-                <ProbeIndexPointValueIterator>
-                  <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-                  <ForVarIterator varname="anzahl"/>
-                </ProbeIndexPointValueIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
               </ForVariable>
               <ReturnClause>
-                <ForVarIterator varname="book"/>
+                <ValueIndexEntryBuilderIterator>
+                  <ForVarIterator varname="$$opt_temp_1"/>
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
               </ReturnClause>
             </FLWORIterator>
-          </EnclosedIterator>
-        </ElementIterator>
-      </ReturnClause>
-    </FLWORIterator>
-  </EnclosedIterator>
-</ElementIterator>
-
+          </CreateInternalIndexIterator>
+        </LetVariable>
+        <ForVariable name="anzahl">
+          <OpToIterator>
+            <SingletonIterator value="xs:integer(1)"/>
+            <SingletonIterator value="xs:integer(2)"/>
+          </OpToIterator>
+        </ForVariable>
+        <ReturnClause>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,gruppe)"/>
+            <AttributeIterator qname="xs:QName(,,anzahl)">
+              <EnclosedIterator attr_cont="true">
+                <ForVarIterator varname="anzahl"/>
+              </EnclosedIterator>
+            </AttributeIterator>
+            <EnclosedIterator attr_cont="false">
+              <FLWORIterator>
+                <ForVariable name="book">
+                  <ProbeIndexPointValueIterator>
+                    <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+                    <ForVarIterator varname="anzahl"/>
+                  </ProbeIndexPointValueIterator>
+                </ForVariable>
+                <ReturnClause>
+                  <ForVarIterator varname="book"/>
+                </ReturnClause>
+              </FLWORIterator>
+            </EnclosedIterator>
+          </ElementIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </EnclosedIterator>
+  </ElementIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9211.iter'
--- test/iterplans/zorba/hashjoins/9211.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9211.iter	2014-02-20 05:31:00 +0000
@@ -1,71 +1,71 @@
-Iterator tree for main query:
-<ElementIterator>
-  <SingletonIterator value="xs:QName(,,karteikasten)"/>
-  <EnclosedIterator attr_cont="false">
-    <FLWORIterator>
-      <LetVariable name="$$opt_temp_0" materialize="true">
-        <HoistIterator>
-          <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-            <FnDocIterator>
-              <SingletonIterator value="xs:string(books.xml)"/>
-            </FnDocIterator>
-          </DescendantAxisIterator>
-        </HoistIterator>
-      </LetVariable>
-      <LetVariable name="$$opt_temp_3" materialize="true">
-        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-          <FLWORIterator>
-            <ForVariable name="$$opt_temp_1">
-              <UnhoistIterator>
-                <LetVarIterator varname="$$opt_temp_0"/>
-              </UnhoistIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ValueIndexEntryBuilderIterator>
-                <ForVarIterator varname="$$opt_temp_1"/>
-                <FnCountIterator>
-                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="$$opt_temp_1"/>
-                  </ChildAxisIterator>
-                </FnCountIterator>
-              </ValueIndexEntryBuilderIterator>
-            </ReturnClause>
-          </FLWORIterator>
-        </CreateInternalIndexIterator>
-      </LetVariable>
-      <ForVariable name="anzahl">
-        <OpToIterator>
-          <SingletonIterator value="xs:integer(1)"/>
-          <SingletonIterator value="xs:integer(2)"/>
-        </OpToIterator>
-      </ForVariable>
-      <OrderBySpec>
-        <ForVarIterator varname="anzahl"/>
-      </OrderBySpec>
-      <ReturnClause>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,gruppe)"/>
-          <AttributeIterator qname="xs:QName(,,anzahl)">
-            <EnclosedIterator attr_cont="true">
-              <ForVarIterator varname="anzahl"/>
-            </EnclosedIterator>
-          </AttributeIterator>
-          <EnclosedIterator attr_cont="false">
+<iterator-tree description="main query">
+  <ElementIterator>
+    <SingletonIterator value="xs:QName(,,karteikasten)"/>
+    <EnclosedIterator attr_cont="false">
+      <FLWORIterator>
+        <LetVariable name="$$opt_temp_0" materialize="true">
+          <HoistIterator>
+            <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+              <FnDocIterator>
+                <SingletonIterator value="xs:string(books.xml)"/>
+              </FnDocIterator>
+            </DescendantAxisIterator>
+          </HoistIterator>
+        </LetVariable>
+        <LetVariable name="$$opt_temp_3" materialize="true">
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
             <FLWORIterator>
-              <ForVariable name="book">
-                <ProbeIndexPointValueIterator>
-                  <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-                  <ForVarIterator varname="anzahl"/>
-                </ProbeIndexPointValueIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
               </ForVariable>
               <ReturnClause>
-                <ForVarIterator varname="book"/>
+                <ValueIndexEntryBuilderIterator>
+                  <ForVarIterator varname="$$opt_temp_1"/>
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
               </ReturnClause>
             </FLWORIterator>
-          </EnclosedIterator>
-        </ElementIterator>
-      </ReturnClause>
-    </FLWORIterator>
-  </EnclosedIterator>
-</ElementIterator>
-
+          </CreateInternalIndexIterator>
+        </LetVariable>
+        <ForVariable name="anzahl">
+          <OpToIterator>
+            <SingletonIterator value="xs:integer(1)"/>
+            <SingletonIterator value="xs:integer(2)"/>
+          </OpToIterator>
+        </ForVariable>
+        <OrderBySpec>
+          <ForVarIterator varname="anzahl"/>
+        </OrderBySpec>
+        <ReturnClause>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,gruppe)"/>
+            <AttributeIterator qname="xs:QName(,,anzahl)">
+              <EnclosedIterator attr_cont="true">
+                <ForVarIterator varname="anzahl"/>
+              </EnclosedIterator>
+            </AttributeIterator>
+            <EnclosedIterator attr_cont="false">
+              <FLWORIterator>
+                <ForVariable name="book">
+                  <ProbeIndexPointValueIterator>
+                    <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+                    <ForVarIterator varname="anzahl"/>
+                  </ProbeIndexPointValueIterator>
+                </ForVariable>
+                <ReturnClause>
+                  <ForVarIterator varname="book"/>
+                </ReturnClause>
+              </FLWORIterator>
+            </EnclosedIterator>
+          </ElementIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </EnclosedIterator>
+  </ElementIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9212.iter'
--- test/iterplans/zorba/hashjoins/9212.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9212.iter	2014-02-20 05:31:00 +0000
@@ -1,79 +1,79 @@
-Iterator tree for main query:
-<ElementIterator>
-  <SingletonIterator value="xs:QName(,,karteikasten)"/>
-  <EnclosedIterator attr_cont="false">
-    <FLWORIterator>
-      <LetVariable name="$$opt_temp_0" materialize="true">
-        <HoistIterator>
+<iterator-tree description="main query">
+  <ElementIterator>
+    <SingletonIterator value="xs:QName(,,karteikasten)"/>
+    <EnclosedIterator attr_cont="false">
+      <FLWORIterator>
+        <LetVariable name="$$opt_temp_0" materialize="true">
+          <HoistIterator>
+            <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+              <FnDocIterator>
+                <SingletonIterator value="xs:string(books.xml)"/>
+              </FnDocIterator>
+            </DescendantAxisIterator>
+          </HoistIterator>
+        </LetVariable>
+        <LetVariable name="$$opt_temp_3" materialize="true">
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <FLWORIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
+                  <ForVarIterator varname="$$opt_temp_1"/>
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </FLWORIterator>
+          </CreateInternalIndexIterator>
+        </LetVariable>
+        <ForVariable name="book">
           <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
             <FnDocIterator>
               <SingletonIterator value="xs:string(books.xml)"/>
             </FnDocIterator>
           </DescendantAxisIterator>
-        </HoistIterator>
-      </LetVariable>
-      <LetVariable name="$$opt_temp_3" materialize="true">
-        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-          <FLWORIterator>
-            <ForVariable name="$$opt_temp_1">
-              <UnhoistIterator>
-                <LetVarIterator varname="$$opt_temp_0"/>
-              </UnhoistIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ValueIndexEntryBuilderIterator>
-                <ForVarIterator varname="$$opt_temp_1"/>
-                <FnCountIterator>
-                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="$$opt_temp_1"/>
-                  </ChildAxisIterator>
-                </FnCountIterator>
-              </ValueIndexEntryBuilderIterator>
-            </ReturnClause>
-          </FLWORIterator>
-        </CreateInternalIndexIterator>
-      </LetVariable>
-      <ForVariable name="book">
-        <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-          <FnDocIterator>
-            <SingletonIterator value="xs:string(books.xml)"/>
-          </FnDocIterator>
-        </DescendantAxisIterator>
-      </ForVariable>
-      <ForVariable name="anzahl">
-        <FnCountIterator>
-          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-            <ForVarIterator varname="book"/>
-          </ChildAxisIterator>
-        </FnCountIterator>
-      </ForVariable>
-      <OrderBySpec>
-        <ForVarIterator varname="anzahl"/>
-      </OrderBySpec>
-      <ReturnClause>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,gruppe)"/>
-          <AttributeIterator qname="xs:QName(,,anzahl)">
-            <EnclosedIterator attr_cont="true">
-              <ForVarIterator varname="anzahl"/>
+        </ForVariable>
+        <ForVariable name="anzahl">
+          <FnCountIterator>
+            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+              <ForVarIterator varname="book"/>
+            </ChildAxisIterator>
+          </FnCountIterator>
+        </ForVariable>
+        <OrderBySpec>
+          <ForVarIterator varname="anzahl"/>
+        </OrderBySpec>
+        <ReturnClause>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,gruppe)"/>
+            <AttributeIterator qname="xs:QName(,,anzahl)">
+              <EnclosedIterator attr_cont="true">
+                <ForVarIterator varname="anzahl"/>
+              </EnclosedIterator>
+            </AttributeIterator>
+            <EnclosedIterator attr_cont="false">
+              <FLWORIterator>
+                <ForVariable name="book">
+                  <ProbeIndexPointValueIterator>
+                    <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+                    <ForVarIterator varname="anzahl"/>
+                  </ProbeIndexPointValueIterator>
+                </ForVariable>
+                <ReturnClause>
+                  <ForVarIterator varname="book"/>
+                </ReturnClause>
+              </FLWORIterator>
             </EnclosedIterator>
-          </AttributeIterator>
-          <EnclosedIterator attr_cont="false">
-            <FLWORIterator>
-              <ForVariable name="book">
-                <ProbeIndexPointValueIterator>
-                  <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-                  <ForVarIterator varname="anzahl"/>
-                </ProbeIndexPointValueIterator>
-              </ForVariable>
-              <ReturnClause>
-                <ForVarIterator varname="book"/>
-              </ReturnClause>
-            </FLWORIterator>
-          </EnclosedIterator>
-        </ElementIterator>
-      </ReturnClause>
-    </FLWORIterator>
-  </EnclosedIterator>
-</ElementIterator>
-
+          </ElementIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </EnclosedIterator>
+  </ElementIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9389.iter'
--- test/iterplans/zorba/hashjoins/9389.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9389.iter	2014-02-20 05:31:00 +0000
@@ -1,66 +1,66 @@
-Iterator tree for main query:
-<ElementIterator>
-  <SingletonIterator value="xs:QName(,,karteikasten)"/>
-  <EnclosedIterator attr_cont="false">
-    <FLWORIterator>
-      <LetVariable name="$$opt_temp_0" materialize="true">
-        <HoistIterator>
-          <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-            <FnDocIterator>
-              <SingletonIterator value="xs:string(books.xml)"/>
-            </FnDocIterator>
-          </DescendantAxisIterator>
-        </HoistIterator>
-      </LetVariable>
-      <LetVariable name="$$opt_temp_3" materialize="true">
-        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-          <FLWORIterator>
-            <ForVariable name="$$opt_temp_1">
-              <UnhoistIterator>
-                <LetVarIterator varname="$$opt_temp_0"/>
-              </UnhoistIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ValueIndexEntryBuilderIterator>
-                <ForVarIterator varname="$$opt_temp_1"/>
-                <FnCountIterator>
-                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="$$opt_temp_1"/>
-                  </ChildAxisIterator>
-                </FnCountIterator>
-              </ValueIndexEntryBuilderIterator>
-            </ReturnClause>
-          </FLWORIterator>
-        </CreateInternalIndexIterator>
-      </LetVariable>
-      <ForVariable name="anzahl">
-        <OpToIterator>
-          <SingletonIterator value="xs:integer(1)"/>
-          <SingletonIterator value="xs:integer(5)"/>
-        </OpToIterator>
-      </ForVariable>
-      <ReturnClause>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,gruppe)"/>
-          <AttributeIterator qname="xs:QName(,,anzahl)">
-            <EnclosedIterator attr_cont="true">
-              <FLWORIterator>
-                <ForVariable name="karte">
-                  <ProbeIndexPointValueIterator>
-                    <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+<iterator-tree description="main query">
+  <ElementIterator>
+    <SingletonIterator value="xs:QName(,,karteikasten)"/>
+    <EnclosedIterator attr_cont="false">
+      <FLWORIterator>
+        <LetVariable name="$$opt_temp_0" materialize="true">
+          <HoistIterator>
+            <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+              <FnDocIterator>
+                <SingletonIterator value="xs:string(books.xml)"/>
+              </FnDocIterator>
+            </DescendantAxisIterator>
+          </HoistIterator>
+        </LetVariable>
+        <LetVariable name="$$opt_temp_3" materialize="true">
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <FLWORIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
+                  <ForVarIterator varname="$$opt_temp_1"/>
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </FLWORIterator>
+          </CreateInternalIndexIterator>
+        </LetVariable>
+        <ForVariable name="anzahl">
+          <OpToIterator>
+            <SingletonIterator value="xs:integer(1)"/>
+            <SingletonIterator value="xs:integer(5)"/>
+          </OpToIterator>
+        </ForVariable>
+        <ReturnClause>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,gruppe)"/>
+            <AttributeIterator qname="xs:QName(,,anzahl)">
+              <EnclosedIterator attr_cont="true">
+                <FLWORIterator>
+                  <ForVariable name="karte">
+                    <ProbeIndexPointValueIterator>
+                      <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+                      <ForVarIterator varname="anzahl"/>
+                    </ProbeIndexPointValueIterator>
+                  </ForVariable>
+                  <ReturnClause>
                     <ForVarIterator varname="anzahl"/>
-                  </ProbeIndexPointValueIterator>
-                </ForVariable>
-                <ReturnClause>
-                  <ForVarIterator varname="anzahl"/>
-                </ReturnClause>
-              </FLWORIterator>
-            </EnclosedIterator>
-          </AttributeIterator>
-          <FnConcatIterator/>
-        </ElementIterator>
-      </ReturnClause>
-    </FLWORIterator>
-  </EnclosedIterator>
-</ElementIterator>
-
+                  </ReturnClause>
+                </FLWORIterator>
+              </EnclosedIterator>
+            </AttributeIterator>
+            <FnConcatIterator/>
+          </ElementIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </EnclosedIterator>
+  </ElementIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9390.iter'
--- test/iterplans/zorba/hashjoins/9390.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9390.iter	2014-02-20 05:31:00 +0000
@@ -1,66 +1,66 @@
-Iterator tree for main query:
-<FLWORIterator>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
-      <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-        <FnDocIterator>
-          <SingletonIterator value="xs:string(books.xml)"/>
-        </FnDocIterator>
-      </DescendantAxisIterator>
-    </HoistIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_3" materialize="true">
-    <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-      <FLWORIterator>
-        <ForVariable name="$$opt_temp_1">
-          <UnhoistIterator>
-            <LetVarIterator varname="$$opt_temp_0"/>
-          </UnhoistIterator>
-        </ForVariable>
-        <ReturnClause>
-          <ValueIndexEntryBuilderIterator>
-            <ForVarIterator varname="$$opt_temp_1"/>
-            <FnCountIterator>
-              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-                <ForVarIterator varname="$$opt_temp_1"/>
-              </ChildAxisIterator>
-            </FnCountIterator>
-          </ValueIndexEntryBuilderIterator>
-        </ReturnClause>
-      </FLWORIterator>
-    </CreateInternalIndexIterator>
-  </LetVariable>
-  <ForVariable name="anzahl">
-    <OpToIterator>
-      <SingletonIterator value="xs:integer(1)"/>
-      <SingletonIterator value="xs:integer(5)"/>
-    </OpToIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,karteikasten)"/>
-      <EnclosedIterator attr_cont="false">
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,gruppe)"/>
-          <AttributeIterator qname="xs:QName(,,anzahl)">
-            <EnclosedIterator attr_cont="true">
-              <FLWORIterator>
-                <ForVariable name="karte">
-                  <ProbeIndexPointValueIterator>
-                    <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <LetVariable name="$$opt_temp_0" materialize="true">
+      <HoistIterator>
+        <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+          <FnDocIterator>
+            <SingletonIterator value="xs:string(books.xml)"/>
+          </FnDocIterator>
+        </DescendantAxisIterator>
+      </HoistIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_3" materialize="true">
+      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+        <FLWORIterator>
+          <ForVariable name="$$opt_temp_1">
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_0"/>
+            </UnhoistIterator>
+          </ForVariable>
+          <ReturnClause>
+            <ValueIndexEntryBuilderIterator>
+              <ForVarIterator varname="$$opt_temp_1"/>
+              <FnCountIterator>
+                <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                  <ForVarIterator varname="$$opt_temp_1"/>
+                </ChildAxisIterator>
+              </FnCountIterator>
+            </ValueIndexEntryBuilderIterator>
+          </ReturnClause>
+        </FLWORIterator>
+      </CreateInternalIndexIterator>
+    </LetVariable>
+    <ForVariable name="anzahl">
+      <OpToIterator>
+        <SingletonIterator value="xs:integer(1)"/>
+        <SingletonIterator value="xs:integer(5)"/>
+      </OpToIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,karteikasten)"/>
+        <EnclosedIterator attr_cont="false">
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,gruppe)"/>
+            <AttributeIterator qname="xs:QName(,,anzahl)">
+              <EnclosedIterator attr_cont="true">
+                <FLWORIterator>
+                  <ForVariable name="karte">
+                    <ProbeIndexPointValueIterator>
+                      <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+                      <ForVarIterator varname="anzahl"/>
+                    </ProbeIndexPointValueIterator>
+                  </ForVariable>
+                  <ReturnClause>
                     <ForVarIterator varname="anzahl"/>
-                  </ProbeIndexPointValueIterator>
-                </ForVariable>
-                <ReturnClause>
-                  <ForVarIterator varname="anzahl"/>
-                </ReturnClause>
-              </FLWORIterator>
-            </EnclosedIterator>
-          </AttributeIterator>
-          <FnConcatIterator/>
-        </ElementIterator>
-      </EnclosedIterator>
-    </ElementIterator>
-  </ReturnClause>
-</FLWORIterator>
-
+                  </ReturnClause>
+                </FLWORIterator>
+              </EnclosedIterator>
+            </AttributeIterator>
+            <FnConcatIterator/>
+          </ElementIterator>
+        </EnclosedIterator>
+      </ElementIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9391.iter'
--- test/iterplans/zorba/hashjoins/9391.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9391.iter	2014-02-20 05:31:00 +0000
@@ -1,71 +1,71 @@
-Iterator tree for main query:
-<ElementIterator>
-  <SingletonIterator value="xs:QName(,,karteikasten)"/>
-  <EnclosedIterator attr_cont="false">
-    <FLWORIterator>
-      <LetVariable name="$$opt_temp_0" materialize="true">
-        <HoistIterator>
-          <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-            <FnDocIterator>
-              <SingletonIterator value="xs:string(books.xml)"/>
-            </FnDocIterator>
-          </DescendantAxisIterator>
-        </HoistIterator>
-      </LetVariable>
-      <LetVariable name="$$opt_temp_3" materialize="true">
-        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-          <FLWORIterator>
-            <ForVariable name="$$opt_temp_1">
-              <UnhoistIterator>
-                <LetVarIterator varname="$$opt_temp_0"/>
-              </UnhoistIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ValueIndexEntryBuilderIterator>
-                <ForVarIterator varname="$$opt_temp_1"/>
-                <FnCountIterator>
-                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="$$opt_temp_1"/>
-                  </ChildAxisIterator>
-                </FnCountIterator>
-              </ValueIndexEntryBuilderIterator>
-            </ReturnClause>
-          </FLWORIterator>
-        </CreateInternalIndexIterator>
-      </LetVariable>
-      <ForVariable name="anzahl">
-        <OpToIterator>
-          <SingletonIterator value="xs:integer(1)"/>
-          <SingletonIterator value="xs:integer(2)"/>
-        </OpToIterator>
-      </ForVariable>
-      <ReturnClause>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,gruppe)"/>
-          <AttributeIterator qname="xs:QName(,,anzahl)">
-            <FnDataIterator>
-              <FnConcatIterator>
-                <SingletonIterator value="xs:string( )"/>
-                <EnclosedIterator attr_cont="true">
-                  <FLWORIterator>
-                    <ForVariable name="karte">
-                      <ProbeIndexPointValueIterator>
-                        <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+<iterator-tree description="main query">
+  <ElementIterator>
+    <SingletonIterator value="xs:QName(,,karteikasten)"/>
+    <EnclosedIterator attr_cont="false">
+      <FLWORIterator>
+        <LetVariable name="$$opt_temp_0" materialize="true">
+          <HoistIterator>
+            <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+              <FnDocIterator>
+                <SingletonIterator value="xs:string(books.xml)"/>
+              </FnDocIterator>
+            </DescendantAxisIterator>
+          </HoistIterator>
+        </LetVariable>
+        <LetVariable name="$$opt_temp_3" materialize="true">
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <FLWORIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
+                  <ForVarIterator varname="$$opt_temp_1"/>
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </FLWORIterator>
+          </CreateInternalIndexIterator>
+        </LetVariable>
+        <ForVariable name="anzahl">
+          <OpToIterator>
+            <SingletonIterator value="xs:integer(1)"/>
+            <SingletonIterator value="xs:integer(2)"/>
+          </OpToIterator>
+        </ForVariable>
+        <ReturnClause>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,gruppe)"/>
+            <AttributeIterator qname="xs:QName(,,anzahl)">
+              <FnDataIterator>
+                <FnConcatIterator>
+                  <SingletonIterator value="xs:string( )"/>
+                  <EnclosedIterator attr_cont="true">
+                    <FLWORIterator>
+                      <ForVariable name="karte">
+                        <ProbeIndexPointValueIterator>
+                          <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+                          <ForVarIterator varname="anzahl"/>
+                        </ProbeIndexPointValueIterator>
+                      </ForVariable>
+                      <ReturnClause>
                         <ForVarIterator varname="anzahl"/>
-                      </ProbeIndexPointValueIterator>
-                    </ForVariable>
-                    <ReturnClause>
-                      <ForVarIterator varname="anzahl"/>
-                    </ReturnClause>
-                  </FLWORIterator>
-                </EnclosedIterator>
-              </FnConcatIterator>
-            </FnDataIterator>
-          </AttributeIterator>
-          <FnConcatIterator/>
-        </ElementIterator>
-      </ReturnClause>
-    </FLWORIterator>
-  </EnclosedIterator>
-</ElementIterator>
-
+                      </ReturnClause>
+                    </FLWORIterator>
+                  </EnclosedIterator>
+                </FnConcatIterator>
+              </FnDataIterator>
+            </AttributeIterator>
+            <FnConcatIterator/>
+          </ElementIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </EnclosedIterator>
+  </ElementIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9392.iter'
--- test/iterplans/zorba/hashjoins/9392.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9392.iter	2014-02-20 05:31:00 +0000
@@ -1,67 +1,67 @@
-Iterator tree for main query:
-<ElementIterator>
-  <SingletonIterator value="xs:QName(,,karteikasten)"/>
-  <EnclosedIterator attr_cont="false">
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,gruppe)"/>
-      <AttributeIterator qname="xs:QName(,,anzahl)">
-        <FnDataIterator>
-          <FnConcatIterator>
-            <SingletonIterator value="xs:string( )"/>
-            <EnclosedIterator attr_cont="true">
-              <FLWORIterator>
-                <LetVariable name="$$opt_temp_0" materialize="true">
-                  <HoistIterator>
-                    <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-                      <FnDocIterator>
-                        <SingletonIterator value="xs:string(books.xml)"/>
-                      </FnDocIterator>
-                    </DescendantAxisIterator>
-                  </HoistIterator>
-                </LetVariable>
-                <LetVariable name="$$opt_temp_3" materialize="true">
-                  <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-                    <FLWORIterator>
-                      <ForVariable name="$$opt_temp_1">
-                        <UnhoistIterator>
-                          <LetVarIterator varname="$$opt_temp_0"/>
-                        </UnhoistIterator>
-                      </ForVariable>
-                      <ReturnClause>
-                        <ValueIndexEntryBuilderIterator>
-                          <ForVarIterator varname="$$opt_temp_1"/>
-                          <FnCountIterator>
-                            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-                              <ForVarIterator varname="$$opt_temp_1"/>
-                            </ChildAxisIterator>
-                          </FnCountIterator>
-                        </ValueIndexEntryBuilderIterator>
-                      </ReturnClause>
-                    </FLWORIterator>
-                  </CreateInternalIndexIterator>
-                </LetVariable>
-                <ForVariable name="anzahl">
-                  <OpToIterator>
-                    <SingletonIterator value="xs:integer(1)"/>
-                    <SingletonIterator value="xs:integer(2)"/>
-                  </OpToIterator>
-                </ForVariable>
-                <ForVariable name="karte">
-                  <ProbeIndexPointValueIterator>
-                    <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+<iterator-tree description="main query">
+  <ElementIterator>
+    <SingletonIterator value="xs:QName(,,karteikasten)"/>
+    <EnclosedIterator attr_cont="false">
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,gruppe)"/>
+        <AttributeIterator qname="xs:QName(,,anzahl)">
+          <FnDataIterator>
+            <FnConcatIterator>
+              <SingletonIterator value="xs:string( )"/>
+              <EnclosedIterator attr_cont="true">
+                <FLWORIterator>
+                  <LetVariable name="$$opt_temp_0" materialize="true">
+                    <HoistIterator>
+                      <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+                        <FnDocIterator>
+                          <SingletonIterator value="xs:string(books.xml)"/>
+                        </FnDocIterator>
+                      </DescendantAxisIterator>
+                    </HoistIterator>
+                  </LetVariable>
+                  <LetVariable name="$$opt_temp_3" materialize="true">
+                    <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+                      <FLWORIterator>
+                        <ForVariable name="$$opt_temp_1">
+                          <UnhoistIterator>
+                            <LetVarIterator varname="$$opt_temp_0"/>
+                          </UnhoistIterator>
+                        </ForVariable>
+                        <ReturnClause>
+                          <ValueIndexEntryBuilderIterator>
+                            <ForVarIterator varname="$$opt_temp_1"/>
+                            <FnCountIterator>
+                              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                                <ForVarIterator varname="$$opt_temp_1"/>
+                              </ChildAxisIterator>
+                            </FnCountIterator>
+                          </ValueIndexEntryBuilderIterator>
+                        </ReturnClause>
+                      </FLWORIterator>
+                    </CreateInternalIndexIterator>
+                  </LetVariable>
+                  <ForVariable name="anzahl">
+                    <OpToIterator>
+                      <SingletonIterator value="xs:integer(1)"/>
+                      <SingletonIterator value="xs:integer(2)"/>
+                    </OpToIterator>
+                  </ForVariable>
+                  <ForVariable name="karte">
+                    <ProbeIndexPointValueIterator>
+                      <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+                      <ForVarIterator varname="anzahl"/>
+                    </ProbeIndexPointValueIterator>
+                  </ForVariable>
+                  <ReturnClause>
                     <ForVarIterator varname="anzahl"/>
-                  </ProbeIndexPointValueIterator>
-                </ForVariable>
-                <ReturnClause>
-                  <ForVarIterator varname="anzahl"/>
-                </ReturnClause>
-              </FLWORIterator>
-            </EnclosedIterator>
-          </FnConcatIterator>
-        </FnDataIterator>
-      </AttributeIterator>
-      <FnConcatIterator/>
-    </ElementIterator>
-  </EnclosedIterator>
-</ElementIterator>
-
+                  </ReturnClause>
+                </FLWORIterator>
+              </EnclosedIterator>
+            </FnConcatIterator>
+          </FnDataIterator>
+        </AttributeIterator>
+        <FnConcatIterator/>
+      </ElementIterator>
+    </EnclosedIterator>
+  </ElementIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9399.iter'
--- test/iterplans/zorba/hashjoins/9399.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9399.iter	2014-02-20 05:31:00 +0000
@@ -1,65 +1,65 @@
-Iterator tree for main query:
-<ElementIterator>
-  <SingletonIterator value="xs:QName(,,karteikasten)"/>
-  <EnclosedIterator attr_cont="false">
-    <FLWORIterator>
-      <LetVariable name="$$opt_temp_0" materialize="true">
-        <HoistIterator>
-          <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-            <FnDocIterator>
-              <SingletonIterator value="xs:string(books.xml)"/>
-            </FnDocIterator>
-          </DescendantAxisIterator>
-        </HoistIterator>
-      </LetVariable>
-      <LetVariable name="$$opt_temp_3" materialize="true">
-        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-          <FLWORIterator>
-            <ForVariable name="$$opt_temp_1">
-              <UnhoistIterator>
-                <LetVarIterator varname="$$opt_temp_0"/>
-              </UnhoistIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ValueIndexEntryBuilderIterator>
-                <ForVarIterator varname="$$opt_temp_1"/>
-                <FnCountIterator>
-                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="$$opt_temp_1"/>
-                  </ChildAxisIterator>
-                </FnCountIterator>
-              </ValueIndexEntryBuilderIterator>
-            </ReturnClause>
-          </FLWORIterator>
-        </CreateInternalIndexIterator>
-      </LetVariable>
-      <ForVariable name="anzahl">
-        <OpToIterator>
-          <SingletonIterator value="xs:integer(1)"/>
-          <SingletonIterator value="xs:integer(2)"/>
-        </OpToIterator>
-      </ForVariable>
-      <ReturnClause>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,gruppe)"/>
-          <AttributeIterator qname="xs:QName(,,anzahl)">
-            <EnclosedIterator attr_cont="true">
-              <FLWORIterator>
-                <ForVariable name="a">
-                  <ProbeIndexPointValueIterator>
-                    <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+<iterator-tree description="main query">
+  <ElementIterator>
+    <SingletonIterator value="xs:QName(,,karteikasten)"/>
+    <EnclosedIterator attr_cont="false">
+      <FLWORIterator>
+        <LetVariable name="$$opt_temp_0" materialize="true">
+          <HoistIterator>
+            <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+              <FnDocIterator>
+                <SingletonIterator value="xs:string(books.xml)"/>
+              </FnDocIterator>
+            </DescendantAxisIterator>
+          </HoistIterator>
+        </LetVariable>
+        <LetVariable name="$$opt_temp_3" materialize="true">
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <FLWORIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
+                  <ForVarIterator varname="$$opt_temp_1"/>
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </FLWORIterator>
+          </CreateInternalIndexIterator>
+        </LetVariable>
+        <ForVariable name="anzahl">
+          <OpToIterator>
+            <SingletonIterator value="xs:integer(1)"/>
+            <SingletonIterator value="xs:integer(2)"/>
+          </OpToIterator>
+        </ForVariable>
+        <ReturnClause>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,gruppe)"/>
+            <AttributeIterator qname="xs:QName(,,anzahl)">
+              <EnclosedIterator attr_cont="true">
+                <FLWORIterator>
+                  <ForVariable name="a">
+                    <ProbeIndexPointValueIterator>
+                      <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+                      <ForVarIterator varname="anzahl"/>
+                    </ProbeIndexPointValueIterator>
+                  </ForVariable>
+                  <ReturnClause>
                     <ForVarIterator varname="anzahl"/>
-                  </ProbeIndexPointValueIterator>
-                </ForVariable>
-                <ReturnClause>
-                  <ForVarIterator varname="anzahl"/>
-                </ReturnClause>
-              </FLWORIterator>
-            </EnclosedIterator>
-          </AttributeIterator>
-        </ElementIterator>
-      </ReturnClause>
-    </FLWORIterator>
-  </EnclosedIterator>
-</ElementIterator>
-
+                  </ReturnClause>
+                </FLWORIterator>
+              </EnclosedIterator>
+            </AttributeIterator>
+          </ElementIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </EnclosedIterator>
+  </ElementIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/9400.iter'
--- test/iterplans/zorba/hashjoins/9400.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/9400.iter	2014-02-20 05:31:00 +0000
@@ -1,66 +1,66 @@
-Iterator tree for main query:
-<ElementIterator>
-  <SingletonIterator value="xs:QName(,,karteikasten)"/>
-  <EnclosedIterator attr_cont="false">
-    <FLWORIterator>
-      <LetVariable name="$$opt_temp_0" materialize="true">
-        <HoistIterator>
-          <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
-            <FnDocIterator>
-              <SingletonIterator value="xs:string(books.xml)"/>
-            </FnDocIterator>
-          </DescendantAxisIterator>
-        </HoistIterator>
-      </LetVariable>
-      <LetVariable name="$$opt_temp_3" materialize="true">
-        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-          <FLWORIterator>
-            <ForVariable name="$$opt_temp_1">
-              <UnhoistIterator>
-                <LetVarIterator varname="$$opt_temp_0"/>
-              </UnhoistIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ValueIndexEntryBuilderIterator>
-                <ForVarIterator varname="$$opt_temp_1"/>
-                <FnCountIterator>
-                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="$$opt_temp_1"/>
-                  </ChildAxisIterator>
-                </FnCountIterator>
-              </ValueIndexEntryBuilderIterator>
-            </ReturnClause>
-          </FLWORIterator>
-        </CreateInternalIndexIterator>
-      </LetVariable>
-      <ForVariable name="anzahl">
-        <OpToIterator>
-          <SingletonIterator value="xs:integer(1)"/>
-          <SingletonIterator value="xs:integer(2)"/>
-        </OpToIterator>
-      </ForVariable>
-      <ReturnClause>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,gruppe)"/>
-          <AttributeIterator qname="xs:QName(,,anzahl)">
-            <EmptyIterator/>
-          </AttributeIterator>
-          <EnclosedIterator attr_cont="false">
+<iterator-tree description="main query">
+  <ElementIterator>
+    <SingletonIterator value="xs:QName(,,karteikasten)"/>
+    <EnclosedIterator attr_cont="false">
+      <FLWORIterator>
+        <LetVariable name="$$opt_temp_0" materialize="true">
+          <HoistIterator>
+            <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
+              <FnDocIterator>
+                <SingletonIterator value="xs:string(books.xml)"/>
+              </FnDocIterator>
+            </DescendantAxisIterator>
+          </HoistIterator>
+        </LetVariable>
+        <LetVariable name="$$opt_temp_3" materialize="true">
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
             <FLWORIterator>
-              <ForVariable name="a">
-                <ProbeIndexPointValueIterator>
-                  <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-                  <ForVarIterator varname="anzahl"/>
-                </ProbeIndexPointValueIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
               </ForVariable>
               <ReturnClause>
-                <ForVarIterator varname="a"/>
+                <ValueIndexEntryBuilderIterator>
+                  <ForVarIterator varname="$$opt_temp_1"/>
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
               </ReturnClause>
             </FLWORIterator>
-          </EnclosedIterator>
-        </ElementIterator>
-      </ReturnClause>
-    </FLWORIterator>
-  </EnclosedIterator>
-</ElementIterator>
-
+          </CreateInternalIndexIterator>
+        </LetVariable>
+        <ForVariable name="anzahl">
+          <OpToIterator>
+            <SingletonIterator value="xs:integer(1)"/>
+            <SingletonIterator value="xs:integer(2)"/>
+          </OpToIterator>
+        </ForVariable>
+        <ReturnClause>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,gruppe)"/>
+            <AttributeIterator qname="xs:QName(,,anzahl)">
+              <EmptyIterator/>
+            </AttributeIterator>
+            <EnclosedIterator attr_cont="false">
+              <FLWORIterator>
+                <ForVariable name="a">
+                  <ProbeIndexPointValueIterator>
+                    <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+                    <ForVarIterator varname="anzahl"/>
+                  </ProbeIndexPointValueIterator>
+                </ForVariable>
+                <ReturnClause>
+                  <ForVarIterator varname="a"/>
+                </ReturnClause>
+              </FLWORIterator>
+            </EnclosedIterator>
+          </ElementIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </EnclosedIterator>
+  </ElementIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/gary1.iter'
--- test/iterplans/zorba/hashjoins/gary1.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/gary1.iter	2014-02-20 05:31:00 +0000
@@ -1,217 +1,217 @@
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for main query:
-<ElementIterator>
-  <SingletonIterator value="xs:QName(,,institutions)"/>
-  <EnclosedIterator attr_cont="false">
-    <FLWORIterator>
-      <LetVariable name="y" materialize="true">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,data)" typename="*" nill allowed="0">
-          <TupleStreamIterator>
-            <WhereIterator>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <ElementIterator>
+    <SingletonIterator value="xs:QName(,,institutions)"/>
+    <EnclosedIterator attr_cont="false">
+      <FLWORIterator>
+        <LetVariable name="y" materialize="true">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,data)" typename="*" nill allowed="0">
+            <TupleStreamIterator>
               <WhereIterator>
-                <ForIterator>
-                  <ForVariable name="$$context-item"/>
+                <WhereIterator>
                   <ForIterator>
                     <ForVariable name="$$context-item"/>
-                    <TupleSourceIterator/>
-                    <FnDocIterator>
-                      <SingletonIterator value="xs:string(min_ic1980.xml)"/>
-                    </FnDocIterator>
+                    <ForIterator>
+                      <ForVariable name="$$context-item"/>
+                      <TupleSourceIterator/>
+                      <FnDocIterator>
+                        <SingletonIterator value="xs:string(min_ic1980.xml)"/>
+                      </FnDocIterator>
+                    </ForIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,ipeds)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$context-item"/>
+                    </ChildAxisIterator>
                   </ForIterator>
-                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,ipeds)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="$$context-item"/>
-                  </ChildAxisIterator>
-                </ForIterator>
+                  <CompareIterator>
+                    <FnDataIterator>
+                      <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,year)" typename="*" nill allowed="0">
+                        <ForVarIterator varname="$$context-item"/>
+                      </AttributeAxisIterator>
+                    </FnDataIterator>
+                    <SingletonIterator value="xs:integer(1980)"/>
+                  </CompareIterator>
+                </WhereIterator>
                 <CompareIterator>
                   <FnDataIterator>
-                    <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,year)" typename="*" nill allowed="0">
+                    <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,file)" typename="*" nill allowed="0">
                       <ForVarIterator varname="$$context-item"/>
                     </AttributeAxisIterator>
                   </FnDataIterator>
-                  <SingletonIterator value="xs:integer(1980)"/>
+                  <SingletonIterator value="xs:string(ic1980)"/>
                 </CompareIterator>
               </WhereIterator>
-              <CompareIterator>
-                <FnDataIterator>
-                  <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,file)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="$$context-item"/>
-                  </AttributeAxisIterator>
-                </FnDataIterator>
-                <SingletonIterator value="xs:string(ic1980)"/>
-              </CompareIterator>
-            </WhereIterator>
-            <ForVarIterator varname="$$context-item"/>
-          </TupleStreamIterator>
-        </ChildAxisIterator>
-      </LetVariable>
-      <LetVariable name="$$opt_temp_4" materialize="true">
-        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-          <FLWORIterator>
-            <ForVariable name="$$opt_temp_2">
-              <LetVarIterator varname="y"/>
-            </ForVariable>
-            <ReturnClause>
-              <GeneralIndexEntryBuilderIterator>
-                <ForVarIterator varname="$$opt_temp_2"/>
-                <FnDataIterator>
-                  <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,unitid)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="$$opt_temp_2"/>
-                  </AttributeAxisIterator>
-                </FnDataIterator>
-              </GeneralIndexEntryBuilderIterator>
-            </ReturnClause>
-          </FLWORIterator>
-        </CreateInternalIndexIterator>
-      </LetVariable>
-      <ForVariable name="i">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,inst)" typename="*" nill allowed="0">
-          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,institutions)" typename="*" nill allowed="0">
-            <FnDocIterator>
-              <SingletonIterator value="xs:string(base.xml)"/>
-            </FnDocIterator>
+              <ForVarIterator varname="$$context-item"/>
+            </TupleStreamIterator>
           </ChildAxisIterator>
-        </ChildAxisIterator>
-      </ForVariable>
-      <LetVariable name="unitid" materialize="true">
-        <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,unitid)" typename="*" nill allowed="0">
-          <ForVarIterator varname="i"/>
-        </AttributeAxisIterator>
-      </LetVariable>
-      <LetVariable name="$$opt_temp_1" materialize="true">
-        <HoistIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="*" typename="*" nill allowed="0">
+        </LetVariable>
+        <LetVariable name="$$opt_temp_4" materialize="true">
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
             <FLWORIterator>
-              <ForVariable name="$$context-item">
-                <NodeSortIterator distinct="true" ascending="true">
-                  <ProbeIndexPointGeneralIterator>
-                    <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-                    <FnDataIterator>
-                      <LetVarIterator varname="unitid"/>
-                    </FnDataIterator>
-                  </ProbeIndexPointGeneralIterator>
-                </NodeSortIterator>
+              <ForVariable name="$$opt_temp_2">
+                <LetVarIterator varname="y"/>
               </ForVariable>
               <ReturnClause>
-                <ForVarIterator varname="$$context-item"/>
+                <GeneralIndexEntryBuilderIterator>
+                  <ForVarIterator varname="$$opt_temp_2"/>
+                  <FnDataIterator>
+                    <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,unitid)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_2"/>
+                    </AttributeAxisIterator>
+                  </FnDataIterator>
+                </GeneralIndexEntryBuilderIterator>
               </ReturnClause>
             </FLWORIterator>
+          </CreateInternalIndexIterator>
+        </LetVariable>
+        <ForVariable name="i">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,inst)" typename="*" nill allowed="0">
+            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,institutions)" typename="*" nill allowed="0">
+              <FnDocIterator>
+                <SingletonIterator value="xs:string(base.xml)"/>
+              </FnDocIterator>
+            </ChildAxisIterator>
+          </ChildAxisIterator>
+        </ForVariable>
+        <LetVariable name="unitid" materialize="true">
+          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,unitid)" typename="*" nill allowed="0">
+            <ForVarIterator varname="i"/>
           </AttributeAxisIterator>
-        </HoistIterator>
-      </LetVariable>
-      <ReturnClause>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,inst)"/>
-          <AttributeIterator qname="xs:QName(,,unitid)">
-            <EnclosedIterator attr_cont="true">
-              <FnDataIterator>
-                <LetVarIterator varname="unitid"/>
-              </FnDataIterator>
-            </EnclosedIterator>
-          </AttributeIterator>
-          <EnclosedIterator attr_cont="false">
-            <FLWORIterator>
-              <ForVariable name="j">
-                <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,year)" typename="*" nill allowed="0">
-                  <ForVarIterator varname="i"/>
-                </ChildAxisIterator>
-              </ForVariable>
-              <LetVariable name="year" materialize="true">
-                <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
-                  <ForVarIterator varname="j"/>
-                </AttributeAxisIterator>
-              </LetVariable>
-              <ForVariable name="$$opt_temp_0">
-                <HoistIterator>
-                  <CompareIterator>
-                    <FnDataIterator>
-                      <LetVarIterator varname="year"/>
-                    </FnDataIterator>
-                    <SingletonIterator value="xs:integer(1980)"/>
-                  </CompareIterator>
-                </HoistIterator>
-              </ForVariable>
-              <ReturnClause>
-                <ElementIterator>
-                  <SingletonIterator value="xs:QName(,,year)"/>
-                  <AttributeIterator qname="xs:QName(,,name)">
-                    <EnclosedIterator attr_cont="true">
+        </LetVariable>
+        <LetVariable name="$$opt_temp_1" materialize="true">
+          <HoistIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="*" typename="*" nill allowed="0">
+              <FLWORIterator>
+                <ForVariable name="$$context-item">
+                  <NodeSortIterator distinct="true" ascending="true">
+                    <ProbeIndexPointGeneralIterator>
+                      <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+                      <FnDataIterator>
+                        <LetVarIterator varname="unitid"/>
+                      </FnDataIterator>
+                    </ProbeIndexPointGeneralIterator>
+                  </NodeSortIterator>
+                </ForVariable>
+                <ReturnClause>
+                  <ForVarIterator varname="$$context-item"/>
+                </ReturnClause>
+              </FLWORIterator>
+            </AttributeAxisIterator>
+          </HoistIterator>
+        </LetVariable>
+        <ReturnClause>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,inst)"/>
+            <AttributeIterator qname="xs:QName(,,unitid)">
+              <EnclosedIterator attr_cont="true">
+                <FnDataIterator>
+                  <LetVarIterator varname="unitid"/>
+                </FnDataIterator>
+              </EnclosedIterator>
+            </AttributeIterator>
+            <EnclosedIterator attr_cont="false">
+              <FLWORIterator>
+                <ForVariable name="j">
+                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,year)" typename="*" nill allowed="0">
+                    <ForVarIterator varname="i"/>
+                  </ChildAxisIterator>
+                </ForVariable>
+                <LetVariable name="year" materialize="true">
+                  <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
+                    <ForVarIterator varname="j"/>
+                  </AttributeAxisIterator>
+                </LetVariable>
+                <ForVariable name="$$opt_temp_0">
+                  <HoistIterator>
+                    <CompareIterator>
                       <FnDataIterator>
                         <LetVarIterator varname="year"/>
                       </FnDataIterator>
-                    </EnclosedIterator>
-                  </AttributeIterator>
-                  <EnclosedIterator attr_cont="false">
-                    <FLWORIterator>
-                      <ForVariable name="k">
-                        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,file)" typename="*" nill allowed="0">
-                          <ForVarIterator varname="j"/>
-                        </ChildAxisIterator>
-                      </ForVariable>
-                      <LetVariable name="file" materialize="true">
-                        <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
-                          <ForVarIterator varname="k"/>
-                        </AttributeAxisIterator>
-                      </LetVariable>
-                      <ReturnClause>
-                        <ElementIterator>
-                          <SingletonIterator value="xs:QName(,,file)"/>
-                          <AttributeIterator qname="xs:QName(,,name)">
-                            <EnclosedIterator attr_cont="true">
-                              <FnDataIterator>
-                                <LetVarIterator varname="file"/>
-                              </FnDataIterator>
-                            </EnclosedIterator>
-                          </AttributeIterator>
-                          <EnclosedIterator attr_cont="false">
-                            <IfThenElseIterator>
-                              <AndIterator>
+                      <SingletonIterator value="xs:integer(1980)"/>
+                    </CompareIterator>
+                  </HoistIterator>
+                </ForVariable>
+                <ReturnClause>
+                  <ElementIterator>
+                    <SingletonIterator value="xs:QName(,,year)"/>
+                    <AttributeIterator qname="xs:QName(,,name)">
+                      <EnclosedIterator attr_cont="true">
+                        <FnDataIterator>
+                          <LetVarIterator varname="year"/>
+                        </FnDataIterator>
+                      </EnclosedIterator>
+                    </AttributeIterator>
+                    <EnclosedIterator attr_cont="false">
+                      <FLWORIterator>
+                        <ForVariable name="k">
+                          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,file)" typename="*" nill allowed="0">
+                            <ForVarIterator varname="j"/>
+                          </ChildAxisIterator>
+                        </ForVariable>
+                        <LetVariable name="file" materialize="true">
+                          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
+                            <ForVarIterator varname="k"/>
+                          </AttributeAxisIterator>
+                        </LetVariable>
+                        <ReturnClause>
+                          <ElementIterator>
+                            <SingletonIterator value="xs:QName(,,file)"/>
+                            <AttributeIterator qname="xs:QName(,,name)">
+                              <EnclosedIterator attr_cont="true">
+                                <FnDataIterator>
+                                  <LetVarIterator varname="file"/>
+                                </FnDataIterator>
+                              </EnclosedIterator>
+                            </AttributeIterator>
+                            <EnclosedIterator attr_cont="false">
+                              <IfThenElseIterator>
+                                <AndIterator>
+                                  <UnhoistIterator>
+                                    <ForVarIterator varname="$$opt_temp_0"/>
+                                  </UnhoistIterator>
+                                  <CompareIterator>
+                                    <FnDataIterator>
+                                      <LetVarIterator varname="file"/>
+                                    </FnDataIterator>
+                                    <SingletonIterator value="xs:string(ic1980)"/>
+                                  </CompareIterator>
+                                </AndIterator>
                                 <UnhoistIterator>
-                                  <ForVarIterator varname="$$opt_temp_0"/>
+                                  <LetVarIterator varname="$$opt_temp_1"/>
                                 </UnhoistIterator>
-                                <CompareIterator>
-                                  <FnDataIterator>
-                                    <LetVarIterator varname="file"/>
-                                  </FnDataIterator>
-                                  <SingletonIterator value="xs:string(ic1980)"/>
-                                </CompareIterator>
-                              </AndIterator>
-                              <UnhoistIterator>
-                                <LetVarIterator varname="$$opt_temp_1"/>
-                              </UnhoistIterator>
-                              <FnConcatIterator/>
-                            </IfThenElseIterator>
-                          </EnclosedIterator>
-                        </ElementIterator>
-                      </ReturnClause>
-                    </FLWORIterator>
-                  </EnclosedIterator>
-                </ElementIterator>
-              </ReturnClause>
-            </FLWORIterator>
-          </EnclosedIterator>
-        </ElementIterator>
-      </ReturnClause>
-    </FLWORIterator>
-  </EnclosedIterator>
-</ElementIterator>
-
+                                <FnConcatIterator/>
+                              </IfThenElseIterator>
+                            </EnclosedIterator>
+                          </ElementIterator>
+                        </ReturnClause>
+                      </FLWORIterator>
+                    </EnclosedIterator>
+                  </ElementIterator>
+                </ReturnClause>
+              </FLWORIterator>
+            </EnclosedIterator>
+          </ElementIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </EnclosedIterator>
+  </ElementIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/gflwor_02.iter'
--- test/iterplans/zorba/hashjoins/gflwor_02.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/gflwor_02.iter	2014-02-20 05:31:00 +0000
@@ -1,222 +1,222 @@
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="products">
-    <ElementIterator copyInputNodes="false">
-      <SingletonIterator value="xs:QName(,,products)"/>
-      <FnConcatIterator>
-        <ElementIterator copyInputNodes="false">
-          <SingletonIterator value="xs:QName(,,prod)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,id)">
-              <SingletonIterator value="xs:string(1)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,name)">
-              <SingletonIterator value="xs:string(car1)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,price)">
-              <SingletonIterator value="xs:string(10)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-        </ElementIterator>
-        <ElementIterator copyInputNodes="false">
-          <SingletonIterator value="xs:QName(,,prod)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,id)">
-              <SingletonIterator value="xs:string(2)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,name)">
-              <SingletonIterator value="xs:string(car2)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,price)">
-              <SingletonIterator value="xs:string(15)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-        </ElementIterator>
-        <ElementIterator copyInputNodes="false">
-          <SingletonIterator value="xs:QName(,,prod)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,id)">
-              <SingletonIterator value="xs:string(3)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,name)">
-              <SingletonIterator value="xs:string(car3)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,price)">
-              <SingletonIterator value="xs:string(9)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-        </ElementIterator>
-      </FnConcatIterator>
-    </ElementIterator>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="5" varname="sales">
-    <ElementIterator copyInputNodes="false">
-      <SingletonIterator value="xs:QName(,,sales)"/>
-      <FnConcatIterator>
-        <ElementIterator copyInputNodes="false">
-          <SingletonIterator value="xs:QName(,,sale)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,pid)">
-              <SingletonIterator value="xs:string(3)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,qty)">
-              <SingletonIterator value="xs:string(3)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,date)">
-              <SingletonIterator value="xs:string(2013-01-01)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-        </ElementIterator>
-        <ElementIterator copyInputNodes="false">
-          <SingletonIterator value="xs:QName(,,sale)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,pid)">
-              <SingletonIterator value="xs:string(3)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,qty)">
-              <SingletonIterator value="xs:string(5)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,date)">
-              <SingletonIterator value="xs:string(2013-01-02)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-        </ElementIterator>
-        <ElementIterator copyInputNodes="false">
-          <SingletonIterator value="xs:QName(,,sale)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,pid)">
-              <SingletonIterator value="xs:string(2)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,qty)">
-              <SingletonIterator value="xs:string(1)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,date)">
-              <SingletonIterator value="xs:string(2013-01-01)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-        </ElementIterator>
-      </FnConcatIterator>
-    </ElementIterator>
-  </CtxVarDeclareIterator>
-  <TupleStreamIterator>
-    <ForIterator>
-      <ForVariable name="s"/>
-      <WhereIterator>
-        <ForIterator>
-          <ForVariable name="$$opt_temp_1"/>
-          <LetIterator>
-            <LetVariable name="$$opt_temp_2" materialize="true"/>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <CtxVarDeclareIterator varid="4" varname="products">
+      <ElementIterator copyInputNodes="false">
+        <SingletonIterator value="xs:QName(,,products)"/>
+        <FnConcatIterator>
+          <ElementIterator copyInputNodes="false">
+            <SingletonIterator value="xs:QName(,,prod)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,id)">
+                <SingletonIterator value="xs:string(1)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,name)">
+                <SingletonIterator value="xs:string(car1)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,price)">
+                <SingletonIterator value="xs:string(10)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+          </ElementIterator>
+          <ElementIterator copyInputNodes="false">
+            <SingletonIterator value="xs:QName(,,prod)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,id)">
+                <SingletonIterator value="xs:string(2)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,name)">
+                <SingletonIterator value="xs:string(car2)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,price)">
+                <SingletonIterator value="xs:string(15)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+          </ElementIterator>
+          <ElementIterator copyInputNodes="false">
+            <SingletonIterator value="xs:QName(,,prod)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,id)">
+                <SingletonIterator value="xs:string(3)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,name)">
+                <SingletonIterator value="xs:string(car3)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,price)">
+                <SingletonIterator value="xs:string(9)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+          </ElementIterator>
+        </FnConcatIterator>
+      </ElementIterator>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="5" varname="sales">
+      <ElementIterator copyInputNodes="false">
+        <SingletonIterator value="xs:QName(,,sales)"/>
+        <FnConcatIterator>
+          <ElementIterator copyInputNodes="false">
+            <SingletonIterator value="xs:QName(,,sale)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,pid)">
+                <SingletonIterator value="xs:string(3)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,qty)">
+                <SingletonIterator value="xs:string(3)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,date)">
+                <SingletonIterator value="xs:string(2013-01-01)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+          </ElementIterator>
+          <ElementIterator copyInputNodes="false">
+            <SingletonIterator value="xs:QName(,,sale)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,pid)">
+                <SingletonIterator value="xs:string(3)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,qty)">
+                <SingletonIterator value="xs:string(5)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,date)">
+                <SingletonIterator value="xs:string(2013-01-02)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+          </ElementIterator>
+          <ElementIterator copyInputNodes="false">
+            <SingletonIterator value="xs:QName(,,sale)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,pid)">
+                <SingletonIterator value="xs:string(2)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,qty)">
+                <SingletonIterator value="xs:string(1)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,date)">
+                <SingletonIterator value="xs:string(2013-01-01)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+          </ElementIterator>
+        </FnConcatIterator>
+      </ElementIterator>
+    </CtxVarDeclareIterator>
+    <TupleStreamIterator>
+      <ForIterator>
+        <ForVariable name="s"/>
+        <WhereIterator>
+          <ForIterator>
+            <ForVariable name="$$opt_temp_1"/>
             <LetIterator>
-              <LetVariable name="$$opt_temp_3" materialize="true"/>
-              <ForIterator>
-                <ForVariable name="p"/>
-                <LetIterator>
-                  <LetVariable name="$$opt_temp_6" materialize="true"/>
+              <LetVariable name="$$opt_temp_2" materialize="true"/>
+              <LetIterator>
+                <LetVariable name="$$opt_temp_3" materialize="true"/>
+                <ForIterator>
+                  <ForVariable name="p"/>
                   <LetIterator>
-                    <LetVariable name="$$opt_temp_0" materialize="true"/>
-                    <TupleSourceIterator/>
-                    <HoistIterator>
-                      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,sale)" typename="*" nill allowed="0">
-                        <CtxVarIterator varid="5" varname="sales" varkind="global"/>
-                      </ChildAxisIterator>
-                    </HoistIterator>
+                    <LetVariable name="$$opt_temp_6" materialize="true"/>
+                    <LetIterator>
+                      <LetVariable name="$$opt_temp_0" materialize="true"/>
+                      <TupleSourceIterator/>
+                      <HoistIterator>
+                        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,sale)" typename="*" nill allowed="0">
+                          <CtxVarIterator varid="5" varname="sales" varkind="global"/>
+                        </ChildAxisIterator>
+                      </HoistIterator>
+                    </LetIterator>
+                    <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+                      <FLWORIterator>
+                        <ForVariable name="$$opt_temp_4">
+                          <UnhoistIterator>
+                            <LetVarIterator varname="$$opt_temp_0"/>
+                          </UnhoistIterator>
+                        </ForVariable>
+                        <ReturnClause>
+                          <ValueIndexEntryBuilderIterator>
+                            <ForVarIterator varname="$$opt_temp_4"/>
+                            <FnStringIterator>
+                              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,pid)" typename="*" nill allowed="0">
+                                <ForVarIterator varname="$$opt_temp_4"/>
+                              </AttributeAxisIterator>
+                            </FnStringIterator>
+                          </ValueIndexEntryBuilderIterator>
+                        </ReturnClause>
+                      </FLWORIterator>
+                    </CreateInternalIndexIterator>
                   </LetIterator>
-                  <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-                    <FLWORIterator>
-                      <ForVariable name="$$opt_temp_4">
-                        <UnhoistIterator>
-                          <LetVarIterator varname="$$opt_temp_0"/>
-                        </UnhoistIterator>
-                      </ForVariable>
-                      <ReturnClause>
-                        <ValueIndexEntryBuilderIterator>
-                          <ForVarIterator varname="$$opt_temp_4"/>
-                          <FnStringIterator>
-                            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,pid)" typename="*" nill allowed="0">
-                              <ForVarIterator varname="$$opt_temp_4"/>
-                            </AttributeAxisIterator>
-                          </FnStringIterator>
-                        </ValueIndexEntryBuilderIterator>
-                      </ReturnClause>
-                    </FLWORIterator>
-                  </CreateInternalIndexIterator>
-                </LetIterator>
-                <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,prod)" typename="*" nill allowed="0">
-                  <CtxVarIterator varid="4" varname="products" varkind="global"/>
-                </ChildAxisIterator>
-              </ForIterator>
+                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,prod)" typename="*" nill allowed="0">
+                    <CtxVarIterator varid="4" varname="products" varkind="global"/>
+                  </ChildAxisIterator>
+                </ForIterator>
+                <HoistIterator>
+                  <PromoteIterator type="xs:anyAtomicType">
+                    <FnDataIterator>
+                      <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,price)" typename="*" nill allowed="0">
+                        <ForVarIterator varname="p"/>
+                      </AttributeAxisIterator>
+                    </FnDataIterator>
+                  </PromoteIterator>
+                </HoistIterator>
+              </LetIterator>
               <HoistIterator>
-                <PromoteIterator type="xs:anyAtomicType">
-                  <FnDataIterator>
-                    <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,price)" typename="*" nill allowed="0">
-                      <ForVarIterator varname="p"/>
-                    </AttributeAxisIterator>
-                  </FnDataIterator>
-                </PromoteIterator>
+                <FnDataIterator>
+                  <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
+                    <ForVarIterator varname="p"/>
+                  </AttributeAxisIterator>
+                </FnDataIterator>
               </HoistIterator>
             </LetIterator>
             <HoistIterator>
+              <FnStringIterator>
+                <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+                  <ForVarIterator varname="p"/>
+                </AttributeAxisIterator>
+              </FnStringIterator>
+            </HoistIterator>
+          </ForIterator>
+          <CompareIterator>
+            <CastIterator type="xs:integer">
               <FnDataIterator>
-                <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
+                <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,price)" typename="*" nill allowed="0">
                   <ForVarIterator varname="p"/>
                 </AttributeAxisIterator>
               </FnDataIterator>
-            </HoistIterator>
-          </LetIterator>
-          <HoistIterator>
-            <FnStringIterator>
-              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-                <ForVarIterator varname="p"/>
-              </AttributeAxisIterator>
-            </FnStringIterator>
-          </HoistIterator>
-        </ForIterator>
-        <CompareIterator>
-          <CastIterator type="xs:integer">
-            <FnDataIterator>
-              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,price)" typename="*" nill allowed="0">
-                <ForVarIterator varname="p"/>
-              </AttributeAxisIterator>
-            </FnDataIterator>
-          </CastIterator>
-          <SingletonIterator value="xs:integer(9)"/>
-        </CompareIterator>
-      </WhereIterator>
-      <ProbeIndexPointValueIterator>
-        <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-        <UnhoistIterator>
-          <ForVarIterator varname="$$opt_temp_1"/>
-        </UnhoistIterator>
-      </ProbeIndexPointValueIterator>
-    </ForIterator>
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,sale)"/>
-      <FnConcatIterator>
-        <AttributeIterator qname="xs:QName(,,prod)">
-          <EnclosedIterator attr_cont="true">
-            <UnhoistIterator>
-              <LetVarIterator varname="$$opt_temp_2"/>
-            </UnhoistIterator>
-          </EnclosedIterator>
-        </AttributeIterator>
-        <AttributeIterator qname="xs:QName(,,amount)">
-          <EnclosedIterator attr_cont="true">
-            <GenericArithIterator_MultiplyOperation>
+            </CastIterator>
+            <SingletonIterator value="xs:integer(9)"/>
+          </CompareIterator>
+        </WhereIterator>
+        <ProbeIndexPointValueIterator>
+          <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+          <UnhoistIterator>
+            <ForVarIterator varname="$$opt_temp_1"/>
+          </UnhoistIterator>
+        </ProbeIndexPointValueIterator>
+      </ForIterator>
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,sale)"/>
+        <FnConcatIterator>
+          <AttributeIterator qname="xs:QName(,,prod)">
+            <EnclosedIterator attr_cont="true">
               <UnhoistIterator>
-                <LetVarIterator varname="$$opt_temp_3"/>
+                <LetVarIterator varname="$$opt_temp_2"/>
               </UnhoistIterator>
-              <PromoteIterator type="xs:anyAtomicType">
-                <FnDataIterator>
-                  <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,qty)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="s"/>
-                  </AttributeAxisIterator>
-                </FnDataIterator>
-              </PromoteIterator>
-            </GenericArithIterator_MultiplyOperation>
-          </EnclosedIterator>
-        </AttributeIterator>
-      </FnConcatIterator>
-    </ElementIterator>
-  </TupleStreamIterator>
-</SequentialIterator>
-
+            </EnclosedIterator>
+          </AttributeIterator>
+          <AttributeIterator qname="xs:QName(,,amount)">
+            <EnclosedIterator attr_cont="true">
+              <GenericArithIterator_MultiplyOperation>
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_3"/>
+                </UnhoistIterator>
+                <PromoteIterator type="xs:anyAtomicType">
+                  <FnDataIterator>
+                    <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,qty)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="s"/>
+                    </AttributeAxisIterator>
+                  </FnDataIterator>
+                </PromoteIterator>
+              </GenericArithIterator_MultiplyOperation>
+            </EnclosedIterator>
+          </AttributeIterator>
+        </FnConcatIterator>
+      </ElementIterator>
+    </TupleStreamIterator>
+  </SequentialIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/gflwor_03.iter'
--- test/iterplans/zorba/hashjoins/gflwor_03.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/gflwor_03.iter	2014-02-20 05:31:00 +0000
@@ -1,200 +1,200 @@
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="sales">
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,sales)"/>
-      <FnConcatIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,sale)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,pid)">
-              <SingletonIterator value="xs:string(3)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,locid)">
-              <SingletonIterator value="xs:string(5)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,qty)">
-              <SingletonIterator value="xs:string(3)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,date)">
-              <SingletonIterator value="xs:string(2013-01-01)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-        </ElementIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,sale)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,pid)">
-              <SingletonIterator value="xs:string(3)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,locid)">
-              <SingletonIterator value="xs:string(5)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,qty)">
-              <SingletonIterator value="xs:string(5)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,date)">
-              <SingletonIterator value="xs:string(2013-01-02)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-        </ElementIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,sale)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,pid)">
-              <SingletonIterator value="xs:string(2)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,locid)">
-              <SingletonIterator value="xs:string(4)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,qty)">
-              <SingletonIterator value="xs:string(1)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,date)">
-              <SingletonIterator value="xs:string(2013-01-01)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-        </ElementIterator>
-      </FnConcatIterator>
-    </ElementIterator>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="5" varname="locations">
-    <ElementIterator copyInputNodes="false">
-      <SingletonIterator value="xs:QName(,,locations)"/>
-      <FnConcatIterator>
-        <ElementIterator copyInputNodes="false">
-          <SingletonIterator value="xs:QName(,,loc)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,id)">
-              <SingletonIterator value="xs:string(5)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,city)">
-              <SingletonIterator value="xs:string(paris)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-        </ElementIterator>
-        <ElementIterator copyInputNodes="false">
-          <SingletonIterator value="xs:QName(,,loc)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,id)">
-              <SingletonIterator value="xs:string(4)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,city)">
-              <SingletonIterator value="xs:string(san fransisco)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-        </ElementIterator>
-      </FnConcatIterator>
-    </ElementIterator>
-  </CtxVarDeclareIterator>
-  <TupleStreamIterator>
-    <ForIterator>
-      <ForVariable name="$$opt_temp_1"/>
-      <GroupByIterator>
-        <ForIterator>
-          <ForVariable name="s"/>
-          <LetIterator>
-            <LetVariable name="$$opt_temp_4" materialize="true"/>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <CtxVarDeclareIterator varid="4" varname="sales">
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,sales)"/>
+        <FnConcatIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,sale)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,pid)">
+                <SingletonIterator value="xs:string(3)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,locid)">
+                <SingletonIterator value="xs:string(5)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,qty)">
+                <SingletonIterator value="xs:string(3)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,date)">
+                <SingletonIterator value="xs:string(2013-01-01)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+          </ElementIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,sale)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,pid)">
+                <SingletonIterator value="xs:string(3)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,locid)">
+                <SingletonIterator value="xs:string(5)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,qty)">
+                <SingletonIterator value="xs:string(5)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,date)">
+                <SingletonIterator value="xs:string(2013-01-02)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+          </ElementIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,sale)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,pid)">
+                <SingletonIterator value="xs:string(2)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,locid)">
+                <SingletonIterator value="xs:string(4)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,qty)">
+                <SingletonIterator value="xs:string(1)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,date)">
+                <SingletonIterator value="xs:string(2013-01-01)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+          </ElementIterator>
+        </FnConcatIterator>
+      </ElementIterator>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="5" varname="locations">
+      <ElementIterator copyInputNodes="false">
+        <SingletonIterator value="xs:QName(,,locations)"/>
+        <FnConcatIterator>
+          <ElementIterator copyInputNodes="false">
+            <SingletonIterator value="xs:QName(,,loc)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,id)">
+                <SingletonIterator value="xs:string(5)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,city)">
+                <SingletonIterator value="xs:string(paris)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+          </ElementIterator>
+          <ElementIterator copyInputNodes="false">
+            <SingletonIterator value="xs:QName(,,loc)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,id)">
+                <SingletonIterator value="xs:string(4)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,city)">
+                <SingletonIterator value="xs:string(san fransisco)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+          </ElementIterator>
+        </FnConcatIterator>
+      </ElementIterator>
+    </CtxVarDeclareIterator>
+    <TupleStreamIterator>
+      <ForIterator>
+        <ForVariable name="$$opt_temp_1"/>
+        <GroupByIterator>
+          <ForIterator>
+            <ForVariable name="s"/>
             <LetIterator>
-              <LetVariable name="$$opt_temp_0" materialize="true"/>
-              <TupleSourceIterator/>
-              <HoistIterator>
-                <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,loc)" typename="*" nill allowed="0">
-                  <CtxVarIterator varid="5" varname="locations" varkind="global"/>
-                </ChildAxisIterator>
-              </HoistIterator>
-            </LetIterator>
-            <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-              <FLWORIterator>
-                <ForVariable name="$$opt_temp_2">
-                  <UnhoistIterator>
-                    <LetVarIterator varname="$$opt_temp_0"/>
-                  </UnhoistIterator>
-                </ForVariable>
-                <ReturnClause>
-                  <ValueIndexEntryBuilderIterator>
-                    <ForVarIterator varname="$$opt_temp_2"/>
-                    <FnStringIterator>
-                      <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-                        <ForVarIterator varname="$$opt_temp_2"/>
-                      </AttributeAxisIterator>
-                    </FnStringIterator>
-                  </ValueIndexEntryBuilderIterator>
-                </ReturnClause>
-              </FLWORIterator>
-            </CreateInternalIndexIterator>
-          </LetIterator>
-          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,sale)" typename="*" nill allowed="0">
-            <CtxVarIterator varid="4" varname="sales" varkind="global"/>
-          </ChildAxisIterator>
-        </ForIterator>
-        <Spec>
-          <TreatIterator quant="?">
-            <FnDataIterator>
-              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,locid)" typename="*" nill allowed="0">
-                <ForVarIterator varname="s"/>
-              </AttributeAxisIterator>
-            </FnDataIterator>
-          </TreatIterator>
-          <GroupVariable/>
-        </Spec>
-        <Spec>
-          <ForVarIterator varname="s"/>
-          <NonGroupVariable/>
-        </Spec>
-      </GroupByIterator>
-      <HoistIterator>
-        <FnStringIterator>
-          <ForVarIterator varname="loc"/>
-        </FnStringIterator>
-      </HoistIterator>
-    </ForIterator>
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,sale)"/>
-      <FnConcatIterator>
-        <AttributeIterator qname="xs:QName(,,city)">
-          <EnclosedIterator attr_cont="true">
-            <FnDataIterator>
-              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,city)" typename="*" nill allowed="0">
+              <LetVariable name="$$opt_temp_4" materialize="true"/>
+              <LetIterator>
+                <LetVariable name="$$opt_temp_0" materialize="true"/>
+                <TupleSourceIterator/>
+                <HoistIterator>
+                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,loc)" typename="*" nill allowed="0">
+                    <CtxVarIterator varid="5" varname="locations" varkind="global"/>
+                  </ChildAxisIterator>
+                </HoistIterator>
+              </LetIterator>
+              <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
                 <FLWORIterator>
-                  <ForVariable name="$$context-item">
-                    <ProbeIndexPointValueIterator>
-                      <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-                      <UnhoistIterator>
-                        <ForVarIterator varname="$$opt_temp_1"/>
-                      </UnhoistIterator>
-                    </ProbeIndexPointValueIterator>
+                  <ForVariable name="$$opt_temp_2">
+                    <UnhoistIterator>
+                      <LetVarIterator varname="$$opt_temp_0"/>
+                    </UnhoistIterator>
                   </ForVariable>
                   <ReturnClause>
-                    <ForVarIterator varname="$$context-item"/>
+                    <ValueIndexEntryBuilderIterator>
+                      <ForVarIterator varname="$$opt_temp_2"/>
+                      <FnStringIterator>
+                        <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+                          <ForVarIterator varname="$$opt_temp_2"/>
+                        </AttributeAxisIterator>
+                      </FnStringIterator>
+                    </ValueIndexEntryBuilderIterator>
                   </ReturnClause>
                 </FLWORIterator>
-              </AttributeAxisIterator>
-            </FnDataIterator>
-          </EnclosedIterator>
-        </AttributeIterator>
-        <AttributeIterator qname="xs:QName(,,qty)">
-          <EnclosedIterator attr_cont="true">
-            <FnSumIterator>
-              <FnDataIterator>
-                <NodeDistinctIterator allow-atomics="false" check-only="false">
-                  <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,qty)" typename="*" nill allowed="0">
-                    <LetVarIterator varname="s"/>
-                  </AttributeAxisIterator>
-                </NodeDistinctIterator>
-              </FnDataIterator>
-            </FnSumIterator>
-          </EnclosedIterator>
-        </AttributeIterator>
-      </FnConcatIterator>
-    </ElementIterator>
-  </TupleStreamIterator>
-</SequentialIterator>
-
+              </CreateInternalIndexIterator>
+            </LetIterator>
+            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,sale)" typename="*" nill allowed="0">
+              <CtxVarIterator varid="4" varname="sales" varkind="global"/>
+            </ChildAxisIterator>
+          </ForIterator>
+          <Spec>
+            <TreatIterator quant="?">
+              <FnDataIterator>
+                <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,locid)" typename="*" nill allowed="0">
+                  <ForVarIterator varname="s"/>
+                </AttributeAxisIterator>
+              </FnDataIterator>
+            </TreatIterator>
+            <GroupVariable/>
+          </Spec>
+          <Spec>
+            <ForVarIterator varname="s"/>
+            <NonGroupVariable/>
+          </Spec>
+        </GroupByIterator>
+        <HoistIterator>
+          <FnStringIterator>
+            <ForVarIterator varname="loc"/>
+          </FnStringIterator>
+        </HoistIterator>
+      </ForIterator>
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,sale)"/>
+        <FnConcatIterator>
+          <AttributeIterator qname="xs:QName(,,city)">
+            <EnclosedIterator attr_cont="true">
+              <FnDataIterator>
+                <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,city)" typename="*" nill allowed="0">
+                  <FLWORIterator>
+                    <ForVariable name="$$context-item">
+                      <ProbeIndexPointValueIterator>
+                        <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+                        <UnhoistIterator>
+                          <ForVarIterator varname="$$opt_temp_1"/>
+                        </UnhoistIterator>
+                      </ProbeIndexPointValueIterator>
+                    </ForVariable>
+                    <ReturnClause>
+                      <ForVarIterator varname="$$context-item"/>
+                    </ReturnClause>
+                  </FLWORIterator>
+                </AttributeAxisIterator>
+              </FnDataIterator>
+            </EnclosedIterator>
+          </AttributeIterator>
+          <AttributeIterator qname="xs:QName(,,qty)">
+            <EnclosedIterator attr_cont="true">
+              <FnSumIterator>
+                <FnDataIterator>
+                  <NodeDistinctIterator allow-atomics="false" check-only="false">
+                    <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,qty)" typename="*" nill allowed="0">
+                      <LetVarIterator varname="s"/>
+                    </AttributeAxisIterator>
+                  </NodeDistinctIterator>
+                </FnDataIterator>
+              </FnSumIterator>
+            </EnclosedIterator>
+          </AttributeIterator>
+        </FnConcatIterator>
+      </ElementIterator>
+    </TupleStreamIterator>
+  </SequentialIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/gflwor_04.iter'
--- test/iterplans/zorba/hashjoins/gflwor_04.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/gflwor_04.iter	2014-02-20 05:31:00 +0000
@@ -1,126 +1,126 @@
-Iterator tree for main query:
-<TupleStreamIterator>
-  <LetIterator>
-    <LetVariable name="y" materialize="true"/>
-    <CountIterator>
-      <LetIterator>
-        <LetVariable name="$$opt_temp_1" materialize="true"/>
-        <ForIterator>
-          <ForVariable name="x"/>
-          <LetIterator>
-            <LetVariable name="$$opt_temp_4" materialize="true"/>
+<iterator-tree description="main query">
+  <TupleStreamIterator>
+    <LetIterator>
+      <LetVariable name="y" materialize="true"/>
+      <CountIterator>
+        <LetIterator>
+          <LetVariable name="$$opt_temp_1" materialize="true"/>
+          <ForIterator>
+            <ForVariable name="x"/>
             <LetIterator>
-              <LetVariable name="$$opt_temp_0" materialize="true"/>
-              <ForIterator>
-                <ForVariable name="a"/>
-                <TupleSourceIterator/>
-                <FnConcatIterator>
-                  <SingletonIterator value="xs:integer(1)"/>
-                  <SingletonIterator value="xs:integer(2)"/>
-                </FnConcatIterator>
-              </ForIterator>
-              <HoistIterator>
-                <UDFunctionCallIterator function="local:foo">
-                  <ForVarIterator varname="a"/>
-                </UDFunctionCallIterator>
-              </HoistIterator>
+              <LetVariable name="$$opt_temp_4" materialize="true"/>
+              <LetIterator>
+                <LetVariable name="$$opt_temp_0" materialize="true"/>
+                <ForIterator>
+                  <ForVariable name="a"/>
+                  <TupleSourceIterator/>
+                  <FnConcatIterator>
+                    <SingletonIterator value="xs:integer(1)"/>
+                    <SingletonIterator value="xs:integer(2)"/>
+                  </FnConcatIterator>
+                </ForIterator>
+                <HoistIterator>
+                  <UDFunctionCallIterator function="local:foo">
+                    <ForVarIterator varname="a"/>
+                  </UDFunctionCallIterator>
+                </HoistIterator>
+              </LetIterator>
+              <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+                <FLWORIterator>
+                  <ForVariable name="$$opt_temp_2">
+                    <UnhoistIterator>
+                      <LetVarIterator varname="$$opt_temp_0"/>
+                    </UnhoistIterator>
+                  </ForVariable>
+                  <ReturnClause>
+                    <ValueIndexEntryBuilderIterator>
+                      <ForVarIterator varname="$$opt_temp_2"/>
+                      <ForVarIterator varname="$$opt_temp_2"/>
+                    </ValueIndexEntryBuilderIterator>
+                  </ReturnClause>
+                </FLWORIterator>
+              </CreateInternalIndexIterator>
             </LetIterator>
-            <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-              <FLWORIterator>
-                <ForVariable name="$$opt_temp_2">
-                  <UnhoistIterator>
-                    <LetVarIterator varname="$$opt_temp_0"/>
-                  </UnhoistIterator>
-                </ForVariable>
-                <ReturnClause>
-                  <ValueIndexEntryBuilderIterator>
-                    <ForVarIterator varname="$$opt_temp_2"/>
-                    <ForVarIterator varname="$$opt_temp_2"/>
-                  </ValueIndexEntryBuilderIterator>
-                </ReturnClause>
-              </FLWORIterator>
-            </CreateInternalIndexIterator>
-          </LetIterator>
+            <FnConcatIterator>
+              <ElementIterator>
+                <SingletonIterator value="xs:QName(,,a)"/>
+                <TextIterator>
+                  <SingletonIterator value="xs:string(1)"/>
+                </TextIterator>
+              </ElementIterator>
+              <ElementIterator>
+                <SingletonIterator value="xs:QName(,,a)"/>
+                <TextIterator>
+                  <SingletonIterator value="xs:string(2)"/>
+                </TextIterator>
+              </ElementIterator>
+              <ElementIterator>
+                <SingletonIterator value="xs:QName(,,a)"/>
+                <TextIterator>
+                  <SingletonIterator value="xs:string(3)"/>
+                </TextIterator>
+              </ElementIterator>
+            </FnConcatIterator>
+          </ForIterator>
+          <HoistIterator>
+            <CastIterator type="xs:integer">
+              <FnDataIterator>
+                <ForVarIterator varname="x"/>
+              </FnDataIterator>
+            </CastIterator>
+          </HoistIterator>
+        </LetIterator>
+      </CountIterator>
+      <FLWORIterator>
+        <ForVariable name="z">
+          <ProbeIndexPointValueIterator>
+            <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_1"/>
+            </UnhoistIterator>
+          </ProbeIndexPointValueIterator>
+        </ForVariable>
+        <ReturnClause>
+          <ForVarIterator varname="z"/>
+        </ReturnClause>
+      </FLWORIterator>
+    </LetIterator>
+    <FnConcatIterator>
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,res)"/>
+        <EnclosedIterator attr_cont="false">
           <FnConcatIterator>
-            <ElementIterator>
-              <SingletonIterator value="xs:QName(,,a)"/>
-              <TextIterator>
-                <SingletonIterator value="xs:string(1)"/>
-              </TextIterator>
-            </ElementIterator>
-            <ElementIterator>
-              <SingletonIterator value="xs:QName(,,a)"/>
-              <TextIterator>
-                <SingletonIterator value="xs:string(2)"/>
-              </TextIterator>
-            </ElementIterator>
-            <ElementIterator>
-              <SingletonIterator value="xs:QName(,,a)"/>
-              <TextIterator>
-                <SingletonIterator value="xs:string(3)"/>
-              </TextIterator>
-            </ElementIterator>
+            <ForVarIterator varname="x"/>
+            <ForVarIterator varname="w"/>
+            <FnCountIterator>
+              <LetVarIterator varname="y"/>
+            </FnCountIterator>
+            <FnSumIntegerIterator>
+              <LetVarIterator varname="y"/>
+            </FnSumIntegerIterator>
           </FnConcatIterator>
-        </ForIterator>
-        <HoistIterator>
-          <CastIterator type="xs:integer">
-            <FnDataIterator>
-              <ForVarIterator varname="x"/>
-            </FnDataIterator>
-          </CastIterator>
-        </HoistIterator>
-      </LetIterator>
-    </CountIterator>
-    <FLWORIterator>
-      <ForVariable name="z">
-        <ProbeIndexPointValueIterator>
-          <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-          <UnhoistIterator>
-            <LetVarIterator varname="$$opt_temp_1"/>
-          </UnhoistIterator>
-        </ProbeIndexPointValueIterator>
-      </ForVariable>
-      <ReturnClause>
-        <ForVarIterator varname="z"/>
-      </ReturnClause>
-    </FLWORIterator>
-  </LetIterator>
-  <FnConcatIterator>
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,res)"/>
-      <EnclosedIterator attr_cont="false">
-        <FnConcatIterator>
-          <ForVarIterator varname="x"/>
-          <ForVarIterator varname="w"/>
-          <FnCountIterator>
-            <LetVarIterator varname="y"/>
-          </FnCountIterator>
-          <FnSumIntegerIterator>
-            <LetVarIterator varname="y"/>
-          </FnSumIntegerIterator>
-        </FnConcatIterator>
-      </EnclosedIterator>
-    </ElementIterator>
-    <SingletonIterator value="xs:string(
+        </EnclosedIterator>
+      </ElementIterator>
+      <SingletonIterator value="xs:string(
 )"/>
-  </FnConcatIterator>
-</TupleStreamIterator>
-
-Iterator tree for local:foo:
-<FLWORIterator>
-  <ForVariable name="x">
-    <LetVarIterator varname="x"/>
-  </ForVariable>
-  <ReturnClause>
-    <FnConcatIterator>
-      <SpecificNumArithIterator_MultiplyOperation_INTEGER>
-        <ForVarIterator varname="x"/>
-        <ForVarIterator varname="x"/>
-      </SpecificNumArithIterator_MultiplyOperation_INTEGER>
-      <FunctionTraceIterator>
-        <ForVarIterator varname="x"/>
-      </FunctionTraceIterator>
     </FnConcatIterator>
-  </ReturnClause>
-</FLWORIterator>
-
+  </TupleStreamIterator>
+</iterator-tree>
+<iterator-tree description="local:foo">
+  <FLWORIterator>
+    <ForVariable name="x">
+      <LetVarIterator varname="x"/>
+    </ForVariable>
+    <ReturnClause>
+      <FnConcatIterator>
+        <SpecificNumArithIterator_MultiplyOperation_INTEGER>
+          <ForVarIterator varname="x"/>
+          <ForVarIterator varname="x"/>
+        </SpecificNumArithIterator_MultiplyOperation_INTEGER>
+        <FunctionTraceIterator>
+          <ForVarIterator varname="x"/>
+        </FunctionTraceIterator>
+      </FnConcatIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/gflwor_05.iter'
--- test/iterplans/zorba/hashjoins/gflwor_05.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/gflwor_05.iter	2014-02-20 05:31:00 +0000
@@ -1,129 +1,129 @@
-Iterator tree for main query:
-<FLWORIterator>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <LetVariable name="$$opt_temp_0" materialize="true">
+      <HoistIterator>
+        <FnConcatIterator>
+          <SingletonIterator value="xs:integer(1)"/>
+          <SingletonIterator value="xs:integer(2)"/>
+          <SingletonIterator value="xs:integer(3)"/>
+        </FnConcatIterator>
+      </HoistIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_4" materialize="true">
+      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+        <FLWORIterator>
+          <ForVariable name="$$opt_temp_2">
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_0"/>
+            </UnhoistIterator>
+          </ForVariable>
+          <ReturnClause>
+            <ValueIndexEntryBuilderIterator>
+              <ForVarIterator varname="$$opt_temp_2"/>
+              <ForVarIterator varname="$$opt_temp_2"/>
+            </ValueIndexEntryBuilderIterator>
+          </ReturnClause>
+        </FLWORIterator>
+      </CreateInternalIndexIterator>
+    </LetVariable>
+    <ForVariable name="x">
       <FnConcatIterator>
-        <SingletonIterator value="xs:integer(1)"/>
-        <SingletonIterator value="xs:integer(2)"/>
-        <SingletonIterator value="xs:integer(3)"/>
+        <ElementIterator>
+          <SingletonIterator value="xs:QName(,,a)"/>
+          <TextIterator>
+            <SingletonIterator value="xs:string(1)"/>
+          </TextIterator>
+        </ElementIterator>
+        <ElementIterator>
+          <SingletonIterator value="xs:QName(,,a)"/>
+          <TextIterator>
+            <SingletonIterator value="xs:string(2)"/>
+          </TextIterator>
+        </ElementIterator>
+        <ElementIterator>
+          <SingletonIterator value="xs:QName(,,a)"/>
+          <TextIterator>
+            <SingletonIterator value="xs:string(3)"/>
+          </TextIterator>
+        </ElementIterator>
       </FnConcatIterator>
-    </HoistIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_4" materialize="true">
-    <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-      <FLWORIterator>
-        <ForVariable name="$$opt_temp_2">
-          <UnhoistIterator>
-            <LetVarIterator varname="$$opt_temp_0"/>
-          </UnhoistIterator>
-        </ForVariable>
-        <ReturnClause>
-          <ValueIndexEntryBuilderIterator>
-            <ForVarIterator varname="$$opt_temp_2"/>
-            <ForVarIterator varname="$$opt_temp_2"/>
-          </ValueIndexEntryBuilderIterator>
-        </ReturnClause>
-      </FLWORIterator>
-    </CreateInternalIndexIterator>
-  </LetVariable>
-  <ForVariable name="x">
-    <FnConcatIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,a)"/>
-        <TextIterator>
-          <SingletonIterator value="xs:string(1)"/>
-        </TextIterator>
-      </ElementIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,a)"/>
-        <TextIterator>
-          <SingletonIterator value="xs:string(2)"/>
-        </TextIterator>
-      </ElementIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,a)"/>
-        <TextIterator>
-          <SingletonIterator value="xs:string(3)"/>
-        </TextIterator>
-      </ElementIterator>
-    </FnConcatIterator>
-  </ForVariable>
-  <LetVariable name="$$opt_temp_1" materialize="true">
-    <HoistIterator>
-      <CastIterator type="xs:integer">
-        <FnDataIterator>
-          <ForVarIterator varname="x"/>
-        </FnDataIterator>
-      </CastIterator>
-    </HoistIterator>
-  </LetVariable>
-  <LetVariable name="y" materialize="true">
-    <TupleStreamIterator>
-      <ForIterator>
-        <ForVariable name="w"/>
-        <GroupByIterator>
-          <ForIterator>
-            <ForVariable name="z"/>
-            <TupleSourceIterator/>
+    </ForVariable>
+    <LetVariable name="$$opt_temp_1" materialize="true">
+      <HoistIterator>
+        <CastIterator type="xs:integer">
+          <FnDataIterator>
+            <ForVarIterator varname="x"/>
+          </FnDataIterator>
+        </CastIterator>
+      </HoistIterator>
+    </LetVariable>
+    <LetVariable name="y" materialize="true">
+      <TupleStreamIterator>
+        <ForIterator>
+          <ForVariable name="w"/>
+          <GroupByIterator>
+            <ForIterator>
+              <ForVariable name="z"/>
+              <TupleSourceIterator/>
+              <FnConcatIterator>
+                <ElementIterator copyInputNodes="false">
+                  <SingletonIterator value="xs:QName(,,b)"/>
+                  <TextIterator>
+                    <SingletonIterator value="xs:string(1)"/>
+                  </TextIterator>
+                </ElementIterator>
+                <ElementIterator copyInputNodes="false">
+                  <SingletonIterator value="xs:QName(,,b)"/>
+                  <TextIterator>
+                    <SingletonIterator value="xs:string(2)"/>
+                  </TextIterator>
+                </ElementIterator>
+                <ElementIterator copyInputNodes="false">
+                  <SingletonIterator value="xs:QName(,,b)"/>
+                  <TextIterator>
+                    <SingletonIterator value="xs:string(2)"/>
+                  </TextIterator>
+                </ElementIterator>
+              </FnConcatIterator>
+            </ForIterator>
+            <Spec>
+              <TreatIterator quant="?">
+                <FnDataIterator>
+                  <ForVarIterator varname="z"/>
+                </FnDataIterator>
+              </TreatIterator>
+              <GroupVariable/>
+            </Spec>
+          </GroupByIterator>
+          <ProbeIndexPointValueIterator>
+            <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_1"/>
+            </UnhoistIterator>
+          </ProbeIndexPointValueIterator>
+        </ForIterator>
+        <ForVarIterator varname="w"/>
+      </TupleStreamIterator>
+    </LetVariable>
+    <ReturnClause>
+      <FnConcatIterator>
+        <ElementIterator>
+          <SingletonIterator value="xs:QName(,,res)"/>
+          <EnclosedIterator attr_cont="false">
             <FnConcatIterator>
-              <ElementIterator copyInputNodes="false">
-                <SingletonIterator value="xs:QName(,,b)"/>
-                <TextIterator>
-                  <SingletonIterator value="xs:string(1)"/>
-                </TextIterator>
-              </ElementIterator>
-              <ElementIterator copyInputNodes="false">
-                <SingletonIterator value="xs:QName(,,b)"/>
-                <TextIterator>
-                  <SingletonIterator value="xs:string(2)"/>
-                </TextIterator>
-              </ElementIterator>
-              <ElementIterator copyInputNodes="false">
-                <SingletonIterator value="xs:QName(,,b)"/>
-                <TextIterator>
-                  <SingletonIterator value="xs:string(2)"/>
-                </TextIterator>
-              </ElementIterator>
+              <ForVarIterator varname="x"/>
+              <FnCountIterator>
+                <LetVarIterator varname="y"/>
+              </FnCountIterator>
+              <FnSumIntegerIterator>
+                <LetVarIterator varname="y"/>
+              </FnSumIntegerIterator>
             </FnConcatIterator>
-          </ForIterator>
-          <Spec>
-            <TreatIterator quant="?">
-              <FnDataIterator>
-                <ForVarIterator varname="z"/>
-              </FnDataIterator>
-            </TreatIterator>
-            <GroupVariable/>
-          </Spec>
-        </GroupByIterator>
-        <ProbeIndexPointValueIterator>
-          <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-          <UnhoistIterator>
-            <LetVarIterator varname="$$opt_temp_1"/>
-          </UnhoistIterator>
-        </ProbeIndexPointValueIterator>
-      </ForIterator>
-      <ForVarIterator varname="w"/>
-    </TupleStreamIterator>
-  </LetVariable>
-  <ReturnClause>
-    <FnConcatIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,res)"/>
-        <EnclosedIterator attr_cont="false">
-          <FnConcatIterator>
-            <ForVarIterator varname="x"/>
-            <FnCountIterator>
-              <LetVarIterator varname="y"/>
-            </FnCountIterator>
-            <FnSumIntegerIterator>
-              <LetVarIterator varname="y"/>
-            </FnSumIntegerIterator>
-          </FnConcatIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-      <SingletonIterator value="xs:string(
+          </EnclosedIterator>
+        </ElementIterator>
+        <SingletonIterator value="xs:string(
 )"/>
-    </FnConcatIterator>
-  </ReturnClause>
-</FLWORIterator>
-
+      </FnConcatIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/idx1.iter'
--- test/iterplans/zorba/hashjoins/idx1.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/idx1.iter	2014-02-20 05:31:00 +0000
@@ -1,97 +1,97 @@
-Iterator tree for main query:
-<FLWORIterator>
-  <LetVariable name="auction" materialize="true">
-    <FnDocIterator>
-      <SingletonIterator value="xs:string(auction.xml)"/>
-    </FnDocIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
-      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auction)" typename="*" nill allowed="0">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auctions)" typename="*" nill allowed="0">
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <LetVariable name="auction" materialize="true">
+      <FnDocIterator>
+        <SingletonIterator value="xs:string(auction.xml)"/>
+      </FnDocIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_0" materialize="true">
+      <HoistIterator>
+        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auction)" typename="*" nill allowed="0">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auctions)" typename="*" nill allowed="0">
+            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
+              <LetVarIterator varname="auction"/>
+            </ChildAxisIterator>
+          </ChildAxisIterator>
+        </ChildAxisIterator>
+      </HoistIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_5" materialize="true">
+      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+        <FLWORIterator>
+          <ForVariable name="$$opt_temp_3">
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_0"/>
+            </UnhoistIterator>
+          </ForVariable>
+          <ReturnClause>
+            <ValueIndexEntryBuilderIterator>
+              <ForVarIterator varname="$$opt_temp_3"/>
+              <PromoteIterator type="xs:anyAtomicType">
+                <FnDataIterator>
+                  <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,buyer)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_3"/>
+                    </ChildAxisIterator>
+                  </AttributeAxisIterator>
+                </FnDataIterator>
+              </PromoteIterator>
+            </ValueIndexEntryBuilderIterator>
+          </ReturnClause>
+        </FLWORIterator>
+      </CreateInternalIndexIterator>
+    </LetVariable>
+    <ForVariable name="p">
+      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
+        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,people)" typename="*" nill allowed="0">
           <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
             <LetVarIterator varname="auction"/>
           </ChildAxisIterator>
         </ChildAxisIterator>
       </ChildAxisIterator>
-    </HoistIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_5" materialize="true">
-    <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-      <FLWORIterator>
-        <ForVariable name="$$opt_temp_3">
-          <UnhoistIterator>
-            <LetVarIterator varname="$$opt_temp_0"/>
-          </UnhoistIterator>
-        </ForVariable>
-        <ReturnClause>
-          <ValueIndexEntryBuilderIterator>
-            <ForVarIterator varname="$$opt_temp_3"/>
-            <PromoteIterator type="xs:anyAtomicType">
-              <FnDataIterator>
-                <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
-                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,buyer)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="$$opt_temp_3"/>
-                  </ChildAxisIterator>
-                </AttributeAxisIterator>
-              </FnDataIterator>
-            </PromoteIterator>
-          </ValueIndexEntryBuilderIterator>
-        </ReturnClause>
-      </FLWORIterator>
-    </CreateInternalIndexIterator>
-  </LetVariable>
-  <ForVariable name="p">
-    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
-      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,people)" typename="*" nill allowed="0">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
-          <LetVarIterator varname="auction"/>
-        </ChildAxisIterator>
-      </ChildAxisIterator>
-    </ChildAxisIterator>
-  </ForVariable>
-  <LetVariable name="$$opt_temp_2" materialize="true">
-    <HoistIterator>
-      <FnDataIterator>
-        <ChildAxisIterator test kind="match_text_test" qname="*" typename="*" nill allowed="0">
-          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
+    </ForVariable>
+    <LetVariable name="$$opt_temp_2" materialize="true">
+      <HoistIterator>
+        <FnDataIterator>
+          <ChildAxisIterator test kind="match_text_test" qname="*" typename="*" nill allowed="0">
+            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
+              <ForVarIterator varname="p"/>
+            </ChildAxisIterator>
+          </ChildAxisIterator>
+        </FnDataIterator>
+      </HoistIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_1" materialize="true">
+      <HoistIterator>
+        <FnDataIterator>
+          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
             <ForVarIterator varname="p"/>
-          </ChildAxisIterator>
-        </ChildAxisIterator>
-      </FnDataIterator>
-    </HoistIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_1" materialize="true">
-    <HoistIterator>
-      <FnDataIterator>
-        <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-          <ForVarIterator varname="p"/>
-        </AttributeAxisIterator>
-      </FnDataIterator>
-    </HoistIterator>
-  </LetVariable>
-  <ForVariable name="a">
-    <ProbeIndexPointValueIterator>
-      <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-      <UnhoistIterator>
-        <LetVarIterator varname="$$opt_temp_1"/>
-      </UnhoistIterator>
-    </ProbeIndexPointValueIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,item)"/>
-      <AttributeIterator qname="xs:QName(,,person)">
-        <EnclosedIterator attr_cont="true">
-          <UnhoistIterator>
-            <LetVarIterator varname="$$opt_temp_2"/>
-          </UnhoistIterator>
+          </AttributeAxisIterator>
+        </FnDataIterator>
+      </HoistIterator>
+    </LetVariable>
+    <ForVariable name="a">
+      <ProbeIndexPointValueIterator>
+        <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+        <UnhoistIterator>
+          <LetVarIterator varname="$$opt_temp_1"/>
+        </UnhoistIterator>
+      </ProbeIndexPointValueIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,item)"/>
+        <AttributeIterator qname="xs:QName(,,person)">
+          <EnclosedIterator attr_cont="true">
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_2"/>
+            </UnhoistIterator>
+          </EnclosedIterator>
+        </AttributeIterator>
+        <EnclosedIterator attr_cont="false">
+          <ForVarIterator varname="a"/>
         </EnclosedIterator>
-      </AttributeIterator>
-      <EnclosedIterator attr_cont="false">
-        <ForVarIterator varname="a"/>
-      </EnclosedIterator>
-    </ElementIterator>
-  </ReturnClause>
-</FLWORIterator>
-
+      </ElementIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/idx10.iter'
--- test/iterplans/zorba/hashjoins/idx10.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/idx10.iter	2014-02-20 05:31:00 +0000
@@ -1,130 +1,130 @@
-Iterator tree for main query:
-<FLWORIterator>
-  <ForVariable name="$$opt_temp_0">
-    <HoistIterator>
-      <ErrorIterator/>
-    </HoistIterator>
-  </ForVariable>
-  <LetVariable name="$$opt_temp_1" materialize="true">
-    <HoistIterator>
-      <OpToIterator>
-        <SingletonIterator value="xs:integer(1)"/>
-        <SingletonIterator value="xs:integer(10)"/>
-      </OpToIterator>
-    </HoistIterator>
-  </LetVariable>
-  <ReturnClause>
-    <TryCatchIterator>
-      <FLWORIterator>
-        <LetVariable name="$$opt_temp_5" materialize="true">
-          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-            <FLWORIterator>
-              <ForVariable name="$$opt_temp_3">
-                <NodeSortIterator distinct="true" ascending="true">
-                  <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-                    <FunctionTraceIterator>
-                      <FLWORIterator>
-                        <ForVariable name="$$opt_temp_0">
-                          <HoistIterator>
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <ForVariable name="$$opt_temp_0">
+      <HoistIterator>
+        <ErrorIterator/>
+      </HoistIterator>
+    </ForVariable>
+    <LetVariable name="$$opt_temp_1" materialize="true">
+      <HoistIterator>
+        <OpToIterator>
+          <SingletonIterator value="xs:integer(1)"/>
+          <SingletonIterator value="xs:integer(10)"/>
+        </OpToIterator>
+      </HoistIterator>
+    </LetVariable>
+    <ReturnClause>
+      <TryCatchIterator>
+        <FLWORIterator>
+          <LetVariable name="$$opt_temp_5" materialize="true">
+            <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+              <FLWORIterator>
+                <ForVariable name="$$opt_temp_3">
+                  <NodeSortIterator distinct="true" ascending="true">
+                    <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+                      <FunctionTraceIterator>
+                        <FLWORIterator>
+                          <ForVariable name="$$opt_temp_0">
+                            <HoistIterator>
+                              <UnhoistIterator>
+                                <ForVarIterator varname="$$opt_temp_0"/>
+                              </UnhoistIterator>
+                            </HoistIterator>
+                          </ForVariable>
+                          <ForVariable name="i">
                             <UnhoistIterator>
-                              <ForVarIterator varname="$$opt_temp_0"/>
+                              <LetVarIterator varname="$$opt_temp_1"/>
                             </UnhoistIterator>
-                          </HoistIterator>
-                        </ForVariable>
-                        <ForVariable name="i">
-                          <UnhoistIterator>
-                            <LetVarIterator varname="$$opt_temp_1"/>
-                          </UnhoistIterator>
-                        </ForVariable>
-                        <ReturnClause>
-                          <IfThenElseIterator>
-                            <TypedValueCompareIterator_INTEGER>
-                              <NumArithIterator_ModOperation>
-                                <ForVarIterator varname="i"/>
-                                <SingletonIterator value="xs:integer(2)"/>
-                              </NumArithIterator_ModOperation>
-                              <SingletonIterator value="xs:integer(0)"/>
-                            </TypedValueCompareIterator_INTEGER>
-                            <ElementIterator>
-                              <SingletonIterator value="xs:QName(,,a)"/>
-                              <AttributeIterator qname="xs:QName(,,id)">
-                                <EnclosedIterator attr_cont="true">
+                          </ForVariable>
+                          <ReturnClause>
+                            <IfThenElseIterator>
+                              <TypedValueCompareIterator_INTEGER>
+                                <NumArithIterator_ModOperation>
                                   <ForVarIterator varname="i"/>
-                                </EnclosedIterator>
-                              </AttributeIterator>
-                            </ElementIterator>
-                            <UnhoistIterator>
-                              <ForVarIterator varname="$$opt_temp_0"/>
-                            </UnhoistIterator>
-                          </IfThenElseIterator>
-                        </ReturnClause>
-                      </FLWORIterator>
-                    </FunctionTraceIterator>
-                  </AttributeAxisIterator>
-                </NodeSortIterator>
-              </ForVariable>
-              <ReturnClause>
-                <ValueIndexEntryBuilderIterator>
-                  <ForVarIterator varname="$$opt_temp_3"/>
-                  <CastIterator type="xs:string">
-                    <FnDataIterator>
-                      <ForVarIterator varname="$$opt_temp_3"/>
-                    </FnDataIterator>
-                  </CastIterator>
-                </ValueIndexEntryBuilderIterator>
-              </ReturnClause>
-            </FLWORIterator>
-          </CreateInternalIndexIterator>
-        </LetVariable>
-        <ForVariable name="i">
-          <NodeSortIterator distinct="true" ascending="true">
-            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-              <FunctionTraceIterator>
-                <FLWORIterator>
-                  <ForVariable name="i">
-                    <OpToIterator>
-                      <SingletonIterator value="xs:integer(1)"/>
-                      <SingletonIterator value="xs:integer(10)"/>
-                    </OpToIterator>
-                  </ForVariable>
-                  <ReturnClause>
-                    <ElementIterator>
-                      <SingletonIterator value="xs:QName(,,b)"/>
-                      <AttributeIterator qname="xs:QName(,,id)">
-                        <EnclosedIterator attr_cont="true">
-                          <ForVarIterator varname="i"/>
-                        </EnclosedIterator>
-                      </AttributeIterator>
-                    </ElementIterator>
-                  </ReturnClause>
-                </FLWORIterator>
-              </FunctionTraceIterator>
-            </AttributeAxisIterator>
-          </NodeSortIterator>
-        </ForVariable>
-        <LetVariable name="$$opt_temp_2" materialize="true">
-          <HoistIterator>
-            <CastIterator type="xs:string">
-              <FnDataIterator>
-                <ForVarIterator varname="i"/>
-              </FnDataIterator>
-            </CastIterator>
-          </HoistIterator>
-        </LetVariable>
-        <ForVariable name="j">
-          <ProbeIndexPointValueIterator>
-            <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-            <UnhoistIterator>
-              <LetVarIterator varname="$$opt_temp_2"/>
-            </UnhoistIterator>
-          </ProbeIndexPointValueIterator>
-        </ForVariable>
-        <ReturnClause>
-          <ForVarIterator varname="i"/>
-        </ReturnClause>
-      </FLWORIterator>
-      <SingletonIterator value="xs:string(caught)"/>
-    </TryCatchIterator>
-  </ReturnClause>
-</FLWORIterator>
-
+                                  <SingletonIterator value="xs:integer(2)"/>
+                                </NumArithIterator_ModOperation>
+                                <SingletonIterator value="xs:integer(0)"/>
+                              </TypedValueCompareIterator_INTEGER>
+                              <ElementIterator>
+                                <SingletonIterator value="xs:QName(,,a)"/>
+                                <AttributeIterator qname="xs:QName(,,id)">
+                                  <EnclosedIterator attr_cont="true">
+                                    <ForVarIterator varname="i"/>
+                                  </EnclosedIterator>
+                                </AttributeIterator>
+                              </ElementIterator>
+                              <UnhoistIterator>
+                                <ForVarIterator varname="$$opt_temp_0"/>
+                              </UnhoistIterator>
+                            </IfThenElseIterator>
+                          </ReturnClause>
+                        </FLWORIterator>
+                      </FunctionTraceIterator>
+                    </AttributeAxisIterator>
+                  </NodeSortIterator>
+                </ForVariable>
+                <ReturnClause>
+                  <ValueIndexEntryBuilderIterator>
+                    <ForVarIterator varname="$$opt_temp_3"/>
+                    <CastIterator type="xs:string">
+                      <FnDataIterator>
+                        <ForVarIterator varname="$$opt_temp_3"/>
+                      </FnDataIterator>
+                    </CastIterator>
+                  </ValueIndexEntryBuilderIterator>
+                </ReturnClause>
+              </FLWORIterator>
+            </CreateInternalIndexIterator>
+          </LetVariable>
+          <ForVariable name="i">
+            <NodeSortIterator distinct="true" ascending="true">
+              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+                <FunctionTraceIterator>
+                  <FLWORIterator>
+                    <ForVariable name="i">
+                      <OpToIterator>
+                        <SingletonIterator value="xs:integer(1)"/>
+                        <SingletonIterator value="xs:integer(10)"/>
+                      </OpToIterator>
+                    </ForVariable>
+                    <ReturnClause>
+                      <ElementIterator>
+                        <SingletonIterator value="xs:QName(,,b)"/>
+                        <AttributeIterator qname="xs:QName(,,id)">
+                          <EnclosedIterator attr_cont="true">
+                            <ForVarIterator varname="i"/>
+                          </EnclosedIterator>
+                        </AttributeIterator>
+                      </ElementIterator>
+                    </ReturnClause>
+                  </FLWORIterator>
+                </FunctionTraceIterator>
+              </AttributeAxisIterator>
+            </NodeSortIterator>
+          </ForVariable>
+          <LetVariable name="$$opt_temp_2" materialize="true">
+            <HoistIterator>
+              <CastIterator type="xs:string">
+                <FnDataIterator>
+                  <ForVarIterator varname="i"/>
+                </FnDataIterator>
+              </CastIterator>
+            </HoistIterator>
+          </LetVariable>
+          <ForVariable name="j">
+            <ProbeIndexPointValueIterator>
+              <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+              <UnhoistIterator>
+                <LetVarIterator varname="$$opt_temp_2"/>
+              </UnhoistIterator>
+            </ProbeIndexPointValueIterator>
+          </ForVariable>
+          <ReturnClause>
+            <ForVarIterator varname="i"/>
+          </ReturnClause>
+        </FLWORIterator>
+        <SingletonIterator value="xs:string(caught)"/>
+      </TryCatchIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/idx11.iter'
--- test/iterplans/zorba/hashjoins/idx11.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/idx11.iter	2014-02-20 05:31:00 +0000
@@ -1,82 +1,82 @@
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for main query:
-<FLWORIterator>
-  <LetVariable name="$$opt_temp_1" materialize="true">
-    <HoistIterator>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <LetVariable name="$$opt_temp_1" materialize="true">
+      <HoistIterator>
+        <FnConcatIterator>
+          <SingletonIterator value="xs:integer(1)"/>
+          <SingletonIterator value="xs:integer(2)"/>
+          <SingletonIterator value="xs:integer(2)"/>
+          <SingletonIterator value="xs:integer(3)"/>
+        </FnConcatIterator>
+      </HoistIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_5" materialize="true">
+      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+        <FLWORIterator>
+          <ForVariable name="$$opt_temp_3">
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_1"/>
+            </UnhoistIterator>
+          </ForVariable>
+          <ReturnClause>
+            <ValueIndexEntryBuilderIterator>
+              <ForVarIterator varname="$$opt_temp_3"/>
+              <ForVarIterator varname="$$opt_temp_3"/>
+            </ValueIndexEntryBuilderIterator>
+          </ReturnClause>
+        </FLWORIterator>
+      </CreateInternalIndexIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_0" materialize="true">
+      <HoistIterator>
+        <FnConcatIterator>
+          <SingletonIterator value="xs:integer(1)"/>
+          <SingletonIterator value="xs:integer(2)"/>
+        </FnConcatIterator>
+      </HoistIterator>
+    </LetVariable>
+    <ForVariable name="x">
       <FnConcatIterator>
         <SingletonIterator value="xs:integer(1)"/>
         <SingletonIterator value="xs:integer(2)"/>
-        <SingletonIterator value="xs:integer(2)"/>
         <SingletonIterator value="xs:integer(3)"/>
       </FnConcatIterator>
-    </HoistIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_5" materialize="true">
-    <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-      <FLWORIterator>
-        <ForVariable name="$$opt_temp_3">
-          <UnhoistIterator>
-            <LetVarIterator varname="$$opt_temp_1"/>
-          </UnhoistIterator>
-        </ForVariable>
-        <ReturnClause>
-          <ValueIndexEntryBuilderIterator>
-            <ForVarIterator varname="$$opt_temp_3"/>
-            <ForVarIterator varname="$$opt_temp_3"/>
-          </ValueIndexEntryBuilderIterator>
-        </ReturnClause>
-      </FLWORIterator>
-    </CreateInternalIndexIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
-      <FnConcatIterator>
-        <SingletonIterator value="xs:integer(1)"/>
-        <SingletonIterator value="xs:integer(2)"/>
-      </FnConcatIterator>
-    </HoistIterator>
-  </LetVariable>
-  <ForVariable name="x">
-    <FnConcatIterator>
-      <SingletonIterator value="xs:integer(1)"/>
-      <SingletonIterator value="xs:integer(2)"/>
-      <SingletonIterator value="xs:integer(3)"/>
-    </FnConcatIterator>
-  </ForVariable>
-  <LetVariable name="y" materialize="true">
-    <UnhoistIterator>
-      <LetVarIterator varname="$$opt_temp_0"/>
-    </UnhoistIterator>
-  </LetVariable>
-  <ForVariable name="$$opt_temp_2">
-    <HoistIterator>
-      <FnCountIterator>
-        <LetVarIterator varname="y"/>
-      </FnCountIterator>
-    </HoistIterator>
-  </ForVariable>
-  <ForVariable name="$$context-item">
-    <ProbeIndexPointValueIterator>
-      <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-      <ForVarIterator varname="x"/>
-    </ProbeIndexPointValueIterator>
-  </ForVariable>
-  <WhereClause>
-    <TypedValueCompareIterator_INTEGER>
-      <ForVarIterator varname="$$context-item"/>
+    </ForVariable>
+    <LetVariable name="y" materialize="true">
       <UnhoistIterator>
-        <ForVarIterator varname="$$opt_temp_2"/>
+        <LetVarIterator varname="$$opt_temp_0"/>
       </UnhoistIterator>
-    </TypedValueCompareIterator_INTEGER>
-  </WhereClause>
-  <ReturnClause>
-    <ForVarIterator varname="$$context-item"/>
-  </ReturnClause>
-</FLWORIterator>
-
+    </LetVariable>
+    <ForVariable name="$$opt_temp_2">
+      <HoistIterator>
+        <FnCountIterator>
+          <LetVarIterator varname="y"/>
+        </FnCountIterator>
+      </HoistIterator>
+    </ForVariable>
+    <ForVariable name="$$context-item">
+      <ProbeIndexPointValueIterator>
+        <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+        <ForVarIterator varname="x"/>
+      </ProbeIndexPointValueIterator>
+    </ForVariable>
+    <WhereClause>
+      <TypedValueCompareIterator_INTEGER>
+        <ForVarIterator varname="$$context-item"/>
+        <UnhoistIterator>
+          <ForVarIterator varname="$$opt_temp_2"/>
+        </UnhoistIterator>
+      </TypedValueCompareIterator_INTEGER>
+    </WhereClause>
+    <ReturnClause>
+      <ForVarIterator varname="$$context-item"/>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/idx2.iter'
--- test/iterplans/zorba/hashjoins/idx2.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/idx2.iter	2014-02-20 05:31:00 +0000
@@ -1,90 +1,90 @@
-Iterator tree for main query:
-<FLWORIterator>
-  <LetVariable name="auction" materialize="true">
-    <FnDocIterator>
-      <SingletonIterator value="xs:string(auction.xml)"/>
-    </FnDocIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
-      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auctions)" typename="*" nill allowed="0">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
-          <LetVarIterator varname="auction"/>
-        </ChildAxisIterator>
-      </ChildAxisIterator>
-    </HoistIterator>
-  </LetVariable>
-  <ForVariable name="p">
-    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
-      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,people)" typename="*" nill allowed="0">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
-          <LetVarIterator varname="auction"/>
-        </ChildAxisIterator>
-      </ChildAxisIterator>
-    </ChildAxisIterator>
-  </ForVariable>
-  <LetVariable name="$$opt_temp_2" materialize="true">
-    <HoistIterator>
-      <FnDataIterator>
-        <ChildAxisIterator test kind="match_text_test" qname="*" typename="*" nill allowed="0">
-          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <LetVariable name="auction" materialize="true">
+      <FnDocIterator>
+        <SingletonIterator value="xs:string(auction.xml)"/>
+      </FnDocIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_0" materialize="true">
+      <HoistIterator>
+        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auctions)" typename="*" nill allowed="0">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
+            <LetVarIterator varname="auction"/>
+          </ChildAxisIterator>
+        </ChildAxisIterator>
+      </HoistIterator>
+    </LetVariable>
+    <ForVariable name="p">
+      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
+        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,people)" typename="*" nill allowed="0">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
+            <LetVarIterator varname="auction"/>
+          </ChildAxisIterator>
+        </ChildAxisIterator>
+      </ChildAxisIterator>
+    </ForVariable>
+    <LetVariable name="$$opt_temp_2" materialize="true">
+      <HoistIterator>
+        <FnDataIterator>
+          <ChildAxisIterator test kind="match_text_test" qname="*" typename="*" nill allowed="0">
+            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
+              <ForVarIterator varname="p"/>
+            </ChildAxisIterator>
+          </ChildAxisIterator>
+        </FnDataIterator>
+      </HoistIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_1" materialize="true">
+      <HoistIterator>
+        <FnDataIterator>
+          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
             <ForVarIterator varname="p"/>
-          </ChildAxisIterator>
-        </ChildAxisIterator>
-      </FnDataIterator>
-    </HoistIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_1" materialize="true">
-    <HoistIterator>
-      <FnDataIterator>
-        <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-          <ForVarIterator varname="p"/>
-        </AttributeAxisIterator>
-      </FnDataIterator>
-    </HoistIterator>
-  </LetVariable>
-  <ForVariable name="a">
-    <UnhoistIterator>
-      <LetVarIterator varname="$$opt_temp_0"/>
-    </UnhoistIterator>
-  </ForVariable>
-  <ForVariable name="t">
-    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auction)" typename="*" nill allowed="0">
-      <ForVarIterator varname="a"/>
-    </ChildAxisIterator>
-  </ForVariable>
-  <WhereClause>
-    <FnBooleanIterator>
-      <TypedValueCompareIterator_STRING>
-        <PromoteIterator type="xs:anyAtomicType">
-          <FnDataIterator>
-            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
-              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,buyer)" typename="*" nill allowed="0">
-                <ForVarIterator varname="t"/>
-              </ChildAxisIterator>
-            </AttributeAxisIterator>
-          </FnDataIterator>
-        </PromoteIterator>
-        <UnhoistIterator>
-          <LetVarIterator varname="$$opt_temp_1"/>
-        </UnhoistIterator>
-      </TypedValueCompareIterator_STRING>
-    </FnBooleanIterator>
-  </WhereClause>
-  <ReturnClause>
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,item)"/>
-      <AttributeIterator qname="xs:QName(,,person)">
-        <EnclosedIterator attr_cont="true">
+          </AttributeAxisIterator>
+        </FnDataIterator>
+      </HoistIterator>
+    </LetVariable>
+    <ForVariable name="a">
+      <UnhoistIterator>
+        <LetVarIterator varname="$$opt_temp_0"/>
+      </UnhoistIterator>
+    </ForVariable>
+    <ForVariable name="t">
+      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auction)" typename="*" nill allowed="0">
+        <ForVarIterator varname="a"/>
+      </ChildAxisIterator>
+    </ForVariable>
+    <WhereClause>
+      <FnBooleanIterator>
+        <TypedValueCompareIterator_STRING>
+          <PromoteIterator type="xs:anyAtomicType">
+            <FnDataIterator>
+              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
+                <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,buyer)" typename="*" nill allowed="0">
+                  <ForVarIterator varname="t"/>
+                </ChildAxisIterator>
+              </AttributeAxisIterator>
+            </FnDataIterator>
+          </PromoteIterator>
           <UnhoistIterator>
-            <LetVarIterator varname="$$opt_temp_2"/>
+            <LetVarIterator varname="$$opt_temp_1"/>
           </UnhoistIterator>
+        </TypedValueCompareIterator_STRING>
+      </FnBooleanIterator>
+    </WhereClause>
+    <ReturnClause>
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,item)"/>
+        <AttributeIterator qname="xs:QName(,,person)">
+          <EnclosedIterator attr_cont="true">
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_2"/>
+            </UnhoistIterator>
+          </EnclosedIterator>
+        </AttributeIterator>
+        <EnclosedIterator attr_cont="false">
+          <ForVarIterator varname="t"/>
         </EnclosedIterator>
-      </AttributeIterator>
-      <EnclosedIterator attr_cont="false">
-        <ForVarIterator varname="t"/>
-      </EnclosedIterator>
-    </ElementIterator>
-  </ReturnClause>
-</FLWORIterator>
-
+      </ElementIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/idx3.iter'
--- test/iterplans/zorba/hashjoins/idx3.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/idx3.iter	2014-02-20 05:31:00 +0000
@@ -1,88 +1,88 @@
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for main query:
-<FunctionTraceIterator>
-  <FLWORIterator>
-    <LetVariable name="$$opt_temp_3" materialize="true">
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <FLWORIterator>
-          <ForVariable name="$$opt_temp_1">
-            <ElementIterator copyInputNodes="false">
-              <SingletonIterator value="xs:QName(,,b)"/>
-            </ElementIterator>
-          </ForVariable>
-          <ReturnClause>
-            <ValueIndexEntryBuilderIterator>
-              <ForVarIterator varname="$$opt_temp_1"/>
-              <FnStringIterator>
-                <NodeNameIterator>
-                  <ForVarIterator varname="$$opt_temp_1"/>
-                </NodeNameIterator>
-              </FnStringIterator>
-            </ValueIndexEntryBuilderIterator>
-          </ReturnClause>
-        </FLWORIterator>
-      </CreateInternalIndexIterator>
-    </LetVariable>
-    <ForVariable name="rec">
-      <NodeSortIterator distinct="true" ascending="true">
-        <ChildAxisIterator test kind="match_name_test" qname="*" typename="*" nill allowed="0">
-          <FnConcatIterator>
-            <ElementIterator>
-              <SingletonIterator value="xs:QName(,,a)"/>
-              <ElementIterator>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <FunctionTraceIterator>
+    <FLWORIterator>
+      <LetVariable name="$$opt_temp_3" materialize="true">
+        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+          <FLWORIterator>
+            <ForVariable name="$$opt_temp_1">
+              <ElementIterator copyInputNodes="false">
                 <SingletonIterator value="xs:QName(,,b)"/>
               </ElementIterator>
-            </ElementIterator>
-            <ElementIterator>
-              <SingletonIterator value="xs:QName(,,a)"/>
-              <ElementIterator>
-                <SingletonIterator value="xs:QName(,,c)"/>
-              </ElementIterator>
-            </ElementIterator>
-            <ElementIterator>
-              <SingletonIterator value="xs:QName(,,x)"/>
-              <FnConcatIterator>
-                <ElementIterator>
-                  <SingletonIterator value="xs:QName(,,x1)"/>
-                </ElementIterator>
-                <ElementIterator>
-                  <SingletonIterator value="xs:QName(,,b)"/>
-                </ElementIterator>
-                <ElementIterator>
-                  <SingletonIterator value="xs:QName(,,x2)"/>
-                </ElementIterator>
-              </FnConcatIterator>
-            </ElementIterator>
-          </FnConcatIterator>
-        </ChildAxisIterator>
-      </NodeSortIterator>
-    </ForVariable>
-    <ReturnClause>
-      <IfThenElseIterator>
-        <FnBooleanIterator>
-          <ProbeIndexPointValueIterator>
-            <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-            <UnhoistIterator>
-              <HoistIterator>
+            </ForVariable>
+            <ReturnClause>
+              <ValueIndexEntryBuilderIterator>
+                <ForVarIterator varname="$$opt_temp_1"/>
                 <FnStringIterator>
                   <NodeNameIterator>
-                    <ForVarIterator varname="rec"/>
+                    <ForVarIterator varname="$$opt_temp_1"/>
                   </NodeNameIterator>
                 </FnStringIterator>
-              </HoistIterator>
-            </UnhoistIterator>
-          </ProbeIndexPointValueIterator>
-        </FnBooleanIterator>
-        <FnConcatIterator/>
-        <ForVarIterator varname="rec"/>
-      </IfThenElseIterator>
-    </ReturnClause>
-  </FLWORIterator>
-</FunctionTraceIterator>
-
+              </ValueIndexEntryBuilderIterator>
+            </ReturnClause>
+          </FLWORIterator>
+        </CreateInternalIndexIterator>
+      </LetVariable>
+      <ForVariable name="rec">
+        <NodeSortIterator distinct="true" ascending="true">
+          <ChildAxisIterator test kind="match_name_test" qname="*" typename="*" nill allowed="0">
+            <FnConcatIterator>
+              <ElementIterator>
+                <SingletonIterator value="xs:QName(,,a)"/>
+                <ElementIterator>
+                  <SingletonIterator value="xs:QName(,,b)"/>
+                </ElementIterator>
+              </ElementIterator>
+              <ElementIterator>
+                <SingletonIterator value="xs:QName(,,a)"/>
+                <ElementIterator>
+                  <SingletonIterator value="xs:QName(,,c)"/>
+                </ElementIterator>
+              </ElementIterator>
+              <ElementIterator>
+                <SingletonIterator value="xs:QName(,,x)"/>
+                <FnConcatIterator>
+                  <ElementIterator>
+                    <SingletonIterator value="xs:QName(,,x1)"/>
+                  </ElementIterator>
+                  <ElementIterator>
+                    <SingletonIterator value="xs:QName(,,b)"/>
+                  </ElementIterator>
+                  <ElementIterator>
+                    <SingletonIterator value="xs:QName(,,x2)"/>
+                  </ElementIterator>
+                </FnConcatIterator>
+              </ElementIterator>
+            </FnConcatIterator>
+          </ChildAxisIterator>
+        </NodeSortIterator>
+      </ForVariable>
+      <ReturnClause>
+        <IfThenElseIterator>
+          <FnBooleanIterator>
+            <ProbeIndexPointValueIterator>
+              <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+              <UnhoistIterator>
+                <HoistIterator>
+                  <FnStringIterator>
+                    <NodeNameIterator>
+                      <ForVarIterator varname="rec"/>
+                    </NodeNameIterator>
+                  </FnStringIterator>
+                </HoistIterator>
+              </UnhoistIterator>
+            </ProbeIndexPointValueIterator>
+          </FnBooleanIterator>
+          <FnConcatIterator/>
+          <ForVarIterator varname="rec"/>
+        </IfThenElseIterator>
+      </ReturnClause>
+    </FLWORIterator>
+  </FunctionTraceIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/idx4.iter'
--- test/iterplans/zorba/hashjoins/idx4.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/idx4.iter	2014-02-20 05:31:00 +0000
@@ -1,160 +1,160 @@
-Iterator tree for main query:
-<FunctionTraceIterator>
-  <FLWORIterator>
-    <LetVariable name="e" materialize="true">
-      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,r2)" typename="*" nill allowed="0" target_position="0">
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,r1)"/>
-          <FnConcatIterator/>
-          <FnConcatIterator>
-            <ElementIterator>
-              <SingletonIterator value="xs:QName(,,r2)"/>
-              <FnConcatIterator/>
-            </ElementIterator>
-            <ElementIterator>
-              <SingletonIterator value="xs:QName(,,r2)"/>
-              <FnConcatIterator/>
-            </ElementIterator>
-          </FnConcatIterator>
-        </ElementIterator>
-      </ChildAxisIterator>
-    </LetVariable>
-    <ForVariable name="$$opt_temp_1">
-      <HoistIterator>
-        <TreatIterator quant="">
-          <LetVarIterator varname="e"/>
-        </TreatIterator>
-      </HoistIterator>
-    </ForVariable>
-    <ForVariable name="$$opt_temp_0">
-      <HoistIterator>
-        <TreatIterator quant="">
-          <LetVarIterator varname="e"/>
-        </TreatIterator>
-      </HoistIterator>
-    </ForVariable>
-    <LetVariable name="parent" materialize="true">
-      <ParentAxisIterator test kind="match_name_test" qname="*" typename="*" nill allowed="0">
-        <LetVarIterator varname="e"/>
-      </ParentAxisIterator>
-    </LetVariable>
-    <ForVariable name="$$opt_temp_2">
-      <HoistIterator>
-        <TreatIterator quant="">
-          <LetVarIterator varname="parent"/>
-        </TreatIterator>
-      </HoistIterator>
-    </ForVariable>
-    <LetVariable name="$$opt_temp_7" materialize="true">
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <FLWORIterator>
-          <ForVariable name="$$opt_temp_5">
-            <UnhoistIterator>
-              <HoistIterator>
-                <InScopePrefixesIterator>
-                  <TreatIterator quant="">
-                    <LetVarIterator varname="parent"/>
-                  </TreatIterator>
-                </InScopePrefixesIterator>
-              </HoistIterator>
-            </UnhoistIterator>
-          </ForVariable>
-          <ReturnClause>
-            <ValueIndexEntryBuilderIterator>
-              <ForVarIterator varname="$$opt_temp_5"/>
-              <ForVarIterator varname="$$opt_temp_5"/>
-            </ValueIndexEntryBuilderIterator>
-          </ReturnClause>
-        </FLWORIterator>
-      </CreateInternalIndexIterator>
-    </LetVariable>
-    <ForVariable name="prefixE">
-      <InScopePrefixesIterator>
-        <TreatIterator quant="">
-          <LetVarIterator varname="e"/>
-        </TreatIterator>
-      </InScopePrefixesIterator>
-    </ForVariable>
-    <LetVariable name="$$opt_temp_4" materialize="true">
-      <HoistIterator>
-        <NamespaceUriForPrefixIterator>
-          <ForVarIterator varname="prefixE"/>
-          <UnhoistIterator>
-            <ForVarIterator varname="$$opt_temp_0"/>
-          </UnhoistIterator>
-        </NamespaceUriForPrefixIterator>
-      </HoistIterator>
-    </LetVariable>
-    <ForVariable name="$$opt_temp_3">
-      <HoistIterator>
-        <ConcatStrIterator>
-          <SingletonIterator value="xs:string(xmlns:)"/>
-          <ForVarIterator varname="prefixE"/>
-          <SingletonIterator value="xs:string(=")"/>
-        </ConcatStrIterator>
-      </HoistIterator>
-    </ForVariable>
-    <LetVariable name="$$opt_temp_1" materialize="true">
-      <HoistIterator>
-        <NamespaceUriForPrefixIterator>
-          <ForVarIterator varname="prefixE"/>
-          <UnhoistIterator>
-            <ForVarIterator varname="$$opt_temp_1"/>
-          </UnhoistIterator>
-        </NamespaceUriForPrefixIterator>
-      </HoistIterator>
-    </LetVariable>
-    <ForVariable name="prefixP">
-      <ProbeIndexPointValueIterator>
-        <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-        <ForVarIterator varname="prefixE"/>
-      </ProbeIndexPointValueIterator>
-    </ForVariable>
-    <WhereClause>
-      <FnBooleanIterator>
-        <CompareIterator>
-          <UnhoistIterator>
-            <LetVarIterator varname="$$opt_temp_1"/>
-          </UnhoistIterator>
-          <NamespaceUriForPrefixIterator>
-            <ForVarIterator varname="prefixP"/>
-            <UnhoistIterator>
-              <ForVarIterator varname="$$opt_temp_2"/>
-            </UnhoistIterator>
-          </NamespaceUriForPrefixIterator>
-        </CompareIterator>
-      </FnBooleanIterator>
-    </WhereClause>
-    <ReturnClause>
-      <FnConcatIterator>
-        <SingletonIterator value="xs:string( )"/>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,span)"/>
-          <AttributeIterator qname="xs:QName(,,class)">
-            <SingletonIterator value="xs:string(ns)"/>
-          </AttributeIterator>
-          <EnclosedIterator attr_cont="false">
+<iterator-tree description="main query">
+  <FunctionTraceIterator>
+    <FLWORIterator>
+      <LetVariable name="e" materialize="true">
+        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,r2)" typename="*" nill allowed="0" target_position="0">
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,r1)"/>
+            <FnConcatIterator/>
             <FnConcatIterator>
-              <UnhoistIterator>
-                <ForVarIterator varname="$$opt_temp_3"/>
-              </UnhoistIterator>
-              <ElementIterator>
-                <SingletonIterator value="xs:QName(,,span)"/>
-                <AttributeIterator qname="xs:QName(,,class)">
-                  <SingletonIterator value="xs:string(nsUri)"/>
-                </AttributeIterator>
-                <EnclosedIterator attr_cont="false">
-                  <UnhoistIterator>
-                    <LetVarIterator varname="$$opt_temp_4"/>
-                  </UnhoistIterator>
-                </EnclosedIterator>
-              </ElementIterator>
-              <SingletonIterator value="xs:string(")"/>
+              <ElementIterator>
+                <SingletonIterator value="xs:QName(,,r2)"/>
+                <FnConcatIterator/>
+              </ElementIterator>
+              <ElementIterator>
+                <SingletonIterator value="xs:QName(,,r2)"/>
+                <FnConcatIterator/>
+              </ElementIterator>
             </FnConcatIterator>
-          </EnclosedIterator>
-        </ElementIterator>
-      </FnConcatIterator>
-    </ReturnClause>
-  </FLWORIterator>
-</FunctionTraceIterator>
-
+          </ElementIterator>
+        </ChildAxisIterator>
+      </LetVariable>
+      <ForVariable name="$$opt_temp_1">
+        <HoistIterator>
+          <TreatIterator quant="">
+            <LetVarIterator varname="e"/>
+          </TreatIterator>
+        </HoistIterator>
+      </ForVariable>
+      <ForVariable name="$$opt_temp_0">
+        <HoistIterator>
+          <TreatIterator quant="">
+            <LetVarIterator varname="e"/>
+          </TreatIterator>
+        </HoistIterator>
+      </ForVariable>
+      <LetVariable name="parent" materialize="true">
+        <ParentAxisIterator test kind="match_name_test" qname="*" typename="*" nill allowed="0">
+          <LetVarIterator varname="e"/>
+        </ParentAxisIterator>
+      </LetVariable>
+      <ForVariable name="$$opt_temp_2">
+        <HoistIterator>
+          <TreatIterator quant="">
+            <LetVarIterator varname="parent"/>
+          </TreatIterator>
+        </HoistIterator>
+      </ForVariable>
+      <LetVariable name="$$opt_temp_7" materialize="true">
+        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+          <FLWORIterator>
+            <ForVariable name="$$opt_temp_5">
+              <UnhoistIterator>
+                <HoistIterator>
+                  <InScopePrefixesIterator>
+                    <TreatIterator quant="">
+                      <LetVarIterator varname="parent"/>
+                    </TreatIterator>
+                  </InScopePrefixesIterator>
+                </HoistIterator>
+              </UnhoistIterator>
+            </ForVariable>
+            <ReturnClause>
+              <ValueIndexEntryBuilderIterator>
+                <ForVarIterator varname="$$opt_temp_5"/>
+                <ForVarIterator varname="$$opt_temp_5"/>
+              </ValueIndexEntryBuilderIterator>
+            </ReturnClause>
+          </FLWORIterator>
+        </CreateInternalIndexIterator>
+      </LetVariable>
+      <ForVariable name="prefixE">
+        <InScopePrefixesIterator>
+          <TreatIterator quant="">
+            <LetVarIterator varname="e"/>
+          </TreatIterator>
+        </InScopePrefixesIterator>
+      </ForVariable>
+      <LetVariable name="$$opt_temp_4" materialize="true">
+        <HoistIterator>
+          <NamespaceUriForPrefixIterator>
+            <ForVarIterator varname="prefixE"/>
+            <UnhoistIterator>
+              <ForVarIterator varname="$$opt_temp_0"/>
+            </UnhoistIterator>
+          </NamespaceUriForPrefixIterator>
+        </HoistIterator>
+      </LetVariable>
+      <ForVariable name="$$opt_temp_3">
+        <HoistIterator>
+          <ConcatStrIterator>
+            <SingletonIterator value="xs:string(xmlns:)"/>
+            <ForVarIterator varname="prefixE"/>
+            <SingletonIterator value="xs:string(=")"/>
+          </ConcatStrIterator>
+        </HoistIterator>
+      </ForVariable>
+      <LetVariable name="$$opt_temp_1" materialize="true">
+        <HoistIterator>
+          <NamespaceUriForPrefixIterator>
+            <ForVarIterator varname="prefixE"/>
+            <UnhoistIterator>
+              <ForVarIterator varname="$$opt_temp_1"/>
+            </UnhoistIterator>
+          </NamespaceUriForPrefixIterator>
+        </HoistIterator>
+      </LetVariable>
+      <ForVariable name="prefixP">
+        <ProbeIndexPointValueIterator>
+          <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+          <ForVarIterator varname="prefixE"/>
+        </ProbeIndexPointValueIterator>
+      </ForVariable>
+      <WhereClause>
+        <FnBooleanIterator>
+          <CompareIterator>
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_1"/>
+            </UnhoistIterator>
+            <NamespaceUriForPrefixIterator>
+              <ForVarIterator varname="prefixP"/>
+              <UnhoistIterator>
+                <ForVarIterator varname="$$opt_temp_2"/>
+              </UnhoistIterator>
+            </NamespaceUriForPrefixIterator>
+          </CompareIterator>
+        </FnBooleanIterator>
+      </WhereClause>
+      <ReturnClause>
+        <FnConcatIterator>
+          <SingletonIterator value="xs:string( )"/>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,span)"/>
+            <AttributeIterator qname="xs:QName(,,class)">
+              <SingletonIterator value="xs:string(ns)"/>
+            </AttributeIterator>
+            <EnclosedIterator attr_cont="false">
+              <FnConcatIterator>
+                <UnhoistIterator>
+                  <ForVarIterator varname="$$opt_temp_3"/>
+                </UnhoistIterator>
+                <ElementIterator>
+                  <SingletonIterator value="xs:QName(,,span)"/>
+                  <AttributeIterator qname="xs:QName(,,class)">
+                    <SingletonIterator value="xs:string(nsUri)"/>
+                  </AttributeIterator>
+                  <EnclosedIterator attr_cont="false">
+                    <UnhoistIterator>
+                      <LetVarIterator varname="$$opt_temp_4"/>
+                    </UnhoistIterator>
+                  </EnclosedIterator>
+                </ElementIterator>
+                <SingletonIterator value="xs:string(")"/>
+              </FnConcatIterator>
+            </EnclosedIterator>
+          </ElementIterator>
+        </FnConcatIterator>
+      </ReturnClause>
+    </FLWORIterator>
+  </FunctionTraceIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/idx5.iter'
--- test/iterplans/zorba/hashjoins/idx5.iter	2013-09-11 10:38:42 +0000
+++ test/iterplans/zorba/hashjoins/idx5.iter	2014-02-20 05:31:00 +0000
@@ -1,24 +1,24 @@
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="tests">
-    <ElementIterator copyInputNodes="false">
-      <SingletonIterator value="xs:QName(,,tests)"/>
-    </ElementIterator>
-  </CtxVarDeclareIterator>
-  <SingletonIterator value="xs:integer(1)"/>
-</SequentialIterator>
-
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <CtxVarDeclareIterator varid="4" varname="tests">
+      <ElementIterator copyInputNodes="false">
+        <SingletonIterator value="xs:QName(,,tests)"/>
+      </ElementIterator>
+    </CtxVarDeclareIterator>
+    <SingletonIterator value="xs:integer(1)"/>
+  </SequentialIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/idx8.iter'
--- test/iterplans/zorba/hashjoins/idx8.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/idx8.iter	2014-02-20 05:31:00 +0000
@@ -1,99 +1,99 @@
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for main query:
-<FLWORIterator>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <LetVariable name="$$opt_temp_0" materialize="true">
+      <HoistIterator>
+        <FnConcatIterator>
+          <SingletonIterator value="xs:string(http://www.w3.org/2005/xpath-functions)"/>
+          <FnConcatIterator/>
+        </FnConcatIterator>
+      </HoistIterator>
+    </LetVariable>
+    <LetVariable name="fs" materialize="true">
+      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(http://www.xqdoc.org/1.0,xqdoc,function)" typename="*" nill allowed="0">
+        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(http://www.xqdoc.org/1.0,xqdoc,functions)" typename="*" nill allowed="0">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(http://www.xqdoc.org/1.0,xqdoc,xqdoc)" typename="*" nill allowed="0">
+            <FnDocIterator>
+              <SingletonIterator value="xs:string(xqdoc.xml)"/>
+            </FnDocIterator>
+          </ChildAxisIterator>
+        </ChildAxisIterator>
+      </ChildAxisIterator>
+    </LetVariable>
+    <ForVariable name="function">
       <FnConcatIterator>
-        <SingletonIterator value="xs:string(http://www.w3.org/2005/xpath-functions)"/>
-        <FnConcatIterator/>
+        <LetVarIterator varname="fs" targetPos="1"/>
+        <LetVarIterator varname="fs" targetPos="8"/>
       </FnConcatIterator>
-    </HoistIterator>
-  </LetVariable>
-  <LetVariable name="fs" materialize="true">
-    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(http://www.xqdoc.org/1.0,xqdoc,function)" typename="*" nill allowed="0">
-      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(http://www.xqdoc.org/1.0,xqdoc,functions)" typename="*" nill allowed="0">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(http://www.xqdoc.org/1.0,xqdoc,xqdoc)" typename="*" nill allowed="0">
-          <FnDocIterator>
-            <SingletonIterator value="xs:string(xqdoc.xml)"/>
-          </FnDocIterator>
-        </ChildAxisIterator>
-      </ChildAxisIterator>
-    </ChildAxisIterator>
-  </LetVariable>
-  <ForVariable name="function">
-    <FnConcatIterator>
-      <LetVarIterator varname="fs" targetPos="1"/>
-      <LetVarIterator varname="fs" targetPos="8"/>
-    </FnConcatIterator>
-  </ForVariable>
-  <LetVariable name="$$opt_temp_2" materialize="true">
-    <HoistIterator>
-      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(http://www.xqdoc.org/1.0,xqdoc,invoked)" typename="*" nill allowed="0">
-        <ForVarIterator varname="function"/>
-      </ChildAxisIterator>
-    </HoistIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_5" materialize="true">
-    <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-      <FLWORIterator>
-        <ForVariable name="$$opt_temp_3">
-          <UnhoistIterator>
-            <LetVarIterator varname="$$opt_temp_2"/>
-          </UnhoistIterator>
-        </ForVariable>
-        <ReturnClause>
-          <ValueIndexEntryBuilderIterator>
-            <ForVarIterator varname="$$opt_temp_3"/>
-            <FnStringIterator>
-              <TreatIterator quant="?">
-                <ChildAxisIterator test kind="match_name_test" qname="xs:QName(http://www.xqdoc.org/1.0,xqdoc,uri)" typename="*" nill allowed="0">
-                  <ForVarIterator varname="$$opt_temp_3"/>
-                </ChildAxisIterator>
-              </TreatIterator>
-            </FnStringIterator>
-          </ValueIndexEntryBuilderIterator>
-        </ReturnClause>
-      </FLWORIterator>
-    </CreateInternalIndexIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_1" materialize="true">
-    <HoistIterator>
-      <ChildAxisIterator test kind="match_text_test" qname="*" typename="*" nill allowed="0">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(http://www.xqdoc.org/1.0,xqdoc,name)" typename="*" nill allowed="0">
+    </ForVariable>
+    <LetVariable name="$$opt_temp_2" materialize="true">
+      <HoistIterator>
+        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(http://www.xqdoc.org/1.0,xqdoc,invoked)" typename="*" nill allowed="0">
           <ForVarIterator varname="function"/>
         </ChildAxisIterator>
-      </ChildAxisIterator>
-    </HoistIterator>
-  </LetVariable>
-  <ForVariable name="furi">
-    <UnhoistIterator>
-      <LetVarIterator varname="$$opt_temp_0"/>
-    </UnhoistIterator>
-  </ForVariable>
-  <ReturnClause>
-    <FnConcatIterator>
+      </HoistIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_5" materialize="true">
+      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+        <FLWORIterator>
+          <ForVariable name="$$opt_temp_3">
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_2"/>
+            </UnhoistIterator>
+          </ForVariable>
+          <ReturnClause>
+            <ValueIndexEntryBuilderIterator>
+              <ForVarIterator varname="$$opt_temp_3"/>
+              <FnStringIterator>
+                <TreatIterator quant="?">
+                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(http://www.xqdoc.org/1.0,xqdoc,uri)" typename="*" nill allowed="0">
+                    <ForVarIterator varname="$$opt_temp_3"/>
+                  </ChildAxisIterator>
+                </TreatIterator>
+              </FnStringIterator>
+            </ValueIndexEntryBuilderIterator>
+          </ReturnClause>
+        </FLWORIterator>
+      </CreateInternalIndexIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_1" materialize="true">
+      <HoistIterator>
+        <ChildAxisIterator test kind="match_text_test" qname="*" typename="*" nill allowed="0">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(http://www.xqdoc.org/1.0,xqdoc,name)" typename="*" nill allowed="0">
+            <ForVarIterator varname="function"/>
+          </ChildAxisIterator>
+        </ChildAxisIterator>
+      </HoistIterator>
+    </LetVariable>
+    <ForVariable name="furi">
       <UnhoistIterator>
-        <LetVarIterator varname="$$opt_temp_1"/>
+        <LetVarIterator varname="$$opt_temp_0"/>
       </UnhoistIterator>
-      <SingletonIterator value="xs:string(:)"/>
-      <FLWORIterator>
-        <ForVariable name="$$context-item">
-          <ProbeIndexPointValueIterator>
-            <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-            <ForVarIterator varname="furi"/>
-          </ProbeIndexPointValueIterator>
-        </ForVariable>
-        <ReturnClause>
-          <ForVarIterator varname="$$context-item"/>
-        </ReturnClause>
-      </FLWORIterator>
-    </FnConcatIterator>
-  </ReturnClause>
-</FLWORIterator>
-
+    </ForVariable>
+    <ReturnClause>
+      <FnConcatIterator>
+        <UnhoistIterator>
+          <LetVarIterator varname="$$opt_temp_1"/>
+        </UnhoistIterator>
+        <SingletonIterator value="xs:string(:)"/>
+        <FLWORIterator>
+          <ForVariable name="$$context-item">
+            <ProbeIndexPointValueIterator>
+              <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+              <ForVarIterator varname="furi"/>
+            </ProbeIndexPointValueIterator>
+          </ForVariable>
+          <ReturnClause>
+            <ForVarIterator varname="$$context-item"/>
+          </ReturnClause>
+        </FLWORIterator>
+      </FnConcatIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/idx9.iter'
--- test/iterplans/zorba/hashjoins/idx9.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/idx9.iter	2014-02-20 05:31:00 +0000
@@ -1,90 +1,90 @@
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <ApplyIterator>
-    <ZorbaCreateCollectionIterator>
-      <SingletonIterator value="xs:QName(http://foo.com,foo,bet)"/>
-    </ZorbaCreateCollectionIterator>
-  </ApplyIterator>
-  <ApplyIterator>
-    <ZorbaCreateCollectionIterator>
-      <SingletonIterator value="xs:QName(http://foo.com,foo,game)"/>
-    </ZorbaCreateCollectionIterator>
-  </ApplyIterator>
-  <FunctionTraceIterator>
-    <TupleStreamIterator>
-      <WhereIterator>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <ApplyIterator>
+      <ZorbaCreateCollectionIterator>
+        <SingletonIterator value="xs:QName(http://foo.com,foo,bet)"/>
+      </ZorbaCreateCollectionIterator>
+    </ApplyIterator>
+    <ApplyIterator>
+      <ZorbaCreateCollectionIterator>
+        <SingletonIterator value="xs:QName(http://foo.com,foo,game)"/>
+      </ZorbaCreateCollectionIterator>
+    </ApplyIterator>
+    <FunctionTraceIterator>
+      <TupleStreamIterator>
         <WhereIterator>
-          <ForIterator>
-            <ForVariable name="$$context-item"/>
-            <LetIterator>
-              <LetVariable name="$$opt_temp_3" materialize="true"/>
-              <TupleSourceIterator/>
-              <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-                <FLWORIterator>
-                  <ForVariable name="$$opt_temp_1">
-                    <ZorbaCollectionIterator>
-                      <SingletonIterator value="xs:QName(http://foo.com,foo,game)"/>
-                    </ZorbaCollectionIterator>
-                  </ForVariable>
-                  <ReturnClause>
-                    <GeneralIndexEntryBuilderIterator>
-                      <ForVarIterator varname="$$opt_temp_1"/>
-                      <FnDataIterator>
-                        <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,gid)" typename="*" nill allowed="0">
-                          <ForVarIterator varname="$$opt_temp_1"/>
-                        </AttributeAxisIterator>
-                      </FnDataIterator>
-                    </GeneralIndexEntryBuilderIterator>
-                  </ReturnClause>
-                </FLWORIterator>
-              </CreateInternalIndexIterator>
-            </LetIterator>
-            <ZorbaCollectionIterator>
-              <SingletonIterator value="xs:QName(http://foo.com,foo,bet)"/>
-            </ZorbaCollectionIterator>
-          </ForIterator>
-          <CompareIterator>
-            <FnDataIterator>
-              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,uid)" typename="*" nill allowed="0">
-                <ForVarIterator varname="$$context-item"/>
-              </AttributeAxisIterator>
-            </FnDataIterator>
-            <SingletonIterator value="xs:integer(1)"/>
-          </CompareIterator>
+          <WhereIterator>
+            <ForIterator>
+              <ForVariable name="$$context-item"/>
+              <LetIterator>
+                <LetVariable name="$$opt_temp_3" materialize="true"/>
+                <TupleSourceIterator/>
+                <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+                  <FLWORIterator>
+                    <ForVariable name="$$opt_temp_1">
+                      <ZorbaCollectionIterator>
+                        <SingletonIterator value="xs:QName(http://foo.com,foo,game)"/>
+                      </ZorbaCollectionIterator>
+                    </ForVariable>
+                    <ReturnClause>
+                      <GeneralIndexEntryBuilderIterator>
+                        <ForVarIterator varname="$$opt_temp_1"/>
+                        <FnDataIterator>
+                          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,gid)" typename="*" nill allowed="0">
+                            <ForVarIterator varname="$$opt_temp_1"/>
+                          </AttributeAxisIterator>
+                        </FnDataIterator>
+                      </GeneralIndexEntryBuilderIterator>
+                    </ReturnClause>
+                  </FLWORIterator>
+                </CreateInternalIndexIterator>
+              </LetIterator>
+              <ZorbaCollectionIterator>
+                <SingletonIterator value="xs:QName(http://foo.com,foo,bet)"/>
+              </ZorbaCollectionIterator>
+            </ForIterator>
+            <CompareIterator>
+              <FnDataIterator>
+                <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,uid)" typename="*" nill allowed="0">
+                  <ForVarIterator varname="$$context-item"/>
+                </AttributeAxisIterator>
+              </FnDataIterator>
+              <SingletonIterator value="xs:integer(1)"/>
+            </CompareIterator>
+          </WhereIterator>
+          <FnBooleanIterator>
+            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,result)" typename="*" nill allowed="0">
+              <ProbeIndexPointGeneralIterator>
+                <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+                <UnhoistIterator>
+                  <HoistIterator>
+                    <FnDataIterator>
+                      <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,gid)" typename="*" nill allowed="0">
+                        <ForVarIterator varname="$$context-item"/>
+                      </AttributeAxisIterator>
+                    </FnDataIterator>
+                  </HoistIterator>
+                </UnhoistIterator>
+              </ProbeIndexPointGeneralIterator>
+            </ChildAxisIterator>
+          </FnBooleanIterator>
         </WhereIterator>
-        <FnBooleanIterator>
-          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,result)" typename="*" nill allowed="0">
-            <ProbeIndexPointGeneralIterator>
-              <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-              <UnhoistIterator>
-                <HoistIterator>
-                  <FnDataIterator>
-                    <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,gid)" typename="*" nill allowed="0">
-                      <ForVarIterator varname="$$context-item"/>
-                    </AttributeAxisIterator>
-                  </FnDataIterator>
-                </HoistIterator>
-              </UnhoistIterator>
-            </ProbeIndexPointGeneralIterator>
-          </ChildAxisIterator>
-        </FnBooleanIterator>
-      </WhereIterator>
-      <SingletonIterator value="xs:integer(1)"/>
-    </TupleStreamIterator>
-  </FunctionTraceIterator>
-</SequentialIterator>
-
+        <SingletonIterator value="xs:integer(1)"/>
+      </TupleStreamIterator>
+    </FunctionTraceIterator>
+  </SequentialIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/no_idx1.iter'
--- test/iterplans/zorba/hashjoins/no_idx1.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/no_idx1.iter	2014-02-20 05:31:00 +0000
@@ -1,65 +1,65 @@
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for main query:
-<FunctionTraceIterator>
-  <FLWORIterator>
-    <ForVariable name="ancestor">
-      <AncestorSelfAxisIterator test kind="match_name_test" qname="*" typename="*" nill allowed="0">
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,a)"/>
-        </ElementIterator>
-      </AncestorSelfAxisIterator>
-    </ForVariable>
-    <ForVariable name="$$opt_temp_0">
-      <HoistIterator>
-        <FnStringIterator>
-          <NodeNameIterator>
-            <ForVarIterator varname="ancestor"/>
-          </NodeNameIterator>
-        </FnStringIterator>
-      </HoistIterator>
-    </ForVariable>
-    <ReturnClause>
-      <FnConcatIterator>
-        <FnStringIterator>
-          <NodeNameIterator>
-            <ForVarIterator varname="ancestor"/>
-          </NodeNameIterator>
-        </FnStringIterator>
-        <FLWORIterator>
-          <ForVariable name="$$context-item">
-            <ParentAxisIterator test kind="match_anykind_test" qname="*" typename="*" nill allowed="0">
-              <ForVarIterator varname="ancestor"/>
-            </ParentAxisIterator>
-          </ForVariable>
-          <ForVariable name="$$context-item">
-            <ChildAxisIterator test kind="match_name_test" qname="*" typename="*" nill allowed="0">
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <FunctionTraceIterator>
+    <FLWORIterator>
+      <ForVariable name="ancestor">
+        <AncestorSelfAxisIterator test kind="match_name_test" qname="*" typename="*" nill allowed="0">
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,a)"/>
+          </ElementIterator>
+        </AncestorSelfAxisIterator>
+      </ForVariable>
+      <ForVariable name="$$opt_temp_0">
+        <HoistIterator>
+          <FnStringIterator>
+            <NodeNameIterator>
+              <ForVarIterator varname="ancestor"/>
+            </NodeNameIterator>
+          </FnStringIterator>
+        </HoistIterator>
+      </ForVariable>
+      <ReturnClause>
+        <FnConcatIterator>
+          <FnStringIterator>
+            <NodeNameIterator>
+              <ForVarIterator varname="ancestor"/>
+            </NodeNameIterator>
+          </FnStringIterator>
+          <FLWORIterator>
+            <ForVariable name="$$context-item">
+              <ParentAxisIterator test kind="match_anykind_test" qname="*" typename="*" nill allowed="0">
+                <ForVarIterator varname="ancestor"/>
+              </ParentAxisIterator>
+            </ForVariable>
+            <ForVariable name="$$context-item">
+              <ChildAxisIterator test kind="match_name_test" qname="*" typename="*" nill allowed="0">
+                <ForVarIterator varname="$$context-item"/>
+              </ChildAxisIterator>
+            </ForVariable>
+            <WhereClause>
+              <TypedValueCompareIterator_STRING>
+                <FnStringIterator>
+                  <NodeNameIterator>
+                    <ForVarIterator varname="$$context-item"/>
+                  </NodeNameIterator>
+                </FnStringIterator>
+                <UnhoistIterator>
+                  <ForVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </TypedValueCompareIterator_STRING>
+            </WhereClause>
+            <ReturnClause>
               <ForVarIterator varname="$$context-item"/>
-            </ChildAxisIterator>
-          </ForVariable>
-          <WhereClause>
-            <TypedValueCompareIterator_STRING>
-              <FnStringIterator>
-                <NodeNameIterator>
-                  <ForVarIterator varname="$$context-item"/>
-                </NodeNameIterator>
-              </FnStringIterator>
-              <UnhoistIterator>
-                <ForVarIterator varname="$$opt_temp_0"/>
-              </UnhoistIterator>
-            </TypedValueCompareIterator_STRING>
-          </WhereClause>
-          <ReturnClause>
-            <ForVarIterator varname="$$context-item"/>
-          </ReturnClause>
-        </FLWORIterator>
-      </FnConcatIterator>
-    </ReturnClause>
-  </FLWORIterator>
-</FunctionTraceIterator>
-
+            </ReturnClause>
+          </FLWORIterator>
+        </FnConcatIterator>
+      </ReturnClause>
+    </FLWORIterator>
+  </FunctionTraceIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/hashjoins/q8.iter'
--- test/iterplans/zorba/hashjoins/q8.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/hashjoins/q8.iter	2014-02-20 05:31:00 +0000
@@ -1,98 +1,98 @@
-Iterator tree for main query:
-<FLWORIterator>
-  <LetVariable name="auction" materialize="true">
-    <FnDocIterator>
-      <SingletonIterator value="xs:string(auction.xml)"/>
-    </FnDocIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
-      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auction)" typename="*" nill allowed="0">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auctions)" typename="*" nill allowed="0">
+<iterator-tree description="main query">
+  <FLWORIterator>
+    <LetVariable name="auction" materialize="true">
+      <FnDocIterator>
+        <SingletonIterator value="xs:string(auction.xml)"/>
+      </FnDocIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_0" materialize="true">
+      <HoistIterator>
+        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auction)" typename="*" nill allowed="0">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auctions)" typename="*" nill allowed="0">
+            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
+              <LetVarIterator varname="auction"/>
+            </ChildAxisIterator>
+          </ChildAxisIterator>
+        </ChildAxisIterator>
+      </HoistIterator>
+    </LetVariable>
+    <LetVariable name="$$opt_temp_4" materialize="true">
+      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+        <FLWORIterator>
+          <ForVariable name="$$opt_temp_2">
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_0"/>
+            </UnhoistIterator>
+          </ForVariable>
+          <ReturnClause>
+            <ValueIndexEntryBuilderIterator>
+              <ForVarIterator varname="$$opt_temp_2"/>
+              <CastIterator type="xs:string">
+                <FnDataIterator>
+                  <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,buyer)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_2"/>
+                    </ChildAxisIterator>
+                  </AttributeAxisIterator>
+                </FnDataIterator>
+              </CastIterator>
+            </ValueIndexEntryBuilderIterator>
+          </ReturnClause>
+        </FLWORIterator>
+      </CreateInternalIndexIterator>
+    </LetVariable>
+    <ForVariable name="p">
+      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
+        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,people)" typename="*" nill allowed="0">
           <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
             <LetVarIterator varname="auction"/>
           </ChildAxisIterator>
         </ChildAxisIterator>
       </ChildAxisIterator>
-    </HoistIterator>
-  </LetVariable>
-  <LetVariable name="$$opt_temp_4" materialize="true">
-    <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-      <FLWORIterator>
-        <ForVariable name="$$opt_temp_2">
-          <UnhoistIterator>
-            <LetVarIterator varname="$$opt_temp_0"/>
-          </UnhoistIterator>
-        </ForVariable>
-        <ReturnClause>
-          <ValueIndexEntryBuilderIterator>
-            <ForVarIterator varname="$$opt_temp_2"/>
-            <CastIterator type="xs:string">
-              <FnDataIterator>
-                <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
-                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,buyer)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="$$opt_temp_2"/>
-                  </ChildAxisIterator>
-                </AttributeAxisIterator>
-              </FnDataIterator>
-            </CastIterator>
-          </ValueIndexEntryBuilderIterator>
-        </ReturnClause>
-      </FLWORIterator>
-    </CreateInternalIndexIterator>
-  </LetVariable>
-  <ForVariable name="p">
-    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
-      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,people)" typename="*" nill allowed="0">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
-          <LetVarIterator varname="auction"/>
-        </ChildAxisIterator>
-      </ChildAxisIterator>
-    </ChildAxisIterator>
-  </ForVariable>
-  <LetVariable name="$$opt_temp_1" materialize="true">
-    <HoistIterator>
-      <CastIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-            <ForVarIterator varname="p"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </CastIterator>
-    </HoistIterator>
-  </LetVariable>
-  <ReturnClause>
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,item)"/>
-      <AttributeIterator qname="xs:QName(,,person)">
-        <EnclosedIterator attr_cont="true">
+    </ForVariable>
+    <LetVariable name="$$opt_temp_1" materialize="true">
+      <HoistIterator>
+        <CastIterator type="xs:string">
           <FnDataIterator>
-            <ChildAxisIterator test kind="match_text_test" qname="*" typename="*" nill allowed="0">
-              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
-                <ForVarIterator varname="p"/>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+              <ForVarIterator varname="p"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </CastIterator>
+      </HoistIterator>
+    </LetVariable>
+    <ReturnClause>
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,item)"/>
+        <AttributeIterator qname="xs:QName(,,person)">
+          <EnclosedIterator attr_cont="true">
+            <FnDataIterator>
+              <ChildAxisIterator test kind="match_text_test" qname="*" typename="*" nill allowed="0">
+                <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
+                  <ForVarIterator varname="p"/>
+                </ChildAxisIterator>
               </ChildAxisIterator>
-            </ChildAxisIterator>
-          </FnDataIterator>
+            </FnDataIterator>
+          </EnclosedIterator>
+        </AttributeIterator>
+        <EnclosedIterator attr_cont="false">
+          <FnCountIterator>
+            <FLWORIterator>
+              <ForVariable name="t">
+                <ProbeIndexPointValueIterator>
+                  <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+                  <UnhoistIterator>
+                    <LetVarIterator varname="$$opt_temp_1"/>
+                  </UnhoistIterator>
+                </ProbeIndexPointValueIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ForVarIterator varname="t"/>
+              </ReturnClause>
+            </FLWORIterator>
+          </FnCountIterator>
         </EnclosedIterator>
-      </AttributeIterator>
-      <EnclosedIterator attr_cont="false">
-        <FnCountIterator>
-          <FLWORIterator>
-            <ForVariable name="t">
-              <ProbeIndexPointValueIterator>
-                <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-                <UnhoistIterator>
-                  <LetVarIterator varname="$$opt_temp_1"/>
-                </UnhoistIterator>
-              </ProbeIndexPointValueIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ForVarIterator varname="t"/>
-            </ReturnClause>
-          </FLWORIterator>
-        </FnCountIterator>
-      </EnclosedIterator>
-    </ElementIterator>
-  </ReturnClause>
-</FLWORIterator>
-
+      </ElementIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/index/match_veq_01.iter'
--- test/iterplans/zorba/index/match_veq_01.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/index/match_veq_01.iter	2014-02-20 05:31:00 +0000
@@ -1,127 +1,127 @@
-Iterator tree for doc indexer:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <CastIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,email)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </CastIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for index:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <ZorbaCollectionIterator>
-      <SingletonIterator value="xs:QName(www.accounts.com,accounts,accounts)"/>
-    </ZorbaCollectionIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <CastIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,email)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </CastIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for const-folded expr:
-<LowerCaseIterator>
-  <SingletonIterator value="xs:string(George@xxxxxxxxx)"/>
-</LowerCaseIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="doc">
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,accounts)"/>
+<iterator-tree description="doc indexer">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <CastIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,email)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </CastIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="index">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <ZorbaCollectionIterator>
+        <SingletonIterator value="xs:QName(www.accounts.com,accounts,accounts)"/>
+      </ZorbaCollectionIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <CastIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,email)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </CastIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <LowerCaseIterator>
+    <SingletonIterator value="xs:string(George@xxxxxxxxx)"/>
+  </LowerCaseIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <CtxVarDeclareIterator varid="4" varname="doc">
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,accounts)"/>
+        <FnConcatIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,account)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,name)">
+                <SingletonIterator value="xs:string(John)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,email)">
+                <SingletonIterator value="xs:string(john@xxxxxxxxx)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+          </ElementIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,account)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,name)">
+                <SingletonIterator value="xs:string(George)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,email)">
+                <SingletonIterator value="xs:string(george@xxxxxxxxx)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+          </ElementIterator>
+        </FnConcatIterator>
+      </ElementIterator>
+    </CtxVarDeclareIterator>
+    <SequentialIterator>
+      <ApplyIterator>
+        <ZorbaCreateCollectionIterator>
+          <SingletonIterator value="xs:QName(www.accounts.com,accounts,accounts)"/>
+        </ZorbaCreateCollectionIterator>
+      </ApplyIterator>
+      <ApplyIterator>
+        <CreateIndexIterator>
+          <SingletonIterator value="xs:QName(www.accounts.com,accounts,accounts-index)"/>
+        </CreateIndexIterator>
+      </ApplyIterator>
+      <FLWORIterator>
+        <ForVariable name="acc">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,account)" typename="*" nill allowed="0">
+            <CtxVarIterator varid="4" varname="doc" varkind="global"/>
+          </ChildAxisIterator>
+        </ForVariable>
+        <MaterializeClause>
+          <MaterializeForVariable inputVar="acc : "/>
+        </MaterializeClause>
+        <ReturnClause>
+          <ApplyIterator>
+            <ZorbaInsertIterator need-to-copy="true">
+              <SingletonIterator value="xs:QName(www.accounts.com,accounts,accounts)"/>
+              <ForVarIterator varname="acc"/>
+            </ZorbaInsertIterator>
+          </ApplyIterator>
+        </ReturnClause>
+      </FLWORIterator>
       <FnConcatIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,account)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,name)">
-              <SingletonIterator value="xs:string(John)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,email)">
-              <SingletonIterator value="xs:string(john@xxxxxxxxx)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-        </ElementIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,account)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,name)">
-              <SingletonIterator value="xs:string(George)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,email)">
+        <FunctionTraceIterator>
+          <NodeSortIterator distinct="false" ascending="true">
+            <ProbeIndexPointValueIterator>
+              <SingletonIterator value="xs:QName(www.accounts.com,accounts,accounts-index)"/>
               <SingletonIterator value="xs:string(george@xxxxxxxxx)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-        </ElementIterator>
+            </ProbeIndexPointValueIterator>
+          </NodeSortIterator>
+        </FunctionTraceIterator>
+        <SingletonIterator value="xs:string(
+)"/>
       </FnConcatIterator>
-    </ElementIterator>
-  </CtxVarDeclareIterator>
-  <SequentialIterator>
-    <ApplyIterator>
-      <ZorbaCreateCollectionIterator>
-        <SingletonIterator value="xs:QName(www.accounts.com,accounts,accounts)"/>
-      </ZorbaCreateCollectionIterator>
-    </ApplyIterator>
-    <ApplyIterator>
-      <CreateIndexIterator>
-        <SingletonIterator value="xs:QName(www.accounts.com,accounts,accounts-index)"/>
-      </CreateIndexIterator>
-    </ApplyIterator>
-    <FLWORIterator>
-      <ForVariable name="acc">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,account)" typename="*" nill allowed="0">
-          <CtxVarIterator varid="4" varname="doc" varkind="global"/>
-        </ChildAxisIterator>
-      </ForVariable>
-      <MaterializeClause>
-        <MaterializeForVariable inputVar="acc : "/>
-      </MaterializeClause>
-      <ReturnClause>
-        <ApplyIterator>
-          <ZorbaInsertIterator need-to-copy="true">
-            <SingletonIterator value="xs:QName(www.accounts.com,accounts,accounts)"/>
-            <ForVarIterator varname="acc"/>
-          </ZorbaInsertIterator>
-        </ApplyIterator>
-      </ReturnClause>
-    </FLWORIterator>
-    <FnConcatIterator>
-      <FunctionTraceIterator>
-        <NodeSortIterator distinct="false" ascending="true">
-          <ProbeIndexPointValueIterator>
-            <SingletonIterator value="xs:QName(www.accounts.com,accounts,accounts-index)"/>
-            <SingletonIterator value="xs:string(george@xxxxxxxxx)"/>
-          </ProbeIndexPointValueIterator>
-        </NodeSortIterator>
-      </FunctionTraceIterator>
-      <SingletonIterator value="xs:string(
-)"/>
-    </FnConcatIterator>
+    </SequentialIterator>
   </SequentialIterator>
-</SequentialIterator>
-
+</iterator-tree>

=== modified file 'test/iterplans/zorba/index/match_veq_02.iter'
--- test/iterplans/zorba/index/match_veq_02.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/index/match_veq_02.iter	2014-02-20 05:31:00 +0000
@@ -1,172 +1,172 @@
-Iterator tree for doc indexer:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <CastIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </CastIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for index:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <ZorbaCollectionIterator>
+<iterator-tree description="doc indexer">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <CastIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </CastIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="index">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <ZorbaCollectionIterator>
+        <SingletonIterator value="xs:QName(www.sessions.com,sessions,sessions)"/>
+      </ZorbaCollectionIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <CastIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </CastIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <CtxVarDeclareIterator varid="4" varname="sessions:sessions">
       <SingletonIterator value="xs:QName(www.sessions.com,sessions,sessions)"/>
-    </ZorbaCollectionIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <CastIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </CastIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="sessions:sessions">
-    <SingletonIterator value="xs:QName(www.sessions.com,sessions,sessions)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="5" varname="external_id">
-    <SingletonIterator value="xs:string(50)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="6" varname="doc">
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,sessions)"/>
-      <FnConcatIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,session)"/>
-          <AttributeIterator qname="xs:QName(,,id)">
-            <SingletonIterator value="xs:string(50)"/>
-          </AttributeIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,data)"/>
-            <TextIterator>
-              <SingletonIterator value="xs:string(1111111111)"/>
-            </TextIterator>
-          </ElementIterator>
-        </ElementIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,session)"/>
-          <AttributeIterator qname="xs:QName(,,id)">
-            <SingletonIterator value="xs:string(12)"/>
-          </AttributeIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,data)"/>
-            <TextIterator>
-              <SingletonIterator value="xs:string(2222222222)"/>
-            </TextIterator>
-          </ElementIterator>
-        </ElementIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,session)"/>
-          <AttributeIterator qname="xs:QName(,,id)">
-            <SingletonIterator value="xs:string(50)"/>
-          </AttributeIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,data)"/>
-            <TextIterator>
-              <SingletonIterator value="xs:string(3333333333)"/>
-            </TextIterator>
-          </ElementIterator>
-        </ElementIterator>
-      </FnConcatIterator>
-    </ElementIterator>
-  </CtxVarDeclareIterator>
-  <SequentialIterator>
-    <ApplyIterator>
-      <ZorbaCreateCollectionIterator>
-        <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
-      </ZorbaCreateCollectionIterator>
-    </ApplyIterator>
-    <ApplyIterator>
-      <CreateIndexIterator>
-        <SingletonIterator value="xs:QName(www.sessions.com,s,session-index)"/>
-      </CreateIndexIterator>
-    </ApplyIterator>
-    <FLWORIterator>
-      <ForVariable name="s">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,session)" typename="*" nill allowed="0">
-          <CtxVarIterator varid="6" varname="doc" varkind="global"/>
-        </ChildAxisIterator>
-      </ForVariable>
-      <MaterializeClause>
-        <MaterializeForVariable inputVar="s : "/>
-      </MaterializeClause>
-      <ReturnClause>
-        <ApplyIterator>
-          <ZorbaInsertIterator need-to-copy="true">
-            <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
-            <ForVarIterator varname="s"/>
-          </ZorbaInsertIterator>
-        </ApplyIterator>
-      </ReturnClause>
-    </FLWORIterator>
-    <FnConcatIterator>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="5" varname="external_id">
+      <SingletonIterator value="xs:string(50)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="6" varname="doc">
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,sessions)"/>
+        <FnConcatIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,session)"/>
+            <AttributeIterator qname="xs:QName(,,id)">
+              <SingletonIterator value="xs:string(50)"/>
+            </AttributeIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,data)"/>
+              <TextIterator>
+                <SingletonIterator value="xs:string(1111111111)"/>
+              </TextIterator>
+            </ElementIterator>
+          </ElementIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,session)"/>
+            <AttributeIterator qname="xs:QName(,,id)">
+              <SingletonIterator value="xs:string(12)"/>
+            </AttributeIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,data)"/>
+              <TextIterator>
+                <SingletonIterator value="xs:string(2222222222)"/>
+              </TextIterator>
+            </ElementIterator>
+          </ElementIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,session)"/>
+            <AttributeIterator qname="xs:QName(,,id)">
+              <SingletonIterator value="xs:string(50)"/>
+            </AttributeIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,data)"/>
+              <TextIterator>
+                <SingletonIterator value="xs:string(3333333333)"/>
+              </TextIterator>
+            </ElementIterator>
+          </ElementIterator>
+        </FnConcatIterator>
+      </ElementIterator>
+    </CtxVarDeclareIterator>
+    <SequentialIterator>
+      <ApplyIterator>
+        <ZorbaCreateCollectionIterator>
+          <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
+        </ZorbaCreateCollectionIterator>
+      </ApplyIterator>
+      <ApplyIterator>
+        <CreateIndexIterator>
+          <SingletonIterator value="xs:QName(www.sessions.com,s,session-index)"/>
+        </CreateIndexIterator>
+      </ApplyIterator>
       <FLWORIterator>
-        <LetVariable name="id" materialize="true">
-          <CtxVarIterator varid="5" varname="external_id" varkind="global"/>
-        </LetVariable>
-        <LetVariable name="$$opt_temp_0" materialize="true">
-          <HoistIterator>
-            <PromoteIterator type="xs:anyAtomicType">
-              <FnDataIterator>
-                <LetVarIterator varname="id"/>
-              </FnDataIterator>
-            </PromoteIterator>
-          </HoistIterator>
-        </LetVariable>
-        <LetVariable name="session" materialize="true">
-          <FLWORIterator>
-            <ForVariable name="session">
-              <NodeSortIterator distinct="false" ascending="true">
-                <ProbeIndexPointValueIterator>
-                  <SingletonIterator value="xs:QName(www.sessions.com,sessions,session-index)"/>
-                  <UnhoistIterator>
-                    <LetVarIterator varname="$$opt_temp_0"/>
-                  </UnhoistIterator>
-                </ProbeIndexPointValueIterator>
-              </NodeSortIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ForVarIterator varname="session"/>
-            </ReturnClause>
-          </FLWORIterator>
-        </LetVariable>
+        <ForVariable name="s">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,session)" typename="*" nill allowed="0">
+            <CtxVarIterator varid="6" varname="doc" varkind="global"/>
+          </ChildAxisIterator>
+        </ForVariable>
+        <MaterializeClause>
+          <MaterializeForVariable inputVar="s : "/>
+        </MaterializeClause>
         <ReturnClause>
-          <IfThenElseIterator>
-            <FnEmptyIterator>
-              <LetVarIterator varname="session"/>
-            </FnEmptyIterator>
-            <TraceIterator>
-              <LetVarIterator varname="id"/>
-              <SingletonIterator value="xs:string(no session with the given uuid)"/>
-            </TraceIterator>
-            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,data)" typename="*" nill allowed="0">
-              <LetVarIterator varname="session"/>
-            </ChildAxisIterator>
-          </IfThenElseIterator>
+          <ApplyIterator>
+            <ZorbaInsertIterator need-to-copy="true">
+              <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
+              <ForVarIterator varname="s"/>
+            </ZorbaInsertIterator>
+          </ApplyIterator>
         </ReturnClause>
       </FLWORIterator>
-      <SingletonIterator value="xs:string(
+      <FnConcatIterator>
+        <FLWORIterator>
+          <LetVariable name="id" materialize="true">
+            <CtxVarIterator varid="5" varname="external_id" varkind="global"/>
+          </LetVariable>
+          <LetVariable name="$$opt_temp_0" materialize="true">
+            <HoistIterator>
+              <PromoteIterator type="xs:anyAtomicType">
+                <FnDataIterator>
+                  <LetVarIterator varname="id"/>
+                </FnDataIterator>
+              </PromoteIterator>
+            </HoistIterator>
+          </LetVariable>
+          <LetVariable name="session" materialize="true">
+            <FLWORIterator>
+              <ForVariable name="session">
+                <NodeSortIterator distinct="false" ascending="true">
+                  <ProbeIndexPointValueIterator>
+                    <SingletonIterator value="xs:QName(www.sessions.com,sessions,session-index)"/>
+                    <UnhoistIterator>
+                      <LetVarIterator varname="$$opt_temp_0"/>
+                    </UnhoistIterator>
+                  </ProbeIndexPointValueIterator>
+                </NodeSortIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ForVarIterator varname="session"/>
+              </ReturnClause>
+            </FLWORIterator>
+          </LetVariable>
+          <ReturnClause>
+            <IfThenElseIterator>
+              <FnEmptyIterator>
+                <LetVarIterator varname="session"/>
+              </FnEmptyIterator>
+              <TraceIterator>
+                <LetVarIterator varname="id"/>
+                <SingletonIterator value="xs:string(no session with the given uuid)"/>
+              </TraceIterator>
+              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,data)" typename="*" nill allowed="0">
+                <LetVarIterator varname="session"/>
+              </ChildAxisIterator>
+            </IfThenElseIterator>
+          </ReturnClause>
+        </FLWORIterator>
+        <SingletonIterator value="xs:string(
 )"/>
-    </FnConcatIterator>
+      </FnConcatIterator>
+    </SequentialIterator>
   </SequentialIterator>
-</SequentialIterator>
-
+</iterator-tree>

=== modified file 'test/iterplans/zorba/index/match_veq_03.iter'
--- test/iterplans/zorba/index/match_veq_03.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/index/match_veq_03.iter	2014-02-20 05:31:00 +0000
@@ -1,172 +1,172 @@
-Iterator tree for doc indexer:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <CastIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </CastIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for index:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <ZorbaCollectionIterator>
+<iterator-tree description="doc indexer">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <CastIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </CastIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="index">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <ZorbaCollectionIterator>
+        <SingletonIterator value="xs:QName(www.sessions.com,sessions,sessions)"/>
+      </ZorbaCollectionIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <CastIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </CastIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <CtxVarDeclareIterator varid="4" varname="sessions:sessions">
       <SingletonIterator value="xs:QName(www.sessions.com,sessions,sessions)"/>
-    </ZorbaCollectionIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <CastIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </CastIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="sessions:sessions">
-    <SingletonIterator value="xs:QName(www.sessions.com,sessions,sessions)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="5" varname="external_id">
-    <SingletonIterator value="xs:string(50)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="6" varname="doc">
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,sessions)"/>
-      <FnConcatIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,session)"/>
-          <AttributeIterator qname="xs:QName(,,id)">
-            <SingletonIterator value="xs:string(50)"/>
-          </AttributeIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,data)"/>
-            <TextIterator>
-              <SingletonIterator value="xs:string(1111111111)"/>
-            </TextIterator>
-          </ElementIterator>
-        </ElementIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,session)"/>
-          <AttributeIterator qname="xs:QName(,,id)">
-            <SingletonIterator value="xs:string(12)"/>
-          </AttributeIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,data)"/>
-            <TextIterator>
-              <SingletonIterator value="xs:string(2222222222)"/>
-            </TextIterator>
-          </ElementIterator>
-        </ElementIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,session)"/>
-          <AttributeIterator qname="xs:QName(,,id)">
-            <SingletonIterator value="xs:string(50)"/>
-          </AttributeIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,data)"/>
-            <TextIterator>
-              <SingletonIterator value="xs:string(3333333333)"/>
-            </TextIterator>
-          </ElementIterator>
-        </ElementIterator>
-      </FnConcatIterator>
-    </ElementIterator>
-  </CtxVarDeclareIterator>
-  <SequentialIterator>
-    <ApplyIterator>
-      <ZorbaCreateCollectionIterator>
-        <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
-      </ZorbaCreateCollectionIterator>
-    </ApplyIterator>
-    <ApplyIterator>
-      <CreateIndexIterator>
-        <SingletonIterator value="xs:QName(www.sessions.com,s,session-index)"/>
-      </CreateIndexIterator>
-    </ApplyIterator>
-    <FLWORIterator>
-      <ForVariable name="s">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,session)" typename="*" nill allowed="0">
-          <CtxVarIterator varid="6" varname="doc" varkind="global"/>
-        </ChildAxisIterator>
-      </ForVariable>
-      <MaterializeClause>
-        <MaterializeForVariable inputVar="s : "/>
-      </MaterializeClause>
-      <ReturnClause>
-        <ApplyIterator>
-          <ZorbaInsertIterator need-to-copy="true">
-            <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
-            <ForVarIterator varname="s"/>
-          </ZorbaInsertIterator>
-        </ApplyIterator>
-      </ReturnClause>
-    </FLWORIterator>
-    <FnConcatIterator>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="5" varname="external_id">
+      <SingletonIterator value="xs:string(50)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="6" varname="doc">
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,sessions)"/>
+        <FnConcatIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,session)"/>
+            <AttributeIterator qname="xs:QName(,,id)">
+              <SingletonIterator value="xs:string(50)"/>
+            </AttributeIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,data)"/>
+              <TextIterator>
+                <SingletonIterator value="xs:string(1111111111)"/>
+              </TextIterator>
+            </ElementIterator>
+          </ElementIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,session)"/>
+            <AttributeIterator qname="xs:QName(,,id)">
+              <SingletonIterator value="xs:string(12)"/>
+            </AttributeIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,data)"/>
+              <TextIterator>
+                <SingletonIterator value="xs:string(2222222222)"/>
+              </TextIterator>
+            </ElementIterator>
+          </ElementIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,session)"/>
+            <AttributeIterator qname="xs:QName(,,id)">
+              <SingletonIterator value="xs:string(50)"/>
+            </AttributeIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,data)"/>
+              <TextIterator>
+                <SingletonIterator value="xs:string(3333333333)"/>
+              </TextIterator>
+            </ElementIterator>
+          </ElementIterator>
+        </FnConcatIterator>
+      </ElementIterator>
+    </CtxVarDeclareIterator>
+    <SequentialIterator>
+      <ApplyIterator>
+        <ZorbaCreateCollectionIterator>
+          <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
+        </ZorbaCreateCollectionIterator>
+      </ApplyIterator>
+      <ApplyIterator>
+        <CreateIndexIterator>
+          <SingletonIterator value="xs:QName(www.sessions.com,s,session-index)"/>
+        </CreateIndexIterator>
+      </ApplyIterator>
       <FLWORIterator>
-        <LetVariable name="id" materialize="true">
-          <CtxVarIterator varid="5" varname="external_id" varkind="global"/>
-        </LetVariable>
-        <LetVariable name="$$opt_temp_0" materialize="true">
-          <HoistIterator>
-            <PromoteIterator type="xs:anyAtomicType">
-              <FnDataIterator>
-                <LetVarIterator varname="id"/>
-              </FnDataIterator>
-            </PromoteIterator>
-          </HoistIterator>
-        </LetVariable>
-        <LetVariable name="session" materialize="true">
-          <FLWORIterator>
-            <ForVariable name="session">
-              <NodeSortIterator distinct="false" ascending="true">
-                <ProbeIndexPointValueIterator>
-                  <SingletonIterator value="xs:QName(www.sessions.com,sessions,session-index)"/>
-                  <UnhoistIterator>
-                    <LetVarIterator varname="$$opt_temp_0"/>
-                  </UnhoistIterator>
-                </ProbeIndexPointValueIterator>
-              </NodeSortIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ForVarIterator varname="session"/>
-            </ReturnClause>
-          </FLWORIterator>
-        </LetVariable>
+        <ForVariable name="s">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,session)" typename="*" nill allowed="0">
+            <CtxVarIterator varid="6" varname="doc" varkind="global"/>
+          </ChildAxisIterator>
+        </ForVariable>
+        <MaterializeClause>
+          <MaterializeForVariable inputVar="s : "/>
+        </MaterializeClause>
         <ReturnClause>
-          <IfThenElseIterator>
-            <FnEmptyIterator>
-              <LetVarIterator varname="session"/>
-            </FnEmptyIterator>
-            <TraceIterator>
-              <LetVarIterator varname="id"/>
-              <SingletonIterator value="xs:string(no session with the given uuid)"/>
-            </TraceIterator>
-            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,data)" typename="*" nill allowed="0">
-              <LetVarIterator varname="session"/>
-            </ChildAxisIterator>
-          </IfThenElseIterator>
+          <ApplyIterator>
+            <ZorbaInsertIterator need-to-copy="true">
+              <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
+              <ForVarIterator varname="s"/>
+            </ZorbaInsertIterator>
+          </ApplyIterator>
         </ReturnClause>
       </FLWORIterator>
-      <SingletonIterator value="xs:string(
+      <FnConcatIterator>
+        <FLWORIterator>
+          <LetVariable name="id" materialize="true">
+            <CtxVarIterator varid="5" varname="external_id" varkind="global"/>
+          </LetVariable>
+          <LetVariable name="$$opt_temp_0" materialize="true">
+            <HoistIterator>
+              <PromoteIterator type="xs:anyAtomicType">
+                <FnDataIterator>
+                  <LetVarIterator varname="id"/>
+                </FnDataIterator>
+              </PromoteIterator>
+            </HoistIterator>
+          </LetVariable>
+          <LetVariable name="session" materialize="true">
+            <FLWORIterator>
+              <ForVariable name="session">
+                <NodeSortIterator distinct="false" ascending="true">
+                  <ProbeIndexPointValueIterator>
+                    <SingletonIterator value="xs:QName(www.sessions.com,sessions,session-index)"/>
+                    <UnhoistIterator>
+                      <LetVarIterator varname="$$opt_temp_0"/>
+                    </UnhoistIterator>
+                  </ProbeIndexPointValueIterator>
+                </NodeSortIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ForVarIterator varname="session"/>
+              </ReturnClause>
+            </FLWORIterator>
+          </LetVariable>
+          <ReturnClause>
+            <IfThenElseIterator>
+              <FnEmptyIterator>
+                <LetVarIterator varname="session"/>
+              </FnEmptyIterator>
+              <TraceIterator>
+                <LetVarIterator varname="id"/>
+                <SingletonIterator value="xs:string(no session with the given uuid)"/>
+              </TraceIterator>
+              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,data)" typename="*" nill allowed="0">
+                <LetVarIterator varname="session"/>
+              </ChildAxisIterator>
+            </IfThenElseIterator>
+          </ReturnClause>
+        </FLWORIterator>
+        <SingletonIterator value="xs:string(
 )"/>
-    </FnConcatIterator>
+      </FnConcatIterator>
+    </SequentialIterator>
   </SequentialIterator>
-</SequentialIterator>
-
+</iterator-tree>

=== modified file 'test/iterplans/zorba/index/match_veq_04.iter'
--- test/iterplans/zorba/index/match_veq_04.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/index/match_veq_04.iter	2014-02-20 05:31:00 +0000
@@ -1,233 +1,233 @@
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for doc indexer:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <FLWORIterator>
-      <ForVariable name="$$context-item">
-        <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
-      </ForVariable>
-      <WhereClause>
-        <CompareIterator>
-          <FnDataIterator>
-            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,duration)" typename="*" nill allowed="0">
-              <ForVarIterator varname="$$context-item"/>
-            </AttributeAxisIterator>
-          </FnDataIterator>
-          <SingletonIterator value="xs:integer(120)"/>
-        </CompareIterator>
-      </WhereClause>
-      <ReturnClause>
-        <ForVarIterator varname="$$context-item"/>
-      </ReturnClause>
-    </FLWORIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <CastIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </CastIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for index:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <FLWORIterator>
-      <ForVariable name="$$context-item">
-        <ZorbaCollectionIterator>
-          <SingletonIterator value="xs:QName(www.sessions.com,sessions,sessions)"/>
-        </ZorbaCollectionIterator>
-      </ForVariable>
-      <WhereClause>
-        <CompareIterator>
-          <FnDataIterator>
-            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,duration)" typename="*" nill allowed="0">
-              <ForVarIterator varname="$$context-item"/>
-            </AttributeAxisIterator>
-          </FnDataIterator>
-          <SingletonIterator value="xs:integer(120)"/>
-        </CompareIterator>
-      </WhereClause>
-      <ReturnClause>
-        <ForVarIterator varname="$$context-item"/>
-      </ReturnClause>
-    </FLWORIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <CastIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </CastIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="sessions:sessions">
-    <SingletonIterator value="xs:QName(www.sessions.com,sessions,sessions)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="5" varname="external_id">
-    <SingletonIterator value="xs:string(50)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="6" varname="doc">
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,sessions)"/>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="doc indexer">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <FLWORIterator>
+        <ForVariable name="$$context-item">
+          <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
+        </ForVariable>
+        <WhereClause>
+          <CompareIterator>
+            <FnDataIterator>
+              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,duration)" typename="*" nill allowed="0">
+                <ForVarIterator varname="$$context-item"/>
+              </AttributeAxisIterator>
+            </FnDataIterator>
+            <SingletonIterator value="xs:integer(120)"/>
+          </CompareIterator>
+        </WhereClause>
+        <ReturnClause>
+          <ForVarIterator varname="$$context-item"/>
+        </ReturnClause>
+      </FLWORIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <CastIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </CastIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="index">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <FLWORIterator>
+        <ForVariable name="$$context-item">
+          <ZorbaCollectionIterator>
+            <SingletonIterator value="xs:QName(www.sessions.com,sessions,sessions)"/>
+          </ZorbaCollectionIterator>
+        </ForVariable>
+        <WhereClause>
+          <CompareIterator>
+            <FnDataIterator>
+              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,duration)" typename="*" nill allowed="0">
+                <ForVarIterator varname="$$context-item"/>
+              </AttributeAxisIterator>
+            </FnDataIterator>
+            <SingletonIterator value="xs:integer(120)"/>
+          </CompareIterator>
+        </WhereClause>
+        <ReturnClause>
+          <ForVarIterator varname="$$context-item"/>
+        </ReturnClause>
+      </FLWORIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <CastIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </CastIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <CtxVarDeclareIterator varid="4" varname="sessions:sessions">
+      <SingletonIterator value="xs:QName(www.sessions.com,sessions,sessions)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="5" varname="external_id">
+      <SingletonIterator value="xs:string(50)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="6" varname="doc">
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,sessions)"/>
+        <FnConcatIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,session)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,id)">
+                <SingletonIterator value="xs:string(50)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,duration)">
+                <SingletonIterator value="xs:string(130)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,data)"/>
+              <TextIterator>
+                <SingletonIterator value="xs:string(1111111111)"/>
+              </TextIterator>
+            </ElementIterator>
+          </ElementIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,session)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,id)">
+                <SingletonIterator value="xs:string(12)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,duration)">
+                <SingletonIterator value="xs:string(30)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,data)"/>
+              <TextIterator>
+                <SingletonIterator value="xs:string(2222222222)"/>
+              </TextIterator>
+            </ElementIterator>
+          </ElementIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,session)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,id)">
+                <SingletonIterator value="xs:string(50)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,duration)">
+                <SingletonIterator value="xs:string(150)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,data)"/>
+              <TextIterator>
+                <SingletonIterator value="xs:string(3333333333)"/>
+              </TextIterator>
+            </ElementIterator>
+          </ElementIterator>
+        </FnConcatIterator>
+      </ElementIterator>
+    </CtxVarDeclareIterator>
+    <SequentialIterator>
+      <ApplyIterator>
+        <ZorbaCreateCollectionIterator>
+          <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
+        </ZorbaCreateCollectionIterator>
+      </ApplyIterator>
+      <ApplyIterator>
+        <CreateIndexIterator>
+          <SingletonIterator value="xs:QName(www.sessions.com,s,session-index)"/>
+        </CreateIndexIterator>
+      </ApplyIterator>
+      <FLWORIterator>
+        <ForVariable name="s">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,session)" typename="*" nill allowed="0">
+            <CtxVarIterator varid="6" varname="doc" varkind="global"/>
+          </ChildAxisIterator>
+        </ForVariable>
+        <MaterializeClause>
+          <MaterializeForVariable inputVar="s : "/>
+        </MaterializeClause>
+        <ReturnClause>
+          <ApplyIterator>
+            <ZorbaInsertIterator need-to-copy="true">
+              <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
+              <ForVarIterator varname="s"/>
+            </ZorbaInsertIterator>
+          </ApplyIterator>
+        </ReturnClause>
+      </FLWORIterator>
       <FnConcatIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,session)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,id)">
-              <SingletonIterator value="xs:string(50)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,duration)">
-              <SingletonIterator value="xs:string(130)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,data)"/>
-            <TextIterator>
-              <SingletonIterator value="xs:string(1111111111)"/>
-            </TextIterator>
-          </ElementIterator>
-        </ElementIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,session)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,id)">
-              <SingletonIterator value="xs:string(12)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,duration)">
-              <SingletonIterator value="xs:string(30)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,data)"/>
-            <TextIterator>
-              <SingletonIterator value="xs:string(2222222222)"/>
-            </TextIterator>
-          </ElementIterator>
-        </ElementIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,session)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,id)">
-              <SingletonIterator value="xs:string(50)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,duration)">
-              <SingletonIterator value="xs:string(150)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,data)"/>
-            <TextIterator>
-              <SingletonIterator value="xs:string(3333333333)"/>
-            </TextIterator>
-          </ElementIterator>
-        </ElementIterator>
-      </FnConcatIterator>
-    </ElementIterator>
-  </CtxVarDeclareIterator>
-  <SequentialIterator>
-    <ApplyIterator>
-      <ZorbaCreateCollectionIterator>
-        <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
-      </ZorbaCreateCollectionIterator>
-    </ApplyIterator>
-    <ApplyIterator>
-      <CreateIndexIterator>
-        <SingletonIterator value="xs:QName(www.sessions.com,s,session-index)"/>
-      </CreateIndexIterator>
-    </ApplyIterator>
-    <FLWORIterator>
-      <ForVariable name="s">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,session)" typename="*" nill allowed="0">
-          <CtxVarIterator varid="6" varname="doc" varkind="global"/>
-        </ChildAxisIterator>
-      </ForVariable>
-      <MaterializeClause>
-        <MaterializeForVariable inputVar="s : "/>
-      </MaterializeClause>
-      <ReturnClause>
-        <ApplyIterator>
-          <ZorbaInsertIterator need-to-copy="true">
-            <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
-            <ForVarIterator varname="s"/>
-          </ZorbaInsertIterator>
-        </ApplyIterator>
-      </ReturnClause>
-    </FLWORIterator>
-    <FnConcatIterator>
-      <FLWORIterator>
-        <LetVariable name="id" materialize="true">
-          <CtxVarIterator varid="5" varname="external_id" varkind="global"/>
-        </LetVariable>
-        <LetVariable name="$$opt_temp_0" materialize="true">
-          <HoistIterator>
-            <PromoteIterator type="xs:anyAtomicType">
-              <FnDataIterator>
+        <FLWORIterator>
+          <LetVariable name="id" materialize="true">
+            <CtxVarIterator varid="5" varname="external_id" varkind="global"/>
+          </LetVariable>
+          <LetVariable name="$$opt_temp_0" materialize="true">
+            <HoistIterator>
+              <PromoteIterator type="xs:anyAtomicType">
+                <FnDataIterator>
+                  <LetVarIterator varname="id"/>
+                </FnDataIterator>
+              </PromoteIterator>
+            </HoistIterator>
+          </LetVariable>
+          <LetVariable name="session" materialize="true">
+            <FLWORIterator>
+              <ForVariable name="$$context-item">
+                <ProbeIndexPointValueIterator>
+                  <SingletonIterator value="xs:QName(www.sessions.com,sessions,session-index)"/>
+                  <UnhoistIterator>
+                    <LetVarIterator varname="$$opt_temp_0"/>
+                  </UnhoistIterator>
+                </ProbeIndexPointValueIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ForVarIterator varname="$$context-item"/>
+              </ReturnClause>
+            </FLWORIterator>
+          </LetVariable>
+          <ReturnClause>
+            <IfThenElseIterator>
+              <FnEmptyIterator>
+                <LetVarIterator varname="session"/>
+              </FnEmptyIterator>
+              <TraceIterator>
                 <LetVarIterator varname="id"/>
-              </FnDataIterator>
-            </PromoteIterator>
-          </HoistIterator>
-        </LetVariable>
-        <LetVariable name="session" materialize="true">
-          <FLWORIterator>
-            <ForVariable name="$$context-item">
-              <ProbeIndexPointValueIterator>
-                <SingletonIterator value="xs:QName(www.sessions.com,sessions,session-index)"/>
-                <UnhoistIterator>
-                  <LetVarIterator varname="$$opt_temp_0"/>
-                </UnhoistIterator>
-              </ProbeIndexPointValueIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ForVarIterator varname="$$context-item"/>
-            </ReturnClause>
-          </FLWORIterator>
-        </LetVariable>
-        <ReturnClause>
-          <IfThenElseIterator>
-            <FnEmptyIterator>
-              <LetVarIterator varname="session"/>
-            </FnEmptyIterator>
-            <TraceIterator>
-              <LetVarIterator varname="id"/>
-              <SingletonIterator value="xs:string(no session with the given uuid)"/>
-            </TraceIterator>
-            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,data)" typename="*" nill allowed="0">
-              <LetVarIterator varname="session"/>
-            </ChildAxisIterator>
-          </IfThenElseIterator>
-        </ReturnClause>
-      </FLWORIterator>
-      <SingletonIterator value="xs:string(
+                <SingletonIterator value="xs:string(no session with the given uuid)"/>
+              </TraceIterator>
+              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,data)" typename="*" nill allowed="0">
+                <LetVarIterator varname="session"/>
+              </ChildAxisIterator>
+            </IfThenElseIterator>
+          </ReturnClause>
+        </FLWORIterator>
+        <SingletonIterator value="xs:string(
 )"/>
-    </FnConcatIterator>
+      </FnConcatIterator>
+    </SequentialIterator>
   </SequentialIterator>
-</SequentialIterator>
-
+</iterator-tree>

=== modified file 'test/iterplans/zorba/index/match_veq_05.iter'
--- test/iterplans/zorba/index/match_veq_05.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/index/match_veq_05.iter	2014-02-20 05:31:00 +0000
@@ -1,322 +1,322 @@
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for doc indexer:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <FLWORIterator>
-      <ForVariable name="$$context-item">
-        <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
-      </ForVariable>
-      <WhereClause>
-        <CompareIterator>
-          <FnDataIterator>
-            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,duration)" typename="*" nill allowed="0">
-              <ForVarIterator varname="$$context-item"/>
-            </AttributeAxisIterator>
-          </FnDataIterator>
-          <SingletonIterator value="xs:integer(120)"/>
-        </CompareIterator>
-      </WhereClause>
-      <ReturnClause>
-        <ForVarIterator varname="$$context-item"/>
-      </ReturnClause>
-    </FLWORIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </PromoteIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for index:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <FLWORIterator>
-      <ForVariable name="$$context-item">
-        <ZorbaCollectionIterator>
-          <SingletonIterator value="xs:QName(www.sessions.com,sessions,sessions)"/>
-        </ZorbaCollectionIterator>
-      </ForVariable>
-      <WhereClause>
-        <CompareIterator>
-          <FnDataIterator>
-            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,duration)" typename="*" nill allowed="0">
-              <ForVarIterator varname="$$context-item"/>
-            </AttributeAxisIterator>
-          </FnDataIterator>
-          <SingletonIterator value="xs:integer(120)"/>
-        </CompareIterator>
-      </WhereClause>
-      <ReturnClause>
-        <ForVarIterator varname="$$context-item"/>
-      </ReturnClause>
-    </FLWORIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </PromoteIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="sessions:sessions">
-    <SingletonIterator value="xs:QName(www.sessions.com,sessions,sessions)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="5" varname="external_id">
-    <SingletonIterator value="xs:string(50)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="6" varname="doc">
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,sessions)"/>
-      <FnConcatIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,session)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,id)">
-              <SingletonIterator value="xs:string(50)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,duration)">
-              <SingletonIterator value="xs:string(130)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,data)"/>
-            <TextIterator>
-              <SingletonIterator value="xs:string(1111111111)"/>
-            </TextIterator>
-          </ElementIterator>
-        </ElementIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,session)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,id)">
-              <SingletonIterator value="xs:string(12)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,duration)">
-              <SingletonIterator value="xs:string(30)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,data)"/>
-            <TextIterator>
-              <SingletonIterator value="xs:string(2222222222)"/>
-            </TextIterator>
-          </ElementIterator>
-        </ElementIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,session)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,id)">
-              <SingletonIterator value="xs:string(50)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,duration)">
-              <SingletonIterator value="xs:string(150)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,data)"/>
-            <TextIterator>
-              <SingletonIterator value="xs:string(3333333333)"/>
-            </TextIterator>
-          </ElementIterator>
-        </ElementIterator>
-      </FnConcatIterator>
-    </ElementIterator>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="7" varname="doc2">
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,sessions)"/>
-      <FnConcatIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,session)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,id)">
-              <SingletonIterator value="xs:string(50)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,duration)">
-              <SingletonIterator value="xs:string(130)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,data)"/>
-            <TextIterator>
-              <SingletonIterator value="xs:string(6666666)"/>
-            </TextIterator>
-          </ElementIterator>
-        </ElementIterator>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,session)"/>
-          <FnConcatIterator>
-            <AttributeIterator qname="xs:QName(,,id)">
-              <SingletonIterator value="xs:string(70)"/>
-            </AttributeIterator>
-            <AttributeIterator qname="xs:QName(,,duration)">
-              <SingletonIterator value="xs:string(150)"/>
-            </AttributeIterator>
-          </FnConcatIterator>
-          <ElementIterator>
-            <SingletonIterator value="xs:QName(,,data)"/>
-            <TextIterator>
-              <SingletonIterator value="xs:string(7777777)"/>
-            </TextIterator>
-          </ElementIterator>
-        </ElementIterator>
-      </FnConcatIterator>
-    </ElementIterator>
-  </CtxVarDeclareIterator>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="doc indexer">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <FLWORIterator>
+        <ForVariable name="$$context-item">
+          <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
+        </ForVariable>
+        <WhereClause>
+          <CompareIterator>
+            <FnDataIterator>
+              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,duration)" typename="*" nill allowed="0">
+                <ForVarIterator varname="$$context-item"/>
+              </AttributeAxisIterator>
+            </FnDataIterator>
+            <SingletonIterator value="xs:integer(120)"/>
+          </CompareIterator>
+        </WhereClause>
+        <ReturnClause>
+          <ForVarIterator varname="$$context-item"/>
+        </ReturnClause>
+      </FLWORIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </PromoteIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="index">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <FLWORIterator>
+        <ForVariable name="$$context-item">
+          <ZorbaCollectionIterator>
+            <SingletonIterator value="xs:QName(www.sessions.com,sessions,sessions)"/>
+          </ZorbaCollectionIterator>
+        </ForVariable>
+        <WhereClause>
+          <CompareIterator>
+            <FnDataIterator>
+              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,duration)" typename="*" nill allowed="0">
+                <ForVarIterator varname="$$context-item"/>
+              </AttributeAxisIterator>
+            </FnDataIterator>
+            <SingletonIterator value="xs:integer(120)"/>
+          </CompareIterator>
+        </WhereClause>
+        <ReturnClause>
+          <ForVarIterator varname="$$context-item"/>
+        </ReturnClause>
+      </FLWORIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </PromoteIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="main query">
   <SequentialIterator>
-    <ApplyIterator>
-      <ZorbaCreateCollectionIterator>
-        <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
-      </ZorbaCreateCollectionIterator>
-    </ApplyIterator>
-    <ApplyIterator>
-      <CreateIndexIterator>
-        <SingletonIterator value="xs:QName(www.sessions.com,s,session-index)"/>
-      </CreateIndexIterator>
-    </ApplyIterator>
-    <FLWORIterator>
-      <ForVariable name="s">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,session)" typename="*" nill allowed="0">
-          <CtxVarIterator varid="6" varname="doc" varkind="global"/>
-        </ChildAxisIterator>
-      </ForVariable>
-      <MaterializeClause>
-        <MaterializeForVariable inputVar="s : "/>
-      </MaterializeClause>
-      <ReturnClause>
-        <ApplyIterator>
-          <ZorbaInsertIterator need-to-copy="true">
-            <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
-            <ForVarIterator varname="s"/>
-          </ZorbaInsertIterator>
-        </ApplyIterator>
-      </ReturnClause>
-    </FLWORIterator>
-    <FLWORIterator>
-      <ForVariable name="s">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,session)" typename="*" nill allowed="0">
-          <CtxVarIterator varid="7" varname="doc2" varkind="global"/>
-        </ChildAxisIterator>
-      </ForVariable>
-      <MaterializeClause>
-        <MaterializeForVariable inputVar="s : "/>
-      </MaterializeClause>
-      <ReturnClause>
-        <ApplyIterator>
-          <ZorbaInsertFirstIterator need-to-copy="true">
-            <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
-            <ForVarIterator varname="s"/>
-          </ZorbaInsertFirstIterator>
-        </ApplyIterator>
-      </ReturnClause>
-    </FLWORIterator>
-    <FLWORIterator>
-      <ForVariable name="s">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,session)" typename="*" nill allowed="0">
-          <CtxVarIterator varid="7" varname="doc2" varkind="global"/>
-        </ChildAxisIterator>
-      </ForVariable>
-      <MaterializeClause>
-        <MaterializeForVariable inputVar="s : "/>
-      </MaterializeClause>
-      <ReturnClause>
-        <ApplyIterator>
-          <ZorbaInsertLastIterator need-to-copy="true">
-            <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
-            <ForVarIterator varname="s"/>
-          </ZorbaInsertLastIterator>
-        </ApplyIterator>
-      </ReturnClause>
-    </FLWORIterator>
-    <FnConcatIterator>
-      <FLWORIterator>
-        <LetVariable name="id" materialize="true">
-          <CtxVarIterator varid="5" varname="external_id" varkind="global"/>
-        </LetVariable>
-        <LetVariable name="$$opt_temp_0" materialize="true">
-          <HoistIterator>
-            <PromoteIterator type="xs:anyAtomicType">
-              <FnDataIterator>
-                <LetVarIterator varname="id"/>
-              </FnDataIterator>
-            </PromoteIterator>
-          </HoistIterator>
-        </LetVariable>
-        <LetVariable name="session" materialize="true">
-          <FLWORIterator>
-            <ForVariable name="$$context-item">
-              <NodeSortIterator distinct="false" ascending="true">
-                <ProbeIndexPointValueIterator>
-                  <SingletonIterator value="xs:QName(www.sessions.com,sessions,session-index)"/>
-                  <UnhoistIterator>
-                    <LetVarIterator varname="$$opt_temp_0"/>
-                  </UnhoistIterator>
-                </ProbeIndexPointValueIterator>
-              </NodeSortIterator>
-            </ForVariable>
-            <WhereClause>
-              <CompareIterator>
+    <CtxVarDeclareIterator varid="4" varname="sessions:sessions">
+      <SingletonIterator value="xs:QName(www.sessions.com,sessions,sessions)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="5" varname="external_id">
+      <SingletonIterator value="xs:string(50)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="6" varname="doc">
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,sessions)"/>
+        <FnConcatIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,session)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,id)">
+                <SingletonIterator value="xs:string(50)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,duration)">
+                <SingletonIterator value="xs:string(130)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,data)"/>
+              <TextIterator>
+                <SingletonIterator value="xs:string(1111111111)"/>
+              </TextIterator>
+            </ElementIterator>
+          </ElementIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,session)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,id)">
+                <SingletonIterator value="xs:string(12)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,duration)">
+                <SingletonIterator value="xs:string(30)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,data)"/>
+              <TextIterator>
+                <SingletonIterator value="xs:string(2222222222)"/>
+              </TextIterator>
+            </ElementIterator>
+          </ElementIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,session)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,id)">
+                <SingletonIterator value="xs:string(50)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,duration)">
+                <SingletonIterator value="xs:string(150)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,data)"/>
+              <TextIterator>
+                <SingletonIterator value="xs:string(3333333333)"/>
+              </TextIterator>
+            </ElementIterator>
+          </ElementIterator>
+        </FnConcatIterator>
+      </ElementIterator>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="7" varname="doc2">
+      <ElementIterator>
+        <SingletonIterator value="xs:QName(,,sessions)"/>
+        <FnConcatIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,session)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,id)">
+                <SingletonIterator value="xs:string(50)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,duration)">
+                <SingletonIterator value="xs:string(130)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,data)"/>
+              <TextIterator>
+                <SingletonIterator value="xs:string(6666666)"/>
+              </TextIterator>
+            </ElementIterator>
+          </ElementIterator>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,session)"/>
+            <FnConcatIterator>
+              <AttributeIterator qname="xs:QName(,,id)">
+                <SingletonIterator value="xs:string(70)"/>
+              </AttributeIterator>
+              <AttributeIterator qname="xs:QName(,,duration)">
+                <SingletonIterator value="xs:string(150)"/>
+              </AttributeIterator>
+            </FnConcatIterator>
+            <ElementIterator>
+              <SingletonIterator value="xs:QName(,,data)"/>
+              <TextIterator>
+                <SingletonIterator value="xs:string(7777777)"/>
+              </TextIterator>
+            </ElementIterator>
+          </ElementIterator>
+        </FnConcatIterator>
+      </ElementIterator>
+    </CtxVarDeclareIterator>
+    <SequentialIterator>
+      <ApplyIterator>
+        <ZorbaCreateCollectionIterator>
+          <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
+        </ZorbaCreateCollectionIterator>
+      </ApplyIterator>
+      <ApplyIterator>
+        <CreateIndexIterator>
+          <SingletonIterator value="xs:QName(www.sessions.com,s,session-index)"/>
+        </CreateIndexIterator>
+      </ApplyIterator>
+      <FLWORIterator>
+        <ForVariable name="s">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,session)" typename="*" nill allowed="0">
+            <CtxVarIterator varid="6" varname="doc" varkind="global"/>
+          </ChildAxisIterator>
+        </ForVariable>
+        <MaterializeClause>
+          <MaterializeForVariable inputVar="s : "/>
+        </MaterializeClause>
+        <ReturnClause>
+          <ApplyIterator>
+            <ZorbaInsertIterator need-to-copy="true">
+              <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
+              <ForVarIterator varname="s"/>
+            </ZorbaInsertIterator>
+          </ApplyIterator>
+        </ReturnClause>
+      </FLWORIterator>
+      <FLWORIterator>
+        <ForVariable name="s">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,session)" typename="*" nill allowed="0">
+            <CtxVarIterator varid="7" varname="doc2" varkind="global"/>
+          </ChildAxisIterator>
+        </ForVariable>
+        <MaterializeClause>
+          <MaterializeForVariable inputVar="s : "/>
+        </MaterializeClause>
+        <ReturnClause>
+          <ApplyIterator>
+            <ZorbaInsertFirstIterator need-to-copy="true">
+              <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
+              <ForVarIterator varname="s"/>
+            </ZorbaInsertFirstIterator>
+          </ApplyIterator>
+        </ReturnClause>
+      </FLWORIterator>
+      <FLWORIterator>
+        <ForVariable name="s">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,session)" typename="*" nill allowed="0">
+            <CtxVarIterator varid="7" varname="doc2" varkind="global"/>
+          </ChildAxisIterator>
+        </ForVariable>
+        <MaterializeClause>
+          <MaterializeForVariable inputVar="s : "/>
+        </MaterializeClause>
+        <ReturnClause>
+          <ApplyIterator>
+            <ZorbaInsertLastIterator need-to-copy="true">
+              <CtxVarIterator varid="4" varname="sessions:sessions" varkind="global"/>
+              <ForVarIterator varname="s"/>
+            </ZorbaInsertLastIterator>
+          </ApplyIterator>
+        </ReturnClause>
+      </FLWORIterator>
+      <FnConcatIterator>
+        <FLWORIterator>
+          <LetVariable name="id" materialize="true">
+            <CtxVarIterator varid="5" varname="external_id" varkind="global"/>
+          </LetVariable>
+          <LetVariable name="$$opt_temp_0" materialize="true">
+            <HoistIterator>
+              <PromoteIterator type="xs:anyAtomicType">
                 <FnDataIterator>
-                  <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,duration)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="$$context-item"/>
-                  </AttributeAxisIterator>
+                  <LetVarIterator varname="id"/>
                 </FnDataIterator>
-                <SingletonIterator value="xs:integer(150)"/>
-              </CompareIterator>
-            </WhereClause>
-            <ReturnClause>
-              <ForVarIterator varname="$$context-item"/>
-            </ReturnClause>
-          </FLWORIterator>
-        </LetVariable>
-        <ReturnClause>
-          <IfThenElseIterator>
-            <FnEmptyIterator>
-              <LetVarIterator varname="session"/>
-            </FnEmptyIterator>
-            <TraceIterator>
-              <LetVarIterator varname="id"/>
-              <SingletonIterator value="xs:string(no session with the given uuid)"/>
-            </TraceIterator>
-            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,data)" typename="*" nill allowed="0">
-              <LetVarIterator varname="session"/>
-            </ChildAxisIterator>
-          </IfThenElseIterator>
-        </ReturnClause>
-      </FLWORIterator>
-      <SingletonIterator value="xs:string(
+              </PromoteIterator>
+            </HoistIterator>
+          </LetVariable>
+          <LetVariable name="session" materialize="true">
+            <FLWORIterator>
+              <ForVariable name="$$context-item">
+                <NodeSortIterator distinct="false" ascending="true">
+                  <ProbeIndexPointValueIterator>
+                    <SingletonIterator value="xs:QName(www.sessions.com,sessions,session-index)"/>
+                    <UnhoistIterator>
+                      <LetVarIterator varname="$$opt_temp_0"/>
+                    </UnhoistIterator>
+                  </ProbeIndexPointValueIterator>
+                </NodeSortIterator>
+              </ForVariable>
+              <WhereClause>
+                <CompareIterator>
+                  <FnDataIterator>
+                    <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,duration)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$context-item"/>
+                    </AttributeAxisIterator>
+                  </FnDataIterator>
+                  <SingletonIterator value="xs:integer(150)"/>
+                </CompareIterator>
+              </WhereClause>
+              <ReturnClause>
+                <ForVarIterator varname="$$context-item"/>
+              </ReturnClause>
+            </FLWORIterator>
+          </LetVariable>
+          <ReturnClause>
+            <IfThenElseIterator>
+              <FnEmptyIterator>
+                <LetVarIterator varname="session"/>
+              </FnEmptyIterator>
+              <TraceIterator>
+                <LetVarIterator varname="id"/>
+                <SingletonIterator value="xs:string(no session with the given uuid)"/>
+              </TraceIterator>
+              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,data)" typename="*" nill allowed="0">
+                <LetVarIterator varname="session"/>
+              </ChildAxisIterator>
+            </IfThenElseIterator>
+          </ReturnClause>
+        </FLWORIterator>
+        <SingletonIterator value="xs:string(
 )"/>
-    </FnConcatIterator>
+      </FnConcatIterator>
+    </SequentialIterator>
   </SequentialIterator>
-</SequentialIterator>
-
+</iterator-tree>

=== modified file 'test/iterplans/zorba/index/match_veq_06.iter'
--- test/iterplans/zorba/index/match_veq_06.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/index/match_veq_06.iter	2014-02-20 05:31:00 +0000
@@ -1,320 +1,320 @@
-Iterator tree for doc indexer:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,uri)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </PromoteIterator>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,child)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </PromoteIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for index:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <ZorbaCollectionIterator>
-      <SingletonIterator value="xs:QName(www.data.com,data,parents)"/>
-    </ZorbaCollectionIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,uri)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </PromoteIterator>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,child)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </PromoteIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for const-folded expr:
-<SingletonIterator value="xs:boolean(true)"/>
-
-Iterator tree for const-folded expr:
-<SingletonIterator value="xs:boolean(false)"/>
-
-Iterator tree for const-folded expr:
-<CastIterator type="xs:anyURI">
-  <SingletonIterator value="xs:string(http://www.xmlteam.com/zorba/repo/index)"/>
-</CastIterator>
-
-Iterator tree for const-folded expr:
-<SingletonIterator value="xs:boolean(true)"/>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="data:parents">
-    <SingletonIterator value="xs:QName(www.data.com,data,parents)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="5" varname="data:idx">
-    <SingletonIterator value="xs:QName(www.data.com,data,idx)"/>
-  </CtxVarDeclareIterator>
-  <SequentialIterator>
-    <ApplyIterator>
-      <ZorbaCreateCollectionIterator>
-        <CtxVarIterator varid="4" varname="data:parents" varkind="global"/>
-      </ZorbaCreateCollectionIterator>
-    </ApplyIterator>
-    <ApplyIterator>
-      <CreateIndexIterator>
-        <CtxVarIterator varid="5" varname="data:idx" varkind="global"/>
-      </CreateIndexIterator>
-    </ApplyIterator>
-    <ApplyIterator>
-      <UDFunctionCallIterator function="data:add-document">
-        <SingletonIterator value="xs:anyURI(http://www.xmlteam.com/zorba/repo/index)"/>
-        <SingletonIterator value="xs:boolean(true)"/>
-      </UDFunctionCallIterator>
-    </ApplyIterator>
-    <FnConcatIterator>
+<iterator-tree description="doc indexer">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,uri)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </PromoteIterator>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,child)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </PromoteIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="index">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
       <ZorbaCollectionIterator>
-        <CtxVarIterator varid="4" varname="data:parents" varkind="global"/>
+        <SingletonIterator value="xs:QName(www.data.com,data,parents)"/>
       </ZorbaCollectionIterator>
-      <SingletonIterator value="xs:string(
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,uri)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </PromoteIterator>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,child)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </PromoteIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <SingletonIterator value="xs:boolean(true)"/>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <SingletonIterator value="xs:boolean(false)"/>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <CastIterator type="xs:anyURI">
+    <SingletonIterator value="xs:string(http://www.xmlteam.com/zorba/repo/index)"/>
+  </CastIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <SingletonIterator value="xs:boolean(true)"/>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <CtxVarDeclareIterator varid="4" varname="data:parents">
+      <SingletonIterator value="xs:QName(www.data.com,data,parents)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="5" varname="data:idx">
+      <SingletonIterator value="xs:QName(www.data.com,data,idx)"/>
+    </CtxVarDeclareIterator>
+    <SequentialIterator>
+      <ApplyIterator>
+        <ZorbaCreateCollectionIterator>
+          <CtxVarIterator varid="4" varname="data:parents" varkind="global"/>
+        </ZorbaCreateCollectionIterator>
+      </ApplyIterator>
+      <ApplyIterator>
+        <CreateIndexIterator>
+          <CtxVarIterator varid="5" varname="data:idx" varkind="global"/>
+        </CreateIndexIterator>
+      </ApplyIterator>
+      <ApplyIterator>
+        <UDFunctionCallIterator function="data:add-document">
+          <SingletonIterator value="xs:anyURI(http://www.xmlteam.com/zorba/repo/index)"/>
+          <SingletonIterator value="xs:boolean(true)"/>
+        </UDFunctionCallIterator>
+      </ApplyIterator>
+      <FnConcatIterator>
+        <ZorbaCollectionIterator>
+          <CtxVarIterator varid="4" varname="data:parents" varkind="global"/>
+        </ZorbaCollectionIterator>
+        <SingletonIterator value="xs:string(
 )"/>
-    </FnConcatIterator>
+      </FnConcatIterator>
+    </SequentialIterator>
   </SequentialIterator>
-</SequentialIterator>
-
-Iterator tree for data:add-document:
-<FLWORIterator>
-  <ForVariable name="docURI">
-    <LetVarIterator varname="docURI"/>
-  </ForVariable>
-  <ForVariable name="overwrite">
-    <LetVarIterator varname="overwrite"/>
-  </ForVariable>
-  <MaterializeClause>
-    <MaterializeForVariable inputVar="docURI : "/>
-    <MaterializeForVariable inputVar="overwrite : "/>
-  </MaterializeClause>
-  <ReturnClause>
-    <SequentialIterator>
-      <CtxVarDeclareIterator varid="1" varname="doc-uri">
-        <SubstringAfterIterator>
-          <PromoteIterator type="xs:string">
-            <ForVarIterator varname="docURI"/>
-          </PromoteIterator>
-          <SingletonIterator value="xs:string(http://www.xmlteam.com)"/>
-        </SubstringAfterIterator>
-      </CtxVarDeclareIterator>
-      <CtxVarDeclareIterator varid="2" varname="segments">
-        <FnTokenizeIterator>
-          <PromoteIterator type="xs:string">
-            <FnDataIterator>
-              <CtxVarIterator varid="1" varname="doc-uri" varkind="local"/>
-            </FnDataIterator>
-          </PromoteIterator>
-          <SingletonIterator value="xs:string(/)"/>
-        </FnTokenizeIterator>
-      </CtxVarDeclareIterator>
-      <FLWORIterator>
-        <ForVariable name="segment">
-          <CtxVarIterator varid="2" varname="segments" varkind="local"/>
-        </ForVariable>
-        <ForVariable name="parent">
-          <StringJoinIterator>
-            <PromoteIterator type="xs:string">
-              <FnDataIterator>
-                <CtxVarIterator varid="2" varname="segments" varkind="local">
-                  <SingletonIterator value="xs:integer(1)"/>
-                  <SpecificNumArithIterator_SubtractOperation_INTEGER>
-                    <ForVarIterator varname="i"/>
-                    <SingletonIterator value="xs:integer(1)"/>
-                  </SpecificNumArithIterator_SubtractOperation_INTEGER>
-                </CtxVarIterator>
-              </FnDataIterator>
-            </PromoteIterator>
-            <SingletonIterator value="xs:string(/)"/>
-          </StringJoinIterator>
-        </ForVariable>
-        <ForVariable name="child">
-          <StringJoinIterator>
-            <PromoteIterator type="xs:string">
-              <FnDataIterator>
-                <CtxVarIterator varid="2" varname="segments" varkind="local">
-                  <SingletonIterator value="xs:integer(1)"/>
-                  <ForVarIterator varname="i"/>
-                </CtxVarIterator>
-              </FnDataIterator>
-            </PromoteIterator>
-            <SingletonIterator value="xs:string(/)"/>
-          </StringJoinIterator>
-        </ForVariable>
-        <WhereClause>
-          <AndIterator>
-            <TypedValueCompareIterator_INTEGER>
-              <ForVarIterator varname="i"/>
-              <SingletonIterator value="xs:integer(1)"/>
-            </TypedValueCompareIterator_INTEGER>
-            <FnEmptyIterator>
-              <ProbeIndexPointValueIterator>
-                <SingletonIterator value="xs:QName(www.data.com,data,idx)"/>
-                <ForVarIterator varname="parent"/>
-                <ForVarIterator varname="child"/>
-              </ProbeIndexPointValueIterator>
-            </FnEmptyIterator>
-          </AndIterator>
-        </WhereClause>
-        <MaterializeClause>
-          <MaterializeForVariable inputVar="parent : "/>
-          <MaterializeForVariable inputVar="child : "/>
-        </MaterializeClause>
-        <ReturnClause>
-          <ApplyIterator>
-            <ZorbaInsertIterator need-to-copy="true">
-              <CtxVarIterator varid="4" varname="data:parents" varkind="global"/>
-              <ElementIterator>
-                <SingletonIterator value="xs:QName(,,parent)"/>
-                <FnConcatIterator>
-                  <AttributeIterator qname="xs:QName(,,uri)">
-                    <EnclosedIterator attr_cont="true">
-                      <ForVarIterator varname="parent"/>
-                    </EnclosedIterator>
-                  </AttributeIterator>
-                  <AttributeIterator qname="xs:QName(,,child)">
-                    <EnclosedIterator attr_cont="true">
-                      <ForVarIterator varname="child"/>
-                    </EnclosedIterator>
-                  </AttributeIterator>
-                </FnConcatIterator>
-              </ElementIterator>
-            </ZorbaInsertIterator>
-          </ApplyIterator>
-        </ReturnClause>
-      </FLWORIterator>
-      <IfThenElseIterator>
-        <AndIterator>
-          <ForVarIterator varname="overwrite"/>
-          <FunctionTraceIterator>
-            <FLWORIterator>
-              <ForVariable name="docURI">
-                <PromoteIterator type="xs:string">
-                  <FnDataIterator>
-                    <CtxVarIterator varid="1" varname="doc-uri" varkind="local"/>
-                  </FnDataIterator>
-                </PromoteIterator>
-              </ForVariable>
-              <ReturnClause>
-                <IfThenElseIterator>
-                  <FnBooleanIterator>
-                    <TryCatchIterator>
-                      <RetrieveDocumentIterator>
-                        <ForVarIterator varname="docURI"/>
-                      </RetrieveDocumentIterator>
-                      <FnConcatIterator/>
-                    </TryCatchIterator>
-                  </FnBooleanIterator>
-                  <SingletonIterator value="xs:boolean(true)"/>
-                  <SingletonIterator value="xs:boolean(false)"/>
-                </IfThenElseIterator>
-              </ReturnClause>
-            </FLWORIterator>
-          </FunctionTraceIterator>
-        </AndIterator>
-        <ApplyIterator>
-          <FunctionTraceIterator>
-            <FLWORIterator>
-              <LetVariable name="tokens" materialize="true">
-                <FnTokenizeIterator>
-                  <SubstringAfterIterator>
-                    <PromoteIterator type="xs:string">
-                      <TraceIterator>
-                        <ForVarIterator varname="docURI"/>
-                        <SingletonIterator value="xs:string(uri)"/>
-                      </TraceIterator>
-                    </PromoteIterator>
-                    <SingletonIterator value="xs:string(http://www.xmlteam.com)"/>
-                  </SubstringAfterIterator>
-                  <SingletonIterator value="xs:string(/)"/>
-                </FnTokenizeIterator>
-              </LetVariable>
-              <ForVariable name="parent-uri">
-                <StringJoinIterator>
-                  <LetVarIterator varname="tokens">
+</iterator-tree>
+<iterator-tree description="data:add-document">
+  <FLWORIterator>
+    <ForVariable name="docURI">
+      <LetVarIterator varname="docURI"/>
+    </ForVariable>
+    <ForVariable name="overwrite">
+      <LetVarIterator varname="overwrite"/>
+    </ForVariable>
+    <MaterializeClause>
+      <MaterializeForVariable inputVar="docURI : "/>
+      <MaterializeForVariable inputVar="overwrite : "/>
+    </MaterializeClause>
+    <ReturnClause>
+      <SequentialIterator>
+        <CtxVarDeclareIterator varid="1" varname="doc-uri">
+          <SubstringAfterIterator>
+            <PromoteIterator type="xs:string">
+              <ForVarIterator varname="docURI"/>
+            </PromoteIterator>
+            <SingletonIterator value="xs:string(http://www.xmlteam.com)"/>
+          </SubstringAfterIterator>
+        </CtxVarDeclareIterator>
+        <CtxVarDeclareIterator varid="2" varname="segments">
+          <FnTokenizeIterator>
+            <PromoteIterator type="xs:string">
+              <FnDataIterator>
+                <CtxVarIterator varid="1" varname="doc-uri" varkind="local"/>
+              </FnDataIterator>
+            </PromoteIterator>
+            <SingletonIterator value="xs:string(/)"/>
+          </FnTokenizeIterator>
+        </CtxVarDeclareIterator>
+        <FLWORIterator>
+          <ForVariable name="segment">
+            <CtxVarIterator varid="2" varname="segments" varkind="local"/>
+          </ForVariable>
+          <ForVariable name="parent">
+            <StringJoinIterator>
+              <PromoteIterator type="xs:string">
+                <FnDataIterator>
+                  <CtxVarIterator varid="2" varname="segments" varkind="local">
                     <SingletonIterator value="xs:integer(1)"/>
                     <SpecificNumArithIterator_SubtractOperation_INTEGER>
-                      <FnCountIterator>
-                        <LetVarIterator varname="tokens"/>
-                      </FnCountIterator>
+                      <ForVarIterator varname="i"/>
                       <SingletonIterator value="xs:integer(1)"/>
                     </SpecificNumArithIterator_SubtractOperation_INTEGER>
-                  </LetVarIterator>
-                  <SingletonIterator value="xs:string(/)"/>
-                </StringJoinIterator>
-              </ForVariable>
-              <ForVariable name="child-uri">
-                <StringJoinIterator>
-                  <LetVarIterator varname="tokens"/>
-                  <SingletonIterator value="xs:string(/)"/>
-                </StringJoinIterator>
-              </ForVariable>
-              <LetVariable name="parent" materialize="true">
+                  </CtxVarIterator>
+                </FnDataIterator>
+              </PromoteIterator>
+              <SingletonIterator value="xs:string(/)"/>
+            </StringJoinIterator>
+          </ForVariable>
+          <ForVariable name="child">
+            <StringJoinIterator>
+              <PromoteIterator type="xs:string">
+                <FnDataIterator>
+                  <CtxVarIterator varid="2" varname="segments" varkind="local">
+                    <SingletonIterator value="xs:integer(1)"/>
+                    <ForVarIterator varname="i"/>
+                  </CtxVarIterator>
+                </FnDataIterator>
+              </PromoteIterator>
+              <SingletonIterator value="xs:string(/)"/>
+            </StringJoinIterator>
+          </ForVariable>
+          <WhereClause>
+            <AndIterator>
+              <TypedValueCompareIterator_INTEGER>
+                <ForVarIterator varname="i"/>
+                <SingletonIterator value="xs:integer(1)"/>
+              </TypedValueCompareIterator_INTEGER>
+              <FnEmptyIterator>
                 <ProbeIndexPointValueIterator>
                   <SingletonIterator value="xs:QName(www.data.com,data,idx)"/>
-                  <ForVarIterator varname="parent-uri"/>
-                  <ForVarIterator varname="child-uri"/>
+                  <ForVarIterator varname="parent"/>
+                  <ForVarIterator varname="child"/>
                 </ProbeIndexPointValueIterator>
-              </LetVariable>
-              <MaterializeClause>
-                <MaterializeForVariable inputVar="parent-uri : "/>
-                <MaterializeForVariable inputVar="child-uri : "/>
-                <MaterializeLetVariable inputVar="parent : "/>
-              </MaterializeClause>
-              <ReturnClause>
-                <SequentialIterator>
-                  <ApplyIterator>
-                    <TraceIterator>
-                      <ForVarIterator varname="parent-uri"/>
-                      <SingletonIterator value="xs:string(parent)"/>
-                    </TraceIterator>
-                  </ApplyIterator>
-                  <ApplyIterator>
-                    <TraceIterator>
-                      <ForVarIterator varname="child-uri"/>
-                      <SingletonIterator value="xs:string(child)"/>
-                    </TraceIterator>
-                  </ApplyIterator>
-                  <ApplyIterator>
-                    <ZorbaDeleteIterator>
-                      <LetVarIterator varname="parent"/>
-                    </ZorbaDeleteIterator>
-                  </ApplyIterator>
-                </SequentialIterator>
-              </ReturnClause>
-            </FLWORIterator>
-          </FunctionTraceIterator>
-        </ApplyIterator>
-        <ApplyIterator>
-          <FnConcatIterator/>
-        </ApplyIterator>
-      </IfThenElseIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</FLWORIterator>
-
+              </FnEmptyIterator>
+            </AndIterator>
+          </WhereClause>
+          <MaterializeClause>
+            <MaterializeForVariable inputVar="parent : "/>
+            <MaterializeForVariable inputVar="child : "/>
+          </MaterializeClause>
+          <ReturnClause>
+            <ApplyIterator>
+              <ZorbaInsertIterator need-to-copy="true">
+                <CtxVarIterator varid="4" varname="data:parents" varkind="global"/>
+                <ElementIterator>
+                  <SingletonIterator value="xs:QName(,,parent)"/>
+                  <FnConcatIterator>
+                    <AttributeIterator qname="xs:QName(,,uri)">
+                      <EnclosedIterator attr_cont="true">
+                        <ForVarIterator varname="parent"/>
+                      </EnclosedIterator>
+                    </AttributeIterator>
+                    <AttributeIterator qname="xs:QName(,,child)">
+                      <EnclosedIterator attr_cont="true">
+                        <ForVarIterator varname="child"/>
+                      </EnclosedIterator>
+                    </AttributeIterator>
+                  </FnConcatIterator>
+                </ElementIterator>
+              </ZorbaInsertIterator>
+            </ApplyIterator>
+          </ReturnClause>
+        </FLWORIterator>
+        <IfThenElseIterator>
+          <AndIterator>
+            <ForVarIterator varname="overwrite"/>
+            <FunctionTraceIterator>
+              <FLWORIterator>
+                <ForVariable name="docURI">
+                  <PromoteIterator type="xs:string">
+                    <FnDataIterator>
+                      <CtxVarIterator varid="1" varname="doc-uri" varkind="local"/>
+                    </FnDataIterator>
+                  </PromoteIterator>
+                </ForVariable>
+                <ReturnClause>
+                  <IfThenElseIterator>
+                    <FnBooleanIterator>
+                      <TryCatchIterator>
+                        <RetrieveDocumentIterator>
+                          <ForVarIterator varname="docURI"/>
+                        </RetrieveDocumentIterator>
+                        <FnConcatIterator/>
+                      </TryCatchIterator>
+                    </FnBooleanIterator>
+                    <SingletonIterator value="xs:boolean(true)"/>
+                    <SingletonIterator value="xs:boolean(false)"/>
+                  </IfThenElseIterator>
+                </ReturnClause>
+              </FLWORIterator>
+            </FunctionTraceIterator>
+          </AndIterator>
+          <ApplyIterator>
+            <FunctionTraceIterator>
+              <FLWORIterator>
+                <LetVariable name="tokens" materialize="true">
+                  <FnTokenizeIterator>
+                    <SubstringAfterIterator>
+                      <PromoteIterator type="xs:string">
+                        <TraceIterator>
+                          <ForVarIterator varname="docURI"/>
+                          <SingletonIterator value="xs:string(uri)"/>
+                        </TraceIterator>
+                      </PromoteIterator>
+                      <SingletonIterator value="xs:string(http://www.xmlteam.com)"/>
+                    </SubstringAfterIterator>
+                    <SingletonIterator value="xs:string(/)"/>
+                  </FnTokenizeIterator>
+                </LetVariable>
+                <ForVariable name="parent-uri">
+                  <StringJoinIterator>
+                    <LetVarIterator varname="tokens">
+                      <SingletonIterator value="xs:integer(1)"/>
+                      <SpecificNumArithIterator_SubtractOperation_INTEGER>
+                        <FnCountIterator>
+                          <LetVarIterator varname="tokens"/>
+                        </FnCountIterator>
+                        <SingletonIterator value="xs:integer(1)"/>
+                      </SpecificNumArithIterator_SubtractOperation_INTEGER>
+                    </LetVarIterator>
+                    <SingletonIterator value="xs:string(/)"/>
+                  </StringJoinIterator>
+                </ForVariable>
+                <ForVariable name="child-uri">
+                  <StringJoinIterator>
+                    <LetVarIterator varname="tokens"/>
+                    <SingletonIterator value="xs:string(/)"/>
+                  </StringJoinIterator>
+                </ForVariable>
+                <LetVariable name="parent" materialize="true">
+                  <ProbeIndexPointValueIterator>
+                    <SingletonIterator value="xs:QName(www.data.com,data,idx)"/>
+                    <ForVarIterator varname="parent-uri"/>
+                    <ForVarIterator varname="child-uri"/>
+                  </ProbeIndexPointValueIterator>
+                </LetVariable>
+                <MaterializeClause>
+                  <MaterializeForVariable inputVar="parent-uri : "/>
+                  <MaterializeForVariable inputVar="child-uri : "/>
+                  <MaterializeLetVariable inputVar="parent : "/>
+                </MaterializeClause>
+                <ReturnClause>
+                  <SequentialIterator>
+                    <ApplyIterator>
+                      <TraceIterator>
+                        <ForVarIterator varname="parent-uri"/>
+                        <SingletonIterator value="xs:string(parent)"/>
+                      </TraceIterator>
+                    </ApplyIterator>
+                    <ApplyIterator>
+                      <TraceIterator>
+                        <ForVarIterator varname="child-uri"/>
+                        <SingletonIterator value="xs:string(child)"/>
+                      </TraceIterator>
+                    </ApplyIterator>
+                    <ApplyIterator>
+                      <ZorbaDeleteIterator>
+                        <LetVarIterator varname="parent"/>
+                      </ZorbaDeleteIterator>
+                    </ApplyIterator>
+                  </SequentialIterator>
+                </ReturnClause>
+              </FLWORIterator>
+            </FunctionTraceIterator>
+          </ApplyIterator>
+          <ApplyIterator>
+            <FnConcatIterator/>
+          </ApplyIterator>
+        </IfThenElseIterator>
+      </SequentialIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/index/match_veq_07.iter'
--- test/iterplans/zorba/index/match_veq_07.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/index/match_veq_07.iter	2014-02-20 05:31:00 +0000
@@ -1,155 +1,155 @@
-Iterator tree for doc indexer:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auction)" typename="*" nill allowed="0">
-      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auctions)" typename="*" nill allowed="0">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
-          <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
-        </ChildAxisIterator>
-      </ChildAxisIterator>
-    </ChildAxisIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
-            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,buyer)" typename="*" nill allowed="0">
-              <ForVarIterator varname="$$context-item"/>
-            </ChildAxisIterator>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </PromoteIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for index:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auction)" typename="*" nill allowed="0">
-      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auctions)" typename="*" nill allowed="0">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
+<iterator-tree description="doc indexer">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auction)" typename="*" nill allowed="0">
+        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auctions)" typename="*" nill allowed="0">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
+            <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
+          </ChildAxisIterator>
+        </ChildAxisIterator>
+      </ChildAxisIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
+              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,buyer)" typename="*" nill allowed="0">
+                <ForVarIterator varname="$$context-item"/>
+              </ChildAxisIterator>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </PromoteIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="index">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auction)" typename="*" nill allowed="0">
+        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auctions)" typename="*" nill allowed="0">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
+            <ZorbaCollectionIterator>
+              <SingletonIterator value="xs:QName(www.xmark.com,x,auctions)"/>
+            </ZorbaCollectionIterator>
+          </ChildAxisIterator>
+        </ChildAxisIterator>
+      </ChildAxisIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
+              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,buyer)" typename="*" nill allowed="0">
+                <ForVarIterator varname="$$context-item"/>
+              </ChildAxisIterator>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </PromoteIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <CtxVarDeclareIterator varid="4" varname="x:auctions">
+      <SingletonIterator value="xs:QName(www.xmark.com,x,auctions)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="5" varname="x:idx">
+      <SingletonIterator value="xs:QName(www.xmark.com,x,idx)"/>
+    </CtxVarDeclareIterator>
+    <SequentialIterator>
+      <ApplyIterator>
+        <ZorbaCreateCollectionIterator>
+          <CtxVarIterator varid="4" varname="x:auctions" varkind="global"/>
+        </ZorbaCreateCollectionIterator>
+      </ApplyIterator>
+      <ApplyIterator>
+        <CreateIndexIterator>
+          <CtxVarIterator varid="5" varname="x:idx" varkind="global"/>
+        </CreateIndexIterator>
+      </ApplyIterator>
+      <ApplyIterator>
+        <ZorbaInsertIterator need-to-copy="true">
+          <CtxVarIterator varid="4" varname="x:auctions" varkind="global"/>
+          <FnDocIterator>
+            <SingletonIterator value="xs:string(auction.xml)"/>
+          </FnDocIterator>
+        </ZorbaInsertIterator>
+      </ApplyIterator>
+      <FLWORIterator>
+        <LetVariable name="auctions" materialize="true">
           <ZorbaCollectionIterator>
-            <SingletonIterator value="xs:QName(www.xmark.com,x,auctions)"/>
+            <CtxVarIterator varid="4" varname="x:auctions" varkind="global"/>
           </ZorbaCollectionIterator>
-        </ChildAxisIterator>
-      </ChildAxisIterator>
-    </ChildAxisIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
-            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,buyer)" typename="*" nill allowed="0">
-              <ForVarIterator varname="$$context-item"/>
+        </LetVariable>
+        <LetVariable name="$$opt_temp_0" materialize="true">
+          <HoistIterator>
+            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auction)" typename="*" nill allowed="0">
+              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auctions)" typename="*" nill allowed="0">
+                <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
+                  <LetVarIterator varname="auctions"/>
+                </ChildAxisIterator>
+              </ChildAxisIterator>
             </ChildAxisIterator>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </PromoteIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="x:auctions">
-    <SingletonIterator value="xs:QName(www.xmark.com,x,auctions)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="5" varname="x:idx">
-    <SingletonIterator value="xs:QName(www.xmark.com,x,idx)"/>
-  </CtxVarDeclareIterator>
-  <SequentialIterator>
-    <ApplyIterator>
-      <ZorbaCreateCollectionIterator>
-        <CtxVarIterator varid="4" varname="x:auctions" varkind="global"/>
-      </ZorbaCreateCollectionIterator>
-    </ApplyIterator>
-    <ApplyIterator>
-      <CreateIndexIterator>
-        <CtxVarIterator varid="5" varname="x:idx" varkind="global"/>
-      </CreateIndexIterator>
-    </ApplyIterator>
-    <ApplyIterator>
-      <ZorbaInsertIterator need-to-copy="true">
-        <CtxVarIterator varid="4" varname="x:auctions" varkind="global"/>
-        <FnDocIterator>
-          <SingletonIterator value="xs:string(auction.xml)"/>
-        </FnDocIterator>
-      </ZorbaInsertIterator>
-    </ApplyIterator>
-    <FLWORIterator>
-      <LetVariable name="auctions" materialize="true">
-        <ZorbaCollectionIterator>
-          <CtxVarIterator varid="4" varname="x:auctions" varkind="global"/>
-        </ZorbaCollectionIterator>
-      </LetVariable>
-      <LetVariable name="$$opt_temp_0" materialize="true">
-        <HoistIterator>
-          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auction)" typename="*" nill allowed="0">
-            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,closed_auctions)" typename="*" nill allowed="0">
+          </HoistIterator>
+        </LetVariable>
+        <ForVariable name="p">
+          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
+            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,people)" typename="*" nill allowed="0">
               <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
                 <LetVarIterator varname="auctions"/>
               </ChildAxisIterator>
             </ChildAxisIterator>
           </ChildAxisIterator>
-        </HoistIterator>
-      </LetVariable>
-      <ForVariable name="p">
-        <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,person)" typename="*" nill allowed="0">
-          <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,people)" typename="*" nill allowed="0">
-            <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,site)" typename="*" nill allowed="0">
-              <LetVarIterator varname="auctions"/>
-            </ChildAxisIterator>
-          </ChildAxisIterator>
-        </ChildAxisIterator>
-      </ForVariable>
-      <LetVariable name="$$opt_temp_1" materialize="true">
-        <HoistIterator>
-          <FnDataIterator>
-            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-              <ForVarIterator varname="p"/>
-            </AttributeAxisIterator>
-          </FnDataIterator>
-        </HoistIterator>
-      </LetVariable>
-      <ReturnClause>
-        <ElementIterator>
-          <SingletonIterator value="xs:QName(,,item)"/>
-          <AttributeIterator qname="xs:QName(,,person)">
-            <EnclosedIterator attr_cont="true">
-              <FnDataIterator>
-                <ChildAxisIterator test kind="match_text_test" qname="*" typename="*" nill allowed="0">
-                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
-                    <ForVarIterator varname="p"/>
+        </ForVariable>
+        <LetVariable name="$$opt_temp_1" materialize="true">
+          <HoistIterator>
+            <FnDataIterator>
+              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+                <ForVarIterator varname="p"/>
+              </AttributeAxisIterator>
+            </FnDataIterator>
+          </HoistIterator>
+        </LetVariable>
+        <ReturnClause>
+          <ElementIterator>
+            <SingletonIterator value="xs:QName(,,item)"/>
+            <AttributeIterator qname="xs:QName(,,person)">
+              <EnclosedIterator attr_cont="true">
+                <FnDataIterator>
+                  <ChildAxisIterator test kind="match_text_test" qname="*" typename="*" nill allowed="0">
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="p"/>
+                    </ChildAxisIterator>
                   </ChildAxisIterator>
-                </ChildAxisIterator>
-              </FnDataIterator>
+                </FnDataIterator>
+              </EnclosedIterator>
+            </AttributeIterator>
+            <EnclosedIterator attr_cont="false">
+              <FnCountIterator>
+                <FLWORIterator>
+                  <ForVariable name="t">
+                    <ProbeIndexPointValueIterator>
+                      <SingletonIterator value="xs:QName(www.xmark.com,x,idx)"/>
+                      <UnhoistIterator>
+                        <LetVarIterator varname="$$opt_temp_1"/>
+                      </UnhoistIterator>
+                    </ProbeIndexPointValueIterator>
+                  </ForVariable>
+                  <ReturnClause>
+                    <ForVarIterator varname="t"/>
+                  </ReturnClause>
+                </FLWORIterator>
+              </FnCountIterator>
             </EnclosedIterator>
-          </AttributeIterator>
-          <EnclosedIterator attr_cont="false">
-            <FnCountIterator>
-              <FLWORIterator>
-                <ForVariable name="t">
-                  <ProbeIndexPointValueIterator>
-                    <SingletonIterator value="xs:QName(www.xmark.com,x,idx)"/>
-                    <UnhoistIterator>
-                      <LetVarIterator varname="$$opt_temp_1"/>
-                    </UnhoistIterator>
-                  </ProbeIndexPointValueIterator>
-                </ForVariable>
-                <ReturnClause>
-                  <ForVarIterator varname="t"/>
-                </ReturnClause>
-              </FLWORIterator>
-            </FnCountIterator>
-          </EnclosedIterator>
-        </ElementIterator>
-      </ReturnClause>
-    </FLWORIterator>
+          </ElementIterator>
+        </ReturnClause>
+      </FLWORIterator>
+    </SequentialIterator>
   </SequentialIterator>
-</SequentialIterator>
-
+</iterator-tree>

=== modified file 'test/iterplans/zorba/index/match_veq_08b.iter'
--- test/iterplans/zorba/index/match_veq_08b.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/index/match_veq_08b.iter	2014-02-20 05:31:00 +0000
@@ -1,113 +1,113 @@
-Iterator tree for index:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <ZorbaCollectionIterator>
-      <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
-    </ZorbaCollectionIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <SingleObjectLookupIterator>
-            <ForVarIterator varname="$$context-item"/>
-            <SingletonIterator value="xs:string(question_id)"/>
-          </SingleObjectLookupIterator>
-        </FnDataIterator>
-      </PromoteIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <ApplyIterator>
-    <ZorbaCreateCollectionIterator>
-      <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
-    </ZorbaCreateCollectionIterator>
-  </ApplyIterator>
-  <ApplyIterator>
-    <ZorbaCreateCollectionIterator>
-      <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
-    </ZorbaCreateCollectionIterator>
-  </ApplyIterator>
-  <ApplyIterator>
-    <CreateIndexIterator>
-      <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
-    </CreateIndexIterator>
-  </ApplyIterator>
-  <TupleStreamIterator>
-    <OrderByIterator>
-      <OrderByForVariable inputVar="id : "/>
-      <OrderByForVariable inputVar="count : "/>
-      <OrderBySpec>
+<iterator-tree description="index">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <ZorbaCollectionIterator>
+        <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
+      </ZorbaCollectionIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <SingleObjectLookupIterator>
+              <ForVarIterator varname="$$context-item"/>
+              <SingletonIterator value="xs:string(question_id)"/>
+            </SingleObjectLookupIterator>
+          </FnDataIterator>
+        </PromoteIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <ApplyIterator>
+      <ZorbaCreateCollectionIterator>
+        <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
+      </ZorbaCreateCollectionIterator>
+    </ApplyIterator>
+    <ApplyIterator>
+      <ZorbaCreateCollectionIterator>
+        <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
+      </ZorbaCreateCollectionIterator>
+    </ApplyIterator>
+    <ApplyIterator>
+      <CreateIndexIterator>
+        <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
+      </CreateIndexIterator>
+    </ApplyIterator>
+    <TupleStreamIterator>
+      <OrderByIterator>
+        <OrderByForVariable inputVar="id : "/>
+        <OrderByForVariable inputVar="count : "/>
+        <OrderBySpec>
+          <ForVarIterator varname="count"/>
+        </OrderBySpec>
+        <ForIterator>
+          <ForVariable name="count"/>
+          <GroupByIterator>
+            <ForIterator>
+              <ForVariable name="answers"/>
+              <TupleSourceIterator/>
+              <ZorbaCollectionIterator>
+                <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
+              </ZorbaCollectionIterator>
+            </ForIterator>
+            <Spec>
+              <TreatIterator quant="?">
+                <FnDataIterator>
+                  <SingleObjectLookupIterator>
+                    <ForVarIterator varname="answers"/>
+                    <SingletonIterator value="xs:string(question_id)"/>
+                  </SingleObjectLookupIterator>
+                </FnDataIterator>
+              </TreatIterator>
+              <GroupVariable/>
+            </Spec>
+            <Spec>
+              <ForVarIterator varname="answers"/>
+              <NonGroupVariable/>
+            </Spec>
+          </GroupByIterator>
+          <FnCountIterator>
+            <LetVarIterator varname="answers"/>
+          </FnCountIterator>
+        </ForIterator>
+      </OrderByIterator>
+      <JSONDirectObjectIterator>
+        <SingletonIterator value="xs:string(title)"/>
+        <SingletonIterator value="xs:string(answer_count)"/>
+        <JSONBoxIterator>
+          <MultiObjectLookupIterator>
+            <FLWORIterator>
+              <ForVariable name="$$context-item">
+                <ProbeIndexRangeValueIterator>
+                  <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
+                  <ForVarIterator varname="id"/>
+                  <ForVarIterator varname="id"/>
+                  <SingletonIterator value="xs:boolean(true)"/>
+                  <SingletonIterator value="xs:boolean(true)"/>
+                  <SingletonIterator value="xs:boolean(true)"/>
+                  <SingletonIterator value="xs:boolean(true)"/>
+                </ProbeIndexRangeValueIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ForVarIterator varname="$$context-item"/>
+              </ReturnClause>
+            </FLWORIterator>
+            <SingletonIterator value="xs:string(title)"/>
+          </MultiObjectLookupIterator>
+        </JSONBoxIterator>
         <ForVarIterator varname="count"/>
-      </OrderBySpec>
-      <ForIterator>
-        <ForVariable name="count"/>
-        <GroupByIterator>
-          <ForIterator>
-            <ForVariable name="answers"/>
-            <TupleSourceIterator/>
-            <ZorbaCollectionIterator>
-              <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
-            </ZorbaCollectionIterator>
-          </ForIterator>
-          <Spec>
-            <TreatIterator quant="?">
-              <FnDataIterator>
-                <SingleObjectLookupIterator>
-                  <ForVarIterator varname="answers"/>
-                  <SingletonIterator value="xs:string(question_id)"/>
-                </SingleObjectLookupIterator>
-              </FnDataIterator>
-            </TreatIterator>
-            <GroupVariable/>
-          </Spec>
-          <Spec>
-            <ForVarIterator varname="answers"/>
-            <NonGroupVariable/>
-          </Spec>
-        </GroupByIterator>
-        <FnCountIterator>
-          <LetVarIterator varname="answers"/>
-        </FnCountIterator>
-      </ForIterator>
-    </OrderByIterator>
-    <JSONDirectObjectIterator>
-      <SingletonIterator value="xs:string(title)"/>
-      <SingletonIterator value="xs:string(answer_count)"/>
-      <JSONBoxIterator>
-        <MultiObjectLookupIterator>
-          <FLWORIterator>
-            <ForVariable name="$$context-item">
-              <ProbeIndexRangeValueIterator>
-                <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
-                <ForVarIterator varname="id"/>
-                <ForVarIterator varname="id"/>
-                <SingletonIterator value="xs:boolean(true)"/>
-                <SingletonIterator value="xs:boolean(true)"/>
-                <SingletonIterator value="xs:boolean(true)"/>
-                <SingletonIterator value="xs:boolean(true)"/>
-              </ProbeIndexRangeValueIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ForVarIterator varname="$$context-item"/>
-            </ReturnClause>
-          </FLWORIterator>
-          <SingletonIterator value="xs:string(title)"/>
-        </MultiObjectLookupIterator>
-      </JSONBoxIterator>
-      <ForVarIterator varname="count"/>
-    </JSONDirectObjectIterator>
-  </TupleStreamIterator>
-</SequentialIterator>
-
+      </JSONDirectObjectIterator>
+    </TupleStreamIterator>
+  </SequentialIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/index/match_veq_09.iter'
--- test/iterplans/zorba/index/match_veq_09.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/index/match_veq_09.iter	2014-02-20 05:31:00 +0000
@@ -1,113 +1,113 @@
-Iterator tree for index:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <ZorbaCollectionIterator>
-      <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
-    </ZorbaCollectionIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <TreatIterator type="xs:integer" quant="">
-        <FnDataIterator>
-          <SingleObjectLookupIterator>
-            <ForVarIterator varname="$$context-item"/>
-            <SingletonIterator value="xs:string(question_id)"/>
-          </SingleObjectLookupIterator>
-        </FnDataIterator>
-      </TreatIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <ApplyIterator>
-    <ZorbaCreateCollectionIterator>
-      <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
-    </ZorbaCreateCollectionIterator>
-  </ApplyIterator>
-  <ApplyIterator>
-    <ZorbaCreateCollectionIterator>
-      <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
-    </ZorbaCreateCollectionIterator>
-  </ApplyIterator>
-  <ApplyIterator>
-    <CreateIndexIterator>
-      <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
-    </CreateIndexIterator>
-  </ApplyIterator>
-  <TupleStreamIterator>
-    <OrderByIterator>
-      <OrderByForVariable inputVar="id : "/>
-      <OrderByForVariable inputVar="count : "/>
-      <OrderBySpec>
+<iterator-tree description="index">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <ZorbaCollectionIterator>
+        <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
+      </ZorbaCollectionIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <TreatIterator type="xs:integer" quant="">
+          <FnDataIterator>
+            <SingleObjectLookupIterator>
+              <ForVarIterator varname="$$context-item"/>
+              <SingletonIterator value="xs:string(question_id)"/>
+            </SingleObjectLookupIterator>
+          </FnDataIterator>
+        </TreatIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <ApplyIterator>
+      <ZorbaCreateCollectionIterator>
+        <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
+      </ZorbaCreateCollectionIterator>
+    </ApplyIterator>
+    <ApplyIterator>
+      <ZorbaCreateCollectionIterator>
+        <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
+      </ZorbaCreateCollectionIterator>
+    </ApplyIterator>
+    <ApplyIterator>
+      <CreateIndexIterator>
+        <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
+      </CreateIndexIterator>
+    </ApplyIterator>
+    <TupleStreamIterator>
+      <OrderByIterator>
+        <OrderByForVariable inputVar="id : "/>
+        <OrderByForVariable inputVar="count : "/>
+        <OrderBySpec>
+          <ForVarIterator varname="count"/>
+        </OrderBySpec>
+        <ForIterator>
+          <ForVariable name="count"/>
+          <GroupByIterator>
+            <ForIterator>
+              <ForVariable name="answers"/>
+              <TupleSourceIterator/>
+              <ZorbaCollectionIterator>
+                <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
+              </ZorbaCollectionIterator>
+            </ForIterator>
+            <Spec>
+              <TreatIterator quant="?">
+                <FnDataIterator>
+                  <SingleObjectLookupIterator>
+                    <ForVarIterator varname="answers"/>
+                    <SingletonIterator value="xs:string(question_id)"/>
+                  </SingleObjectLookupIterator>
+                </FnDataIterator>
+              </TreatIterator>
+              <GroupVariable/>
+            </Spec>
+            <Spec>
+              <ForVarIterator varname="answers"/>
+              <NonGroupVariable/>
+            </Spec>
+          </GroupByIterator>
+          <FnCountIterator>
+            <LetVarIterator varname="answers"/>
+          </FnCountIterator>
+        </ForIterator>
+      </OrderByIterator>
+      <JSONDirectObjectIterator>
+        <SingletonIterator value="xs:string(title)"/>
+        <SingletonIterator value="xs:string(answer_count)"/>
+        <JSONBoxIterator>
+          <MultiObjectLookupIterator>
+            <FLWORIterator>
+              <ForVariable name="$$context-item">
+                <ProbeIndexRangeValueIterator>
+                  <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
+                  <ForVarIterator varname="id"/>
+                  <ForVarIterator varname="id"/>
+                  <SingletonIterator value="xs:boolean(true)"/>
+                  <SingletonIterator value="xs:boolean(true)"/>
+                  <SingletonIterator value="xs:boolean(true)"/>
+                  <SingletonIterator value="xs:boolean(true)"/>
+                </ProbeIndexRangeValueIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ForVarIterator varname="$$context-item"/>
+              </ReturnClause>
+            </FLWORIterator>
+            <SingletonIterator value="xs:string(title)"/>
+          </MultiObjectLookupIterator>
+        </JSONBoxIterator>
         <ForVarIterator varname="count"/>
-      </OrderBySpec>
-      <ForIterator>
-        <ForVariable name="count"/>
-        <GroupByIterator>
-          <ForIterator>
-            <ForVariable name="answers"/>
-            <TupleSourceIterator/>
-            <ZorbaCollectionIterator>
-              <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
-            </ZorbaCollectionIterator>
-          </ForIterator>
-          <Spec>
-            <TreatIterator quant="?">
-              <FnDataIterator>
-                <SingleObjectLookupIterator>
-                  <ForVarIterator varname="answers"/>
-                  <SingletonIterator value="xs:string(question_id)"/>
-                </SingleObjectLookupIterator>
-              </FnDataIterator>
-            </TreatIterator>
-            <GroupVariable/>
-          </Spec>
-          <Spec>
-            <ForVarIterator varname="answers"/>
-            <NonGroupVariable/>
-          </Spec>
-        </GroupByIterator>
-        <FnCountIterator>
-          <LetVarIterator varname="answers"/>
-        </FnCountIterator>
-      </ForIterator>
-    </OrderByIterator>
-    <JSONDirectObjectIterator>
-      <SingletonIterator value="xs:string(title)"/>
-      <SingletonIterator value="xs:string(answer_count)"/>
-      <JSONBoxIterator>
-        <MultiObjectLookupIterator>
-          <FLWORIterator>
-            <ForVariable name="$$context-item">
-              <ProbeIndexRangeValueIterator>
-                <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
-                <ForVarIterator varname="id"/>
-                <ForVarIterator varname="id"/>
-                <SingletonIterator value="xs:boolean(true)"/>
-                <SingletonIterator value="xs:boolean(true)"/>
-                <SingletonIterator value="xs:boolean(true)"/>
-                <SingletonIterator value="xs:boolean(true)"/>
-              </ProbeIndexRangeValueIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ForVarIterator varname="$$context-item"/>
-            </ReturnClause>
-          </FLWORIterator>
-          <SingletonIterator value="xs:string(title)"/>
-        </MultiObjectLookupIterator>
-      </JSONBoxIterator>
-      <ForVarIterator varname="count"/>
-    </JSONDirectObjectIterator>
-  </TupleStreamIterator>
-</SequentialIterator>
-
+      </JSONDirectObjectIterator>
+    </TupleStreamIterator>
+  </SequentialIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/index/match_veq_10.iter'
--- test/iterplans/zorba/index/match_veq_10.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/index/match_veq_10.iter	2014-02-20 05:31:00 +0000
@@ -1,127 +1,127 @@
-Iterator tree for index:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <ZorbaCollectionIterator>
-      <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
-    </ZorbaCollectionIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <PromoteIterator type="xs:string">
-        <CastIterator type="xs:string">
-          <FnDataIterator>
-            <SingleObjectLookupIterator>
-              <ForVarIterator varname="$$context-item"/>
-              <SingletonIterator value="xs:string(question_id)"/>
-            </SingleObjectLookupIterator>
-          </FnDataIterator>
-        </CastIterator>
-      </PromoteIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <ApplyIterator>
-    <ZorbaCreateCollectionIterator>
-      <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
-    </ZorbaCreateCollectionIterator>
-  </ApplyIterator>
-  <ApplyIterator>
-    <ZorbaCreateCollectionIterator>
-      <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
-    </ZorbaCreateCollectionIterator>
-  </ApplyIterator>
-  <ApplyIterator>
-    <CreateIndexIterator>
-      <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
-    </CreateIndexIterator>
-  </ApplyIterator>
-  <TupleStreamIterator>
-    <OrderByIterator>
-      <OrderByForVariable inputVar="count : "/>
-      <OrderByLetVariable inputVar="$$opt_temp_0 : "/>
-      <OrderBySpec>
+<iterator-tree description="index">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <ZorbaCollectionIterator>
+        <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
+      </ZorbaCollectionIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <PromoteIterator type="xs:string">
+          <CastIterator type="xs:string">
+            <FnDataIterator>
+              <SingleObjectLookupIterator>
+                <ForVarIterator varname="$$context-item"/>
+                <SingletonIterator value="xs:string(question_id)"/>
+              </SingleObjectLookupIterator>
+            </FnDataIterator>
+          </CastIterator>
+        </PromoteIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <ApplyIterator>
+      <ZorbaCreateCollectionIterator>
+        <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
+      </ZorbaCreateCollectionIterator>
+    </ApplyIterator>
+    <ApplyIterator>
+      <ZorbaCreateCollectionIterator>
+        <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
+      </ZorbaCreateCollectionIterator>
+    </ApplyIterator>
+    <ApplyIterator>
+      <CreateIndexIterator>
+        <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
+      </CreateIndexIterator>
+    </ApplyIterator>
+    <TupleStreamIterator>
+      <OrderByIterator>
+        <OrderByForVariable inputVar="count : "/>
+        <OrderByLetVariable inputVar="$$opt_temp_0 : "/>
+        <OrderBySpec>
+          <ForVarIterator varname="count"/>
+        </OrderBySpec>
+        <ForIterator>
+          <ForVariable name="count"/>
+          <LetIterator>
+            <LetVariable name="$$opt_temp_0" materialize="true"/>
+            <GroupByIterator>
+              <ForIterator>
+                <ForVariable name="answers"/>
+                <TupleSourceIterator/>
+                <ZorbaCollectionIterator>
+                  <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
+                </ZorbaCollectionIterator>
+              </ForIterator>
+              <Spec>
+                <TreatIterator quant="?">
+                  <FnDataIterator>
+                    <SingleObjectLookupIterator>
+                      <ForVarIterator varname="answers"/>
+                      <SingletonIterator value="xs:string(question_id)"/>
+                    </SingleObjectLookupIterator>
+                  </FnDataIterator>
+                </TreatIterator>
+                <GroupVariable/>
+              </Spec>
+              <Spec>
+                <ForVarIterator varname="answers"/>
+                <NonGroupVariable/>
+              </Spec>
+            </GroupByIterator>
+            <HoistIterator>
+              <CastIterator type="xs:string">
+                <ForVarIterator varname="id"/>
+              </CastIterator>
+            </HoistIterator>
+          </LetIterator>
+          <FnCountIterator>
+            <LetVarIterator varname="answers"/>
+          </FnCountIterator>
+        </ForIterator>
+      </OrderByIterator>
+      <JSONDirectObjectIterator>
+        <SingletonIterator value="xs:string(title)"/>
+        <SingletonIterator value="xs:string(answer_count)"/>
+        <JSONBoxIterator>
+          <MultiObjectLookupIterator>
+            <FLWORIterator>
+              <ForVariable name="$$context-item">
+                <ProbeIndexRangeValueIterator>
+                  <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
+                  <UnhoistIterator>
+                    <LetVarIterator varname="$$opt_temp_0"/>
+                  </UnhoistIterator>
+                  <UnhoistIterator>
+                    <LetVarIterator varname="$$opt_temp_0"/>
+                  </UnhoistIterator>
+                  <SingletonIterator value="xs:boolean(true)"/>
+                  <SingletonIterator value="xs:boolean(true)"/>
+                  <SingletonIterator value="xs:boolean(true)"/>
+                  <SingletonIterator value="xs:boolean(true)"/>
+                </ProbeIndexRangeValueIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ForVarIterator varname="$$context-item"/>
+              </ReturnClause>
+            </FLWORIterator>
+            <SingletonIterator value="xs:string(title)"/>
+          </MultiObjectLookupIterator>
+        </JSONBoxIterator>
         <ForVarIterator varname="count"/>
-      </OrderBySpec>
-      <ForIterator>
-        <ForVariable name="count"/>
-        <LetIterator>
-          <LetVariable name="$$opt_temp_0" materialize="true"/>
-          <GroupByIterator>
-            <ForIterator>
-              <ForVariable name="answers"/>
-              <TupleSourceIterator/>
-              <ZorbaCollectionIterator>
-                <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
-              </ZorbaCollectionIterator>
-            </ForIterator>
-            <Spec>
-              <TreatIterator quant="?">
-                <FnDataIterator>
-                  <SingleObjectLookupIterator>
-                    <ForVarIterator varname="answers"/>
-                    <SingletonIterator value="xs:string(question_id)"/>
-                  </SingleObjectLookupIterator>
-                </FnDataIterator>
-              </TreatIterator>
-              <GroupVariable/>
-            </Spec>
-            <Spec>
-              <ForVarIterator varname="answers"/>
-              <NonGroupVariable/>
-            </Spec>
-          </GroupByIterator>
-          <HoistIterator>
-            <CastIterator type="xs:string">
-              <ForVarIterator varname="id"/>
-            </CastIterator>
-          </HoistIterator>
-        </LetIterator>
-        <FnCountIterator>
-          <LetVarIterator varname="answers"/>
-        </FnCountIterator>
-      </ForIterator>
-    </OrderByIterator>
-    <JSONDirectObjectIterator>
-      <SingletonIterator value="xs:string(title)"/>
-      <SingletonIterator value="xs:string(answer_count)"/>
-      <JSONBoxIterator>
-        <MultiObjectLookupIterator>
-          <FLWORIterator>
-            <ForVariable name="$$context-item">
-              <ProbeIndexRangeValueIterator>
-                <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
-                <UnhoistIterator>
-                  <LetVarIterator varname="$$opt_temp_0"/>
-                </UnhoistIterator>
-                <UnhoistIterator>
-                  <LetVarIterator varname="$$opt_temp_0"/>
-                </UnhoistIterator>
-                <SingletonIterator value="xs:boolean(true)"/>
-                <SingletonIterator value="xs:boolean(true)"/>
-                <SingletonIterator value="xs:boolean(true)"/>
-                <SingletonIterator value="xs:boolean(true)"/>
-              </ProbeIndexRangeValueIterator>
-            </ForVariable>
-            <ReturnClause>
-              <ForVarIterator varname="$$context-item"/>
-            </ReturnClause>
-          </FLWORIterator>
-          <SingletonIterator value="xs:string(title)"/>
-        </MultiObjectLookupIterator>
-      </JSONBoxIterator>
-      <ForVarIterator varname="count"/>
-    </JSONDirectObjectIterator>
-  </TupleStreamIterator>
-</SequentialIterator>
-
+      </JSONDirectObjectIterator>
+    </TupleStreamIterator>
+  </SequentialIterator>
+</iterator-tree>

=== modified file 'test/iterplans/zorba/index/match_veq_11.iter'
--- test/iterplans/zorba/index/match_veq_11.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/index/match_veq_11.iter	2014-02-20 05:31:00 +0000
@@ -1,189 +1,189 @@
-Iterator tree for doc indexer:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <TreatIterator quant="">
-        <CastIterator type="xs:int">
-          <FnDataIterator>
-            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-              <ForVarIterator varname="$$context-item"/>
-            </AttributeAxisIterator>
-          </FnDataIterator>
-        </CastIterator>
-      </TreatIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for index:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <ZorbaCollectionIterator>
-      <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,custaccs)"/>
-    </ZorbaCollectionIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <TreatIterator quant="">
-        <CastIterator type="xs:int">
-          <FnDataIterator>
-            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-              <ForVarIterator varname="$$context-item"/>
-            </AttributeAxisIterator>
-          </FnDataIterator>
-        </CastIterator>
-      </TreatIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for doc indexer:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </PromoteIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for index:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <ZorbaCollectionIterator>
-      <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,custaccs)"/>
-    </ZorbaCollectionIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </PromoteIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="ca:custaccs">
-    <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,custaccs)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="5" varname="ca:orders">
-    <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,orders)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="6" varname="ca:index-custaccs-str">
-    <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,index-custaccs-str)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="7" varname="ca:index-custaccs-int">
-    <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,index-custaccs-int)"/>
-  </CtxVarDeclareIterator>
+<iterator-tree description="doc indexer">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <TreatIterator quant="">
+          <CastIterator type="xs:int">
+            <FnDataIterator>
+              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+                <ForVarIterator varname="$$context-item"/>
+              </AttributeAxisIterator>
+            </FnDataIterator>
+          </CastIterator>
+        </TreatIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="index">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <ZorbaCollectionIterator>
+        <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,custaccs)"/>
+      </ZorbaCollectionIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <TreatIterator quant="">
+          <CastIterator type="xs:int">
+            <FnDataIterator>
+              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+                <ForVarIterator varname="$$context-item"/>
+              </AttributeAxisIterator>
+            </FnDataIterator>
+          </CastIterator>
+        </TreatIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="doc indexer">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </PromoteIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="index">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <ZorbaCollectionIterator>
+        <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,custaccs)"/>
+      </ZorbaCollectionIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </PromoteIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="main query">
   <SequentialIterator>
-    <ApplyIterator>
-      <ZorbaCreateCollectionIterator>
-        <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,custaccs)"/>
-      </ZorbaCreateCollectionIterator>
-    </ApplyIterator>
-    <ApplyIterator>
-      <ZorbaCreateCollectionIterator>
-        <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,orders)"/>
-      </ZorbaCreateCollectionIterator>
-    </ApplyIterator>
-    <ApplyIterator>
-      <CreateIndexIterator>
-        <CtxVarIterator varid="6" varname="ca:index-custaccs-str" varkind="global"/>
-      </CreateIndexIterator>
-    </ApplyIterator>
-    <ApplyIterator>
-      <CreateIndexIterator>
-        <CtxVarIterator varid="7" varname="ca:index-custaccs-int" varkind="global"/>
-      </CreateIndexIterator>
-    </ApplyIterator>
-    <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-      <FLWORIterator>
-        <ForVariable name="$$opt_temp_0">
-          <ZorbaCollectionIterator>
-            <CtxVarIterator varid="5" varname="ca:orders" varkind="global"/>
-          </ZorbaCollectionIterator>
-        </ForVariable>
-        <ReturnClause>
-          <GeneralIndexEntryBuilderIterator>
-            <ForVarIterator varname="$$opt_temp_0"/>
-            <FnDataIterator>
-              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,Acct)" typename="*" nill allowed="0">
-                <ForVarIterator varname="$$opt_temp_0"/>
-              </AttributeAxisIterator>
-            </FnDataIterator>
-          </GeneralIndexEntryBuilderIterator>
-        </ReturnClause>
-      </FLWORIterator>
-    </CreateInternalIndexIterator>
-    <FnMinMaxIterator type="max">
-      <FnDataIterator>
+    <CtxVarDeclareIterator varid="4" varname="ca:custaccs">
+      <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,custaccs)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="5" varname="ca:orders">
+      <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,orders)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="6" varname="ca:index-custaccs-str">
+      <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,index-custaccs-str)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="7" varname="ca:index-custaccs-int">
+      <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,index-custaccs-int)"/>
+    </CtxVarDeclareIterator>
+    <SequentialIterator>
+      <ApplyIterator>
+        <ZorbaCreateCollectionIterator>
+          <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,custaccs)"/>
+        </ZorbaCreateCollectionIterator>
+      </ApplyIterator>
+      <ApplyIterator>
+        <ZorbaCreateCollectionIterator>
+          <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,orders)"/>
+        </ZorbaCreateCollectionIterator>
+      </ApplyIterator>
+      <ApplyIterator>
+        <CreateIndexIterator>
+          <CtxVarIterator varid="6" varname="ca:index-custaccs-str" varkind="global"/>
+        </CreateIndexIterator>
+      </ApplyIterator>
+      <ApplyIterator>
+        <CreateIndexIterator>
+          <CtxVarIterator varid="7" varname="ca:index-custaccs-int" varkind="global"/>
+        </CreateIndexIterator>
+      </ApplyIterator>
+      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
         <FLWORIterator>
-          <ForVariable name="$$context-item">
-            <ProbeIndexPointValueIterator>
-              <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,index-custaccs-str)"/>
-              <SingletonIterator value="xs:integer(4)"/>
-            </ProbeIndexPointValueIterator>
-          </ForVariable>
-          <ForVariable name="$$context-item">
-            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
-              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,Account)" typename="*" nill allowed="0">
-                <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,Accounts)" typename="*" nill allowed="0">
-                  <ForVarIterator varname="$$context-item"/>
-                </ChildAxisIterator>
-              </ChildAxisIterator>
-            </AttributeAxisIterator>
-          </ForVariable>
-          <ForVariable name="acct-id">
-            <FnStringIterator>
-              <ForVarIterator varname="$$context-item"/>
-            </FnStringIterator>
-          </ForVariable>
-          <ForVariable name="ord">
-            <NodeSortIterator distinct="true" ascending="true">
-              <ProbeIndexPointGeneralIterator>
-                <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-                <ForVarIterator varname="acct-id"/>
-              </ProbeIndexPointGeneralIterator>
-            </NodeSortIterator>
+          <ForVariable name="$$opt_temp_0">
+            <ZorbaCollectionIterator>
+              <CtxVarIterator varid="5" varname="ca:orders" varkind="global"/>
+            </ZorbaCollectionIterator>
           </ForVariable>
           <ReturnClause>
-            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,Cash)" typename="*" nill allowed="0">
-              <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,OrdQty)" typename="*" nill allowed="0">
-                <ForVarIterator varname="ord"/>
-              </ChildAxisIterator>
-            </AttributeAxisIterator>
+            <GeneralIndexEntryBuilderIterator>
+              <ForVarIterator varname="$$opt_temp_0"/>
+              <FnDataIterator>
+                <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,Acct)" typename="*" nill allowed="0">
+                  <ForVarIterator varname="$$opt_temp_0"/>
+                </AttributeAxisIterator>
+              </FnDataIterator>
+            </GeneralIndexEntryBuilderIterator>
           </ReturnClause>
         </FLWORIterator>
-      </FnDataIterator>
-    </FnMinMaxIterator>
+      </CreateInternalIndexIterator>
+      <FnMinMaxIterator type="max">
+        <FnDataIterator>
+          <FLWORIterator>
+            <ForVariable name="$$context-item">
+              <ProbeIndexPointValueIterator>
+                <SingletonIterator value="xs:QName(http://www.28msec.com/benchmark/lib/custacc,ca,index-custaccs-str)"/>
+                <SingletonIterator value="xs:integer(4)"/>
+              </ProbeIndexPointValueIterator>
+            </ForVariable>
+            <ForVariable name="$$context-item">
+              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,id)" typename="*" nill allowed="0">
+                <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,Account)" typename="*" nill allowed="0">
+                  <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,Accounts)" typename="*" nill allowed="0">
+                    <ForVarIterator varname="$$context-item"/>
+                  </ChildAxisIterator>
+                </ChildAxisIterator>
+              </AttributeAxisIterator>
+            </ForVariable>
+            <ForVariable name="acct-id">
+              <FnStringIterator>
+                <ForVarIterator varname="$$context-item"/>
+              </FnStringIterator>
+            </ForVariable>
+            <ForVariable name="ord">
+              <NodeSortIterator distinct="true" ascending="true">
+                <ProbeIndexPointGeneralIterator>
+                  <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+                  <ForVarIterator varname="acct-id"/>
+                </ProbeIndexPointGeneralIterator>
+              </NodeSortIterator>
+            </ForVariable>
+            <ReturnClause>
+              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,Cash)" typename="*" nill allowed="0">
+                <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,OrdQty)" typename="*" nill allowed="0">
+                  <ForVarIterator varname="ord"/>
+                </ChildAxisIterator>
+              </AttributeAxisIterator>
+            </ReturnClause>
+          </FLWORIterator>
+        </FnDataIterator>
+      </FnMinMaxIterator>
+    </SequentialIterator>
   </SequentialIterator>
-</SequentialIterator>
-
+</iterator-tree>

=== modified file 'test/iterplans/zorba/index/match_vrange_01.iter'
--- test/iterplans/zorba/index/match_vrange_01.iter	2014-02-19 01:28:17 +0000
+++ test/iterplans/zorba/index/match_vrange_01.iter	2014-02-20 05:31:00 +0000
@@ -1,241 +1,241 @@
-Iterator tree for doc indexer:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,uri)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </PromoteIterator>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,date-time)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </PromoteIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for index:
-<FLWORIterator>
-  <ForVariable name="$$context-item">
-    <ZorbaCollectionIterator>
+<iterator-tree description="doc indexer">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <CtxVarIterator varid="1" varname="$$idx_doc_var" varkind="global"/>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,uri)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </PromoteIterator>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,date-time)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </PromoteIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="index">
+  <FLWORIterator>
+    <ForVariable name="$$context-item">
+      <ZorbaCollectionIterator>
+        <SingletonIterator value="xs:QName(www.data.com,data,parents)"/>
+      </ZorbaCollectionIterator>
+    </ForVariable>
+    <ReturnClause>
+      <ValueIndexEntryBuilderIterator>
+        <ForVarIterator varname="$$context-item"/>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,uri)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </PromoteIterator>
+        <PromoteIterator type="xs:string">
+          <FnDataIterator>
+            <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,date-time)" typename="*" nill allowed="0">
+              <ForVarIterator varname="$$context-item"/>
+            </AttributeAxisIterator>
+          </FnDataIterator>
+        </PromoteIterator>
+      </ValueIndexEntryBuilderIterator>
+    </ReturnClause>
+  </FLWORIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <OrIterator>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+    <SingletonIterator value="xs:boolean(false)"/>
+  </OrIterator>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <SingletonIterator value="xs:string(/zorba/repo)"/>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <SingletonIterator value="xs:string(/zorba/repo)"/>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <SingletonIterator value="xs:string(/zorba/repo)"/>
+</iterator-tree>
+<iterator-tree description="const-folded expr">
+  <SingletonIterator value="xs:string(/zorba/repo)"/>
+</iterator-tree>
+<iterator-tree description="main query">
+  <SequentialIterator>
+    <CtxVarDeclareIterator varid="4" varname="data:parents">
       <SingletonIterator value="xs:QName(www.data.com,data,parents)"/>
-    </ZorbaCollectionIterator>
-  </ForVariable>
-  <ReturnClause>
-    <ValueIndexEntryBuilderIterator>
-      <ForVarIterator varname="$$context-item"/>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,uri)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </PromoteIterator>
-      <PromoteIterator type="xs:string">
-        <FnDataIterator>
-          <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,date-time)" typename="*" nill allowed="0">
-            <ForVarIterator varname="$$context-item"/>
-          </AttributeAxisIterator>
-        </FnDataIterator>
-      </PromoteIterator>
-    </ValueIndexEntryBuilderIterator>
-  </ReturnClause>
-</FLWORIterator>
-
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for const-folded expr:
-<OrIterator>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-  <SingletonIterator value="xs:boolean(false)"/>
-</OrIterator>
-
-Iterator tree for const-folded expr:
-<SingletonIterator value="xs:string(/zorba/repo)"/>
-
-Iterator tree for const-folded expr:
-<SingletonIterator value="xs:string(/zorba/repo)"/>
-
-Iterator tree for const-folded expr:
-<SingletonIterator value="xs:string(/zorba/repo)"/>
-
-Iterator tree for const-folded expr:
-<SingletonIterator value="xs:string(/zorba/repo)"/>
-
-Iterator tree for main query:
-<SequentialIterator>
-  <CtxVarDeclareIterator varid="4" varname="data:parents">
-    <SingletonIterator value="xs:QName(www.data.com,data,parents)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="5" varname="data:idx">
-    <SingletonIterator value="xs:QName(www.data.com,data,idx)"/>
-  </CtxVarDeclareIterator>
-  <CtxVarDeclareIterator varid="6" varname="doc">
-    <ElementIterator>
-      <SingletonIterator value="xs:QName(,,parents)"/>
+    </CtxVarDeclareIterator>
+    <CtxVarDeclareIterator varid="5" varname="data:idx">
+      <SingletonIterator valu

Follow ups