← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/bug-967428 into lp:zorba

 

Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/bug-967428 into lp:zorba.

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-967428/+merge/108704

Improved hoist rule: tighter hoisting of expressions (also fixes bug #967428)
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-967428/+merge/108704
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-05-30 00:37:00 +0000
+++ ChangeLog	2012-06-05 08:59:24 +0000
@@ -1,5 +1,8 @@
 Zorba - The XQuery Processor
 
+version 2.7
+  * Improved hoist rule: tighter hoisting of expressions (also fixes bug #967428)
+
 version 2.5
 
 New Features:

=== modified file 'src/compiler/expression/expr.h'
--- src/compiler/expression/expr.h	2012-05-16 17:25:48 +0000
+++ src/compiler/expression/expr.h	2012-06-05 08:59:24 +0000
@@ -1002,6 +1002,8 @@
 
   expr* get_try_expr() const { return theTryExpr.getp(); }
 
+  void set_try_expr(expr* e) { theTryExpr = e; }
+
   expr* get_catch_expr(csize i) const { return theCatchExprs[i].getp(); }
 
   void add_catch_expr(expr_t e);

=== modified file 'src/compiler/rewriter/rules/hoist_rules.cpp'
--- src/compiler/rewriter/rules/hoist_rules.cpp	2012-05-03 12:31:51 +0000
+++ src/compiler/rewriter/rules/hoist_rules.cpp	2012-06-05 08:59:24 +0000
@@ -137,9 +137,9 @@
   {
     flwor_expr* flwor = static_cast<flwor_expr *>(e);
 
-    PathHolder curr_holder;
-    curr_holder.prev = path;
-    curr_holder.expr = e;
+    PathHolder step;
+    step.prev = path;
+    step.expr = e;
 
     csize numForLetClauses = flwor->num_forlet_clauses();
     csize i = 0;
@@ -147,32 +147,26 @@
     while (i < numForLetClauses)
     {
       forletwin_clause* flc = static_cast<forletwin_clause*>(flwor->get_clause(i));
-
       expr* domainExpr = flc->get_expr();
 
-      expr_t unhoistExpr = try_hoisting(rCtx,
-                                        domainExpr,
-                                        varmap,
-                                        freevarMap,
-                                        &curr_holder);
+      expr_t unhoistExpr = 
+      try_hoisting(rCtx, domainExpr, varmap, freevarMap, &step);
+
       if (unhoistExpr != NULL)
       {
         flc->set_expr(unhoistExpr.getp());
         status = true;
-
         numForLetClauses = flwor->num_forlet_clauses();
-
         // TODO: the expr that was just hoisted here, may contain sub-exprs that
         // can be hoisted even earlier. 
       }
       else if (domainExpr->is_sequential())
       {
         PathHolder root;
-        bool hoisted = hoist_expressions(rCtx,
-                                         domainExpr,
-                                         varmap,
-                                         freevarMap,
-                                         &root);
+
+        bool hoisted = 
+        hoist_expressions(rCtx, domainExpr, varmap, freevarMap, &root);
+
         if (hoisted)
         {
           if (root.expr != NULL)
@@ -180,7 +174,6 @@
             assert(root.expr->get_expr_kind() == flwor_expr_kind);
 
             static_cast<flwor_expr*>(root.expr.getp())->set_return_expr(domainExpr);
-
             flc->set_expr(root.expr.getp());
           }
 
@@ -190,11 +183,9 @@
       }
       else
       {
-        bool hoisted = hoist_expressions(rCtx,
-                                         domainExpr,
-                                         varmap,
-                                         freevarMap,
-                                         &curr_holder);
+        bool hoisted = 
+        hoist_expressions(rCtx, domainExpr, varmap, freevarMap, &step);
+
         if (hoisted)
         {
           status = true;
@@ -202,7 +193,7 @@
         }
       }
 
-      i = ++(curr_holder.clauseCount);
+      i = ++(step.clauseCount);
 
       assert(numForLetClauses == flwor->num_forlet_clauses());
     }
@@ -212,7 +203,8 @@
     {
       ZORBA_ASSERT(!we->is_sequential());
 
-      expr_t unhoistExpr = try_hoisting(rCtx, we, varmap, freevarMap, &curr_holder);
+      expr_t unhoistExpr = try_hoisting(rCtx, we, varmap, freevarMap, &step);
+
       if (unhoistExpr != NULL)
       {
         flwor->set_where(unhoistExpr.getp());
@@ -220,14 +212,14 @@
       }
       else
       {
-        status = hoist_expressions(rCtx, we, varmap, freevarMap, &curr_holder) || status;
+        status = hoist_expressions(rCtx, we, varmap, freevarMap, &step) || status;
       }
     }
 
     // TODO: hoist orderby exprs
 
     expr_t re = flwor->get_return_expr();
-    expr_t unhoistExpr = try_hoisting(rCtx, re, varmap, freevarMap, &curr_holder);
+    expr_t unhoistExpr = try_hoisting(rCtx, re, varmap, freevarMap, &step);
 
     if (unhoistExpr != NULL)
     {
@@ -251,15 +243,15 @@
     }
     else
     {
-      status = hoist_expressions(rCtx, re, varmap, freevarMap, &curr_holder) || status;
+      status = hoist_expressions(rCtx, re, varmap, freevarMap, &step) || status;
     }
   }
 
   else if (e->get_expr_kind() == trycatch_expr_kind)
   {
-    PathHolder pathStep;
-    pathStep.prev = path;
-    pathStep.expr = e;
+    PathHolder step;
+    step.prev = path;
+    step.expr = e;
 
     ExprIterator iter(e);
 
@@ -268,7 +260,7 @@
       expr* ce = &*(*iter);
       if (ce)
       {
-        expr_t unhoistExpr = try_hoisting(rCtx, ce, varmap, freevarMap, &pathStep);
+        expr_t unhoistExpr = try_hoisting(rCtx, ce, varmap, freevarMap, &step);
         if (unhoistExpr != NULL)
         {
           *iter = unhoistExpr.getp();
@@ -276,7 +268,7 @@
         }
         else
         {
-          status = hoist_expressions(rCtx, ce, varmap, freevarMap, &pathStep) || status;
+          status = hoist_expressions(rCtx, ce, varmap, freevarMap, &step) || status;
         }
       }
 
@@ -358,7 +350,7 @@
     expr* e,
     const VarIdMap& varmap,
     const ExprVarsMap& freevarMap,
-    struct PathHolder* holder)
+    struct PathHolder* path)
 {
   if (non_hoistable(e) || e->contains_node_construction())
   {
@@ -371,21 +363,21 @@
   ZORBA_ASSERT(fvme != freevarMap.end());
   const DynamicBitset& varset = fvme->second;
 
-  PathHolder* h = holder;
+  PathHolder* step = path;
 
   bool inloop = false;
   bool foundReferencedFLWORVar = false;
   bool foundSequentialClause = false;
   int i = 0;
 
-  // h->prev == NULL means that expr e is not inside any flwor expr, and as a
+  // step->prev == NULL means that expr e is not inside any flwor expr, and as a
   // result, there is nothing to hoist. 
-  while (h->prev != NULL)
+  while (step->prev != NULL)
   {
-    if (h->expr->get_expr_kind() == trycatch_expr_kind)
+    if (step->expr->get_expr_kind() == trycatch_expr_kind)
     {
       // Should not hoist an expr out of a try-catch if it contains any try-catch vars
-      trycatch_expr* trycatch = static_cast<trycatch_expr*>(h->expr.getp());
+      trycatch_expr* trycatch = static_cast<trycatch_expr*>(step->expr.getp());
       csize numClauses = trycatch->clause_count();
 
       for (csize i = 0; i < numClauses; ++i)
@@ -407,10 +399,9 @@
     }
     else
     {
-      assert(h->expr->get_expr_kind() == flwor_expr_kind);
+      assert(step->expr->get_expr_kind() == flwor_expr_kind);
 
-      flwor_expr* flwor = static_cast<flwor_expr*>(h->expr.getp());
- 
+      flwor_expr* flwor = static_cast<flwor_expr*>(step->expr.getp());
       group_clause* gc = flwor->get_group_clause();
 
       // If any free variable is a group-by variable, give up.
@@ -441,7 +432,7 @@
       // If yes, then let V be the inner-most var referenced by e. If there are any
       // FOR vars after V, e can be hoisted out of any such FOR vars. Otherwise, e
       // cannot be hoisted.
-      for (i = h->clauseCount - 1; i >= 0; --i)
+      for (i = step->clauseCount - 1; i >= 0; --i)
       {
         const forletwin_clause* flc = 
         static_cast<const forletwin_clause*>(flwor->get_clause(i));
@@ -469,7 +460,10 @@
         break;
     }
 
-    h = h->prev;
+    if (step->prev->prev == NULL)
+      break;
+
+    step = step->prev;
   }
 
   if (!inloop)
@@ -489,27 +483,33 @@
   hoisted->setFlags(e->getFlags());
   letvar->setFlags(e->getFlags());
 
-  let_clause_t flref(new let_clause(e->get_sctx(),
-                                    e->get_loc(),
-                                    letvar,
-                                    hoisted));
+  let_clause_t flref(new let_clause(e->get_sctx(), e->get_loc(), letvar, hoisted));
 
   letvar->set_flwor_clause(flref.getp());
 
-  if (h->prev == NULL)
+  if (step->prev == NULL)
   {
-    if (h->expr == NULL)
+    if (step->expr == NULL)
     {
-      h->expr = new flwor_expr(e->get_sctx(), e->get_loc(), false);
+      step->expr = new flwor_expr(e->get_sctx(), e->get_loc(), false);
     }
-    static_cast<flwor_expr*>(h->expr.getp())->add_clause(flref);
+    static_cast<flwor_expr*>(step->expr.getp())->add_clause(flref);
+  }
+  else if (step->expr->get_expr_kind() == flwor_expr_kind)
+  {
+    static_cast<flwor_expr*>(step->expr.getp())->add_clause(i + 1, flref);
+    ++step->clauseCount;
   }
   else
   {
-    assert(h->expr->get_expr_kind() == flwor_expr_kind);
-
-    static_cast<flwor_expr*>(h->expr.getp())->add_clause(i + 1, flref);
-    ++h->clauseCount;
+    assert(step->expr->get_expr_kind() == trycatch_expr_kind);
+    trycatch_expr* trycatchExpr = static_cast<trycatch_expr*>(step->expr.getp());
+
+    flwor_expr_t flwor = new flwor_expr(e->get_sctx(), e->get_loc(), false);
+    flwor->add_clause(flref);
+    flwor->set_return_expr(trycatchExpr->get_try_expr());
+
+    trycatchExpr->set_try_expr(flwor);
   }
 
   expr_t unhoisted = new fo_expr(e->get_sctx(),

=== modified file 'src/compiler/rewriter/rules/index_join_rule.cpp'
--- src/compiler/rewriter/rules/index_join_rule.cpp	2012-05-03 12:31:51 +0000
+++ src/compiler/rewriter/rules/index_join_rule.cpp	2012-06-05 08:59:24 +0000
@@ -518,7 +518,7 @@
                          innerPosInStack))
       return;
 
-    ulong numClauses = innerFlwor->num_clauses();
+    csize numClauses = innerFlwor->num_clauses();
 
     if (innerFlwor->defines_variable(predInfo.theOuterVar) >= 0 ||
         mostInnerVarPos < numClauses-1)
@@ -529,12 +529,12 @@
 
       flwor_expr_t nestedFlwor = new flwor_expr(sctx, nestedLoc, false);
 
-      for (ulong i = mostInnerVarPos+1; i < numClauses; ++i)
+      for (csize i = mostInnerVarPos+1; i < numClauses; ++i)
       {
         nestedFlwor->add_clause(innerFlwor->get_clause(i));
       }
 
-      for (ulong i = numClauses - 1; i > mostInnerVarPos; --i)
+      for (csize i = numClauses - 1; i > mostInnerVarPos; --i)
       {
         innerFlwor->remove_clause(i);
       }
@@ -563,8 +563,8 @@
       {
         block_expr* seqExpr = static_cast<block_expr*>(returnExpr);
 
-        ulong numArgs = seqExpr->size();
-        ulong arg;
+        csize numArgs = seqExpr->size();
+        csize arg;
         for (arg = 0; arg < numArgs; ++arg)
         {
           if ((*seqExpr)[arg]->get_function_kind() !=
@@ -590,9 +590,9 @@
   }
   else
   {
-    // All the variables referenced by the inner domain expr are defined after
-    // the outer var. In this case, Find the flwor expr defining the outer var
-    // and create the index just before this flwor.
+    // The inner domain expr does not reference any flwor vars. In this case,
+    // find the flwor expr defining the outer var and create the index just 
+    // before this flwor.
     flwor_expr* outerFlworExpr = NULL;
     ulong outerPosInStack = 0;
     ulong dummy = 0;

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9197.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9197.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9197.iter	2012-06-05 08:59:24 +0000
@@ -1,33 +1,33 @@
 Iterator tree for main query:
-<flwor::FLWORIterator>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
-      <OpToIterator>
-        <SingletonIterator value="xs:integer(1)"/>
-        <SingletonIterator value="xs:integer(2)"/>
-      </OpToIterator>
-    </HoistIterator>
-  </LetVariable>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+<ElementIterator>
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::FLWORIterator>
+      <LetVariable name="$$opt_temp_0" materialize="true">
+        <HoistIterator>
+          <OpToIterator>
+            <SingletonIterator value="xs:integer(1)"/>
+            <SingletonIterator value="xs:integer(2)"/>
+          </OpToIterator>
+        </HoistIterator>
+      </LetVariable>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::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>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="book">
               <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
@@ -64,9 +64,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9198.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9198.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9198.iter	2012-06-05 08:59:24 +0000
@@ -1,33 +1,33 @@
 Iterator tree for main query:
-<flwor::FLWORIterator>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
-      <OpToIterator>
-        <SingletonIterator value="xs:integer(1)"/>
-        <SingletonIterator value="xs:integer(2)"/>
-      </OpToIterator>
-    </HoistIterator>
-  </LetVariable>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+<ElementIterator>
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::FLWORIterator>
+      <LetVariable name="$$opt_temp_0" materialize="true">
+        <HoistIterator>
+          <OpToIterator>
+            <SingletonIterator value="xs:integer(1)"/>
+            <SingletonIterator value="xs:integer(2)"/>
+          </OpToIterator>
+        </HoistIterator>
+      </LetVariable>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::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>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="book">
               <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
@@ -67,9 +67,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9199.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9199.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9199.iter	2012-06-05 08:59:24 +0000
@@ -1,33 +1,33 @@
 Iterator tree for main query:
-<flwor::FLWORIterator>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
-      <OpToIterator>
-        <SingletonIterator value="xs:integer(1)"/>
-        <SingletonIterator value="xs:integer(2)"/>
-      </OpToIterator>
-    </HoistIterator>
-  </LetVariable>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+<ElementIterator>
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::FLWORIterator>
+      <LetVariable name="$$opt_temp_0" materialize="true">
+        <HoistIterator>
+          <OpToIterator>
+            <SingletonIterator value="xs:integer(1)"/>
+            <SingletonIterator value="xs:integer(2)"/>
+          </OpToIterator>
+        </HoistIterator>
+      </LetVariable>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::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>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="book">
               <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
@@ -67,9 +67,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9206.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9206.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9206.iter	2012-06-05 08:59:24 +0000
@@ -1,38 +1,38 @@
 Iterator tree for main query:
-<flwor::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>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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">
+<ElementIterator>
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::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>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::FLWORIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
                   <ForVarIterator varname="$$opt_temp_1"/>
-                </ChildAxisIterator>
-              </FnCountIterator>
-            </ValueIndexEntryBuilderIterator>
-          </ReturnClause>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="anzahl">
               <OpToIterator>
@@ -60,9 +60,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9207.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9207.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9207.iter	2012-06-05 08:59:24 +0000
@@ -1,33 +1,33 @@
 Iterator tree for main query:
-<flwor::FLWORIterator>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
-      <OpToIterator>
-        <SingletonIterator value="xs:integer(1)"/>
-        <SingletonIterator value="xs:integer(2)"/>
-      </OpToIterator>
-    </HoistIterator>
-  </LetVariable>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+<ElementIterator>
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::FLWORIterator>
+      <LetVariable name="$$opt_temp_0" materialize="true">
+        <HoistIterator>
+          <OpToIterator>
+            <SingletonIterator value="xs:integer(1)"/>
+            <SingletonIterator value="xs:integer(2)"/>
+          </OpToIterator>
+        </HoistIterator>
+      </LetVariable>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::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>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="book">
               <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
@@ -67,9 +67,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9210.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9210.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9210.iter	2012-06-05 08:59:24 +0000
@@ -1,38 +1,38 @@
 Iterator tree for main query:
-<flwor::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>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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">
+<ElementIterator>
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::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>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::FLWORIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
                   <ForVarIterator varname="$$opt_temp_1"/>
-                </ChildAxisIterator>
-              </FnCountIterator>
-            </ValueIndexEntryBuilderIterator>
-          </ReturnClause>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="anzahl">
               <OpToIterator>
@@ -64,9 +64,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9211.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9211.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9211.iter	2012-06-05 08:59:24 +0000
@@ -1,38 +1,38 @@
 Iterator tree for main query:
-<flwor::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>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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">
+<ElementIterator>
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::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>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::FLWORIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
                   <ForVarIterator varname="$$opt_temp_1"/>
-                </ChildAxisIterator>
-              </FnCountIterator>
-            </ValueIndexEntryBuilderIterator>
-          </ReturnClause>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="anzahl">
               <OpToIterator>
@@ -67,9 +67,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9212.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9212.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9212.iter	2012-06-05 08:59:24 +0000
@@ -1,38 +1,38 @@
 Iterator tree for main query:
-<flwor::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>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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">
+<ElementIterator>
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::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>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::FLWORIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
                   <ForVarIterator varname="$$opt_temp_1"/>
-                </ChildAxisIterator>
-              </FnCountIterator>
-            </ValueIndexEntryBuilderIterator>
-          </ReturnClause>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="book">
               <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
@@ -75,9 +75,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9389.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9389.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9389.iter	2012-06-05 08:59:24 +0000
@@ -1,38 +1,38 @@
 Iterator tree for main query:
-<flwor::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>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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">
+<ElementIterator>
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::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>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::FLWORIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
                   <ForVarIterator varname="$$opt_temp_1"/>
-                </ChildAxisIterator>
-              </FnCountIterator>
-            </ValueIndexEntryBuilderIterator>
-          </ReturnClause>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="anzahl">
               <OpToIterator>
@@ -62,9 +62,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9391.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9391.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9391.iter	2012-06-05 08:59:24 +0000
@@ -1,38 +1,38 @@
 Iterator tree for main query:
-<flwor::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>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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">
+<ElementIterator>
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::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>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::FLWORIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
                   <ForVarIterator varname="$$opt_temp_1"/>
-                </ChildAxisIterator>
-              </FnCountIterator>
-            </ValueIndexEntryBuilderIterator>
-          </ReturnClause>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="anzahl">
               <OpToIterator>
@@ -67,9 +67,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9392.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9392.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9392.iter	2012-06-05 08:59:24 +0000
@@ -1,45 +1,45 @@
 Iterator tree for main query:
-<flwor::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>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <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">
+<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">
+              <flwor::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>
+                <ReturnClause>
+                  <SequentialIterator>
+                    <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+                      <flwor::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>
+                      </flwor::FLWORIterator>
+                    </CreateInternalIndexIterator>
                     <flwor::FLWORIterator>
                       <ForVariable name="anzahl">
                         <OpToIterator>
@@ -57,15 +57,15 @@
                         <ForVarIterator varname="anzahl"/>
                       </ReturnClause>
                     </flwor::FLWORIterator>
-                  </EnclosedIterator>
-                </FnConcatIterator>
-              </FnDataIterator>
-            </AttributeIterator>
-            <FnConcatIterator/>
-          </ElementIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+                  </SequentialIterator>
+                </ReturnClause>
+              </flwor::FLWORIterator>
+            </EnclosedIterator>
+          </FnConcatIterator>
+        </FnDataIterator>
+      </AttributeIterator>
+      <FnConcatIterator/>
+    </ElementIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9399.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9399.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9399.iter	2012-06-05 08:59:24 +0000
@@ -1,38 +1,38 @@
 Iterator tree for main query:
-<flwor::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>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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">
+<ElementIterator>
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::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>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::FLWORIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
                   <ForVarIterator varname="$$opt_temp_1"/>
-                </ChildAxisIterator>
-              </FnCountIterator>
-            </ValueIndexEntryBuilderIterator>
-          </ReturnClause>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="anzahl">
               <OpToIterator>
@@ -61,9 +61,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9400.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9400.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/9400.iter	2012-06-05 08:59:24 +0000
@@ -1,38 +1,38 @@
 Iterator tree for main query:
-<flwor::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>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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">
+<ElementIterator>
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::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>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::FLWORIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
                   <ForVarIterator varname="$$opt_temp_1"/>
-                </ChildAxisIterator>
-              </FnCountIterator>
-            </ValueIndexEntryBuilderIterator>
-          </ReturnClause>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator>
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="anzahl">
               <OpToIterator>
@@ -62,9 +62,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/idx4.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/idx4.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/idx4.iter	2012-06-05 08:59:24 +0000
@@ -76,89 +76,85 @@
               </TreatIterator>
             </HoistIterator>
           </LetVariable>
+          <ForVariable name="prefix">
+            <flwor::FLWORIterator>
+              <ForVariable name="prefixE">
+                <InScopePrefixesIterator>
+                  <TreatIterator quant="">
+                    <LetVarIterator varname="e"/>
+                  </TreatIterator>
+                </InScopePrefixesIterator>
+              </ForVariable>
+              <LetVariable name="$$opt_temp_1" materialize="true">
+                <HoistIterator>
+                  <NamespaceUriForPrefixIterator>
+                    <ForVarIterator varname="prefixE"/>
+                    <UnhoistIterator>
+                      <LetVarIterator varname="$$opt_temp_0"/>
+                    </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>
+                <ForVarIterator varname="prefixE"/>
+              </ReturnClause>
+            </flwor::FLWORIterator>
+          </ForVariable>
           <ReturnClause>
-            <flwor::FLWORIterator>
-              <ForVariable name="prefix">
-                <flwor::FLWORIterator>
-                  <ForVariable name="prefixE">
-                    <InScopePrefixesIterator>
-                      <TreatIterator quant="">
-                        <LetVarIterator varname="e"/>
-                      </TreatIterator>
-                    </InScopePrefixesIterator>
-                  </ForVariable>
-                  <LetVariable name="$$opt_temp_1" materialize="true">
-                    <HoistIterator>
-                      <NamespaceUriForPrefixIterator>
-                        <ForVarIterator varname="prefixE"/>
-                        <UnhoistIterator>
-                          <LetVarIterator varname="$$opt_temp_0"/>
-                        </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>
+            <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>
+                    <ConcatStrIterator>
+                      <SingletonIterator value="xs:string(xmlns:)"/>
+                      <ForVarIterator varname="prefix"/>
+                      <SingletonIterator value="xs:string(=")"/>
+                    </ConcatStrIterator>
+                    <ElementIterator>
+                      <SingletonIterator value="xs:QName(,,span)"/>
+                      <AttributeIterator qname="xs:QName(,,class)">
+                        <SingletonIterator value="xs:string(nsUri)"/>
+                      </AttributeIterator>
+                      <EnclosedIterator attr_cont="false">
                         <NamespaceUriForPrefixIterator>
-                          <ForVarIterator varname="prefixP"/>
+                          <ForVarIterator varname="prefix"/>
                           <UnhoistIterator>
-                            <ForVarIterator varname="$$opt_temp_2"/>
+                            <ForVarIterator varname="$$opt_temp_3"/>
                           </UnhoistIterator>
                         </NamespaceUriForPrefixIterator>
-                      </CompareIterator>
-                    </FnBooleanIterator>
-                  </WhereClause>
-                  <ReturnClause>
-                    <ForVarIterator varname="prefixE"/>
-                  </ReturnClause>
-                </flwor::FLWORIterator>
-              </ForVariable>
-              <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>
-                        <ConcatStrIterator>
-                          <SingletonIterator value="xs:string(xmlns:)"/>
-                          <ForVarIterator varname="prefix"/>
-                          <SingletonIterator value="xs:string(=")"/>
-                        </ConcatStrIterator>
-                        <ElementIterator>
-                          <SingletonIterator value="xs:QName(,,span)"/>
-                          <AttributeIterator qname="xs:QName(,,class)">
-                            <SingletonIterator value="xs:string(nsUri)"/>
-                          </AttributeIterator>
-                          <EnclosedIterator attr_cont="false">
-                            <NamespaceUriForPrefixIterator>
-                              <ForVarIterator varname="prefix"/>
-                              <UnhoistIterator>
-                                <ForVarIterator varname="$$opt_temp_3"/>
-                              </UnhoistIterator>
-                            </NamespaceUriForPrefixIterator>
-                          </EnclosedIterator>
-                        </ElementIterator>
-                        <SingletonIterator value="xs:string(")"/>
-                      </FnConcatIterator>
-                    </EnclosedIterator>
-                  </ElementIterator>
-                </FnConcatIterator>
-              </ReturnClause>
-            </flwor::FLWORIterator>
+                      </EnclosedIterator>
+                    </ElementIterator>
+                    <SingletonIterator value="xs:string(")"/>
+                  </FnConcatIterator>
+                </EnclosedIterator>
+              </ElementIterator>
+            </FnConcatIterator>
           </ReturnClause>
         </flwor::FLWORIterator>
       </SequentialIterator>

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/idx5.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/idx5.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/hashjoins/idx5.iter	2012-06-05 08:59:24 +0000
@@ -19,98 +19,94 @@
       <SingletonIterator value="xs:QName(,,tests)"/>
     </ElementIterator>
   </CtxVarDeclareIterator>
-  <flwor::FLWORIterator>
-    <LetVariable name="$$opt_temp_1" materialize="true">
-      <HoistIterator>
-        <flwor::FLWORIterator>
-          <ForVariable name="$$dot">
-            <CtxVarIterator varid="2" varname="tests" varkind="global"/>
-          </ForVariable>
-          <WhereClause>
-            <FnBooleanIterator>
-              <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
-                <TreatIterator type="[NodeXQType anyNode content=[XQType ANY_TYPE_KIND*]]" quant="*">
-                  <ForVarIterator varname="$$dot"/>
-                </TreatIterator>
-              </AttributeAxisIterator>
-            </FnBooleanIterator>
-          </WhereClause>
-          <ReturnClause>
-            <ForVarIterator varname="$$dot"/>
-          </ReturnClause>
-        </flwor::FLWORIterator>
-      </HoistIterator>
-    </LetVariable>
-    <ReturnClause>
-      <SequentialIterator>
-        <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+  <SequentialIterator>
+    <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+      <flwor::FLWORIterator>
+        <ForVariable name="$$opt_temp_2">
+          <CtxVarIterator varid="2" varname="tests" varkind="global"/>
+        </ForVariable>
+        <ReturnClause>
+          <ValueIndexEntryBuilderIterator>
+            <ForVarIterator varname="$$opt_temp_2"/>
+            <CastIterator type="xs:string">
+              <PromoteIterator type="xs:anyAtomicType">
+                <FnDataIterator>
+                  <ChildAxisIterator test kind="match_text_test" qname="*" typename="*" nill allowed="0">
+                    <TreatIterator type="[NodeXQType anyNode content=[XQType ANY_TYPE_KIND*]]" quant="*">
+                      <ForVarIterator varname="$$opt_temp_2"/>
+                    </TreatIterator>
+                  </ChildAxisIterator>
+                </FnDataIterator>
+              </PromoteIterator>
+            </CastIterator>
+          </ValueIndexEntryBuilderIterator>
+        </ReturnClause>
+      </flwor::FLWORIterator>
+    </CreateInternalIndexIterator>
+    <flwor::FLWORIterator>
+      <LetVariable name="$$opt_temp_1" materialize="true">
+        <HoistIterator>
           <flwor::FLWORIterator>
-            <ForVariable name="$$opt_temp_2">
+            <ForVariable name="$$dot">
               <CtxVarIterator varid="2" varname="tests" varkind="global"/>
             </ForVariable>
+            <WhereClause>
+              <FnBooleanIterator>
+                <AttributeAxisIterator test kind="match_name_test" qname="xs:QName(,,name)" typename="*" nill allowed="0">
+                  <TreatIterator type="[NodeXQType anyNode content=[XQType ANY_TYPE_KIND*]]" quant="*">
+                    <ForVarIterator varname="$$dot"/>
+                  </TreatIterator>
+                </AttributeAxisIterator>
+              </FnBooleanIterator>
+            </WhereClause>
             <ReturnClause>
-              <ValueIndexEntryBuilderIterator>
-                <ForVarIterator varname="$$opt_temp_2"/>
-                <CastIterator type="xs:string">
-                  <PromoteIterator type="xs:anyAtomicType">
-                    <FnDataIterator>
-                      <ChildAxisIterator test kind="match_text_test" qname="*" typename="*" nill allowed="0">
-                        <TreatIterator type="[NodeXQType anyNode content=[XQType ANY_TYPE_KIND*]]" quant="*">
-                          <ForVarIterator varname="$$opt_temp_2"/>
-                        </TreatIterator>
-                      </ChildAxisIterator>
-                    </FnDataIterator>
-                  </PromoteIterator>
-                </CastIterator>
-              </ValueIndexEntryBuilderIterator>
+              <ForVarIterator varname="$$dot"/>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </CreateInternalIndexIterator>
+        </HoistIterator>
+      </LetVariable>
+      <ForVariable name="test">
+        <CtxVarIterator varid="2" varname="tests" varkind="global"/>
+      </ForVariable>
+      <LetVariable name="$$opt_temp_0" materialize="true">
+        <HoistIterator>
+          <CastIterator type="xs:string">
+            <PromoteIterator type="xs:anyAtomicType">
+              <FnDataIterator>
+                <ChildAxisIterator test kind="match_text_test" qname="*" typename="*" nill allowed="0">
+                  <TreatIterator type="[NodeXQType anyNode content=[XQType ANY_TYPE_KIND*]]" quant="*">
+                    <ForVarIterator varname="test"/>
+                  </TreatIterator>
+                </ChildAxisIterator>
+              </FnDataIterator>
+            </PromoteIterator>
+          </CastIterator>
+        </HoistIterator>
+      </LetVariable>
+      <LetVariable name="test_old" materialize="true">
         <flwor::FLWORIterator>
-          <ForVariable name="test">
-            <CtxVarIterator varid="2" varname="tests" varkind="global"/>
+          <ForVariable name="$$dot">
+            <ProbeIndexPointValueIterator>
+              <SingletonIterator value="xs:QName(,,tempIndex0)"/>
+              <UnhoistIterator>
+                <LetVarIterator varname="$$opt_temp_0"/>
+              </UnhoistIterator>
+            </ProbeIndexPointValueIterator>
           </ForVariable>
-          <LetVariable name="$$opt_temp_0" materialize="true">
-            <HoistIterator>
-              <CastIterator type="xs:string">
-                <PromoteIterator type="xs:anyAtomicType">
-                  <FnDataIterator>
-                    <ChildAxisIterator test kind="match_text_test" qname="*" typename="*" nill allowed="0">
-                      <TreatIterator type="[NodeXQType anyNode content=[XQType ANY_TYPE_KIND*]]" quant="*">
-                        <ForVarIterator varname="test"/>
-                      </TreatIterator>
-                    </ChildAxisIterator>
-                  </FnDataIterator>
-                </PromoteIterator>
-              </CastIterator>
-            </HoistIterator>
-          </LetVariable>
-          <LetVariable name="test_old" materialize="true">
-            <flwor::FLWORIterator>
-              <ForVariable name="$$dot">
-                <ProbeIndexPointValueIterator>
-                  <SingletonIterator value="xs:QName(,,tempIndex0)"/>
-                  <UnhoistIterator>
-                    <LetVarIterator varname="$$opt_temp_0"/>
-                  </UnhoistIterator>
-                </ProbeIndexPointValueIterator>
-              </ForVariable>
-              <ReturnClause>
-                <ForVarIterator varname="$$dot"/>
-              </ReturnClause>
-            </flwor::FLWORIterator>
-          </LetVariable>
-          <LetVariable name="qt_old" materialize="true">
-            <UnhoistIterator>
-              <LetVarIterator varname="$$opt_temp_1"/>
-            </UnhoistIterator>
-          </LetVariable>
           <ReturnClause>
-            <SingletonIterator value="xs:integer(1)"/>
+            <ForVarIterator varname="$$dot"/>
           </ReturnClause>
         </flwor::FLWORIterator>
-      </SequentialIterator>
-    </ReturnClause>
-  </flwor::FLWORIterator>
+      </LetVariable>
+      <LetVariable name="qt_old" materialize="true">
+        <UnhoistIterator>
+          <LetVarIterator varname="$$opt_temp_1"/>
+        </UnhoistIterator>
+      </LetVariable>
+      <ReturnClause>
+        <SingletonIterator value="xs:integer(1)"/>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </SequentialIterator>
 </SequentialIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/misc/hoist4.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/misc/hoist4.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/misc/hoist4.iter	2012-06-05 08:59:24 +0000
@@ -83,27 +83,23 @@
             </GenericArithIterator_AddOperation>
           </HoistIterator>
         </LetVariable>
+        <ForVariable name="c">
+          <OpToIterator>
+            <SingletonIterator value="xs:integer(1)"/>
+            <PromoteIterator type="xs:integer">
+              <FnDataIterator>
+                <CtxVarIterator varid="2" varname="x" varkind="local"/>
+              </FnDataIterator>
+            </PromoteIterator>
+          </OpToIterator>
+        </ForVariable>
         <ReturnClause>
-          <flwor::FLWORIterator>
-            <ForVariable name="c">
-              <OpToIterator>
-                <SingletonIterator value="xs:integer(1)"/>
-                <PromoteIterator type="xs:integer">
-                  <FnDataIterator>
-                    <CtxVarIterator varid="2" varname="x" varkind="local"/>
-                  </FnDataIterator>
-                </PromoteIterator>
-              </OpToIterator>
-            </ForVariable>
-            <ReturnClause>
-              <GenericArithIterator_AddOperation>
-                <UnhoistIterator>
-                  <LetVarIterator varname="$$opt_temp_0"/>
-                </UnhoistIterator>
-                <ForVarIterator varname="c"/>
-              </GenericArithIterator_AddOperation>
-            </ReturnClause>
-          </flwor::FLWORIterator>
+          <GenericArithIterator_AddOperation>
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_0"/>
+            </UnhoistIterator>
+            <ForVarIterator varname="c"/>
+          </GenericArithIterator_AddOperation>
         </ReturnClause>
       </flwor::FLWORIterator>
     </SequentialIterator>

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-9198.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-9198.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-9198.iter	2012-06-05 08:59:24 +0000
@@ -1,33 +1,33 @@
 Iterator tree for main query:
-<flwor::FLWORIterator>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
-      <OpToIterator>
-        <SingletonIterator value="xs:integer(1)"/>
-        <SingletonIterator value="xs:integer(2)"/>
-      </OpToIterator>
-    </HoistIterator>
-  </LetVariable>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator copyInputNodes="false">
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+<ElementIterator copyInputNodes="false">
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::FLWORIterator>
+      <LetVariable name="$$opt_temp_0" materialize="true">
+        <HoistIterator>
+          <OpToIterator>
+            <SingletonIterator value="xs:integer(1)"/>
+            <SingletonIterator value="xs:integer(2)"/>
+          </OpToIterator>
+        </HoistIterator>
+      </LetVariable>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::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>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="book">
               <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
@@ -67,9 +67,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-9199.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-9199.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-9199.iter	2012-06-05 08:59:24 +0000
@@ -1,33 +1,33 @@
 Iterator tree for main query:
-<flwor::FLWORIterator>
-  <LetVariable name="$$opt_temp_0" materialize="true">
-    <HoistIterator>
-      <OpToIterator>
-        <SingletonIterator value="xs:integer(1)"/>
-        <SingletonIterator value="xs:integer(2)"/>
-      </OpToIterator>
-    </HoistIterator>
-  </LetVariable>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator copyInputNodes="false">
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+<ElementIterator copyInputNodes="false">
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::FLWORIterator>
+      <LetVariable name="$$opt_temp_0" materialize="true">
+        <HoistIterator>
+          <OpToIterator>
+            <SingletonIterator value="xs:integer(1)"/>
+            <SingletonIterator value="xs:integer(2)"/>
+          </OpToIterator>
+        </HoistIterator>
+      </LetVariable>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::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>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="book">
               <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
@@ -67,9 +67,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-9212.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-9212.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-9212.iter	2012-06-05 08:59:24 +0000
@@ -1,38 +1,38 @@
 Iterator tree for main query:
-<flwor::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>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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">
+<ElementIterator copyInputNodes="false">
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::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>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::FLWORIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
                   <ForVarIterator varname="$$opt_temp_1"/>
-                </ChildAxisIterator>
-              </FnCountIterator>
-            </ValueIndexEntryBuilderIterator>
-          </ReturnClause>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator copyInputNodes="false">
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="book">
               <DescendantAxisIterator test kind="match_name_test" qname="xs:QName(,,book)" typename="*" nill allowed="0">
@@ -75,9 +75,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-9389.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-9389.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-9389.iter	2012-06-05 08:59:24 +0000
@@ -1,38 +1,38 @@
 Iterator tree for main query:
-<flwor::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>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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">
+<ElementIterator copyInputNodes="false">
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <flwor::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>
+      <ReturnClause>
+        <SequentialIterator>
+          <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+            <flwor::FLWORIterator>
+              <ForVariable name="$$opt_temp_1">
+                <UnhoistIterator>
+                  <LetVarIterator varname="$$opt_temp_0"/>
+                </UnhoistIterator>
+              </ForVariable>
+              <ReturnClause>
+                <ValueIndexEntryBuilderIterator>
                   <ForVarIterator varname="$$opt_temp_1"/>
-                </ChildAxisIterator>
-              </FnCountIterator>
-            </ValueIndexEntryBuilderIterator>
-          </ReturnClause>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator copyInputNodes="false">
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
+                  <FnCountIterator>
+                    <ChildAxisIterator test kind="match_name_test" qname="xs:QName(,,author)" typename="*" nill allowed="0">
+                      <ForVarIterator varname="$$opt_temp_1"/>
+                    </ChildAxisIterator>
+                  </FnCountIterator>
+                </ValueIndexEntryBuilderIterator>
+              </ReturnClause>
+            </flwor::FLWORIterator>
+          </CreateInternalIndexIterator>
           <flwor::FLWORIterator>
             <ForVariable name="anzahl">
               <OpToIterator>
@@ -62,9 +62,9 @@
               </ElementIterator>
             </ReturnClause>
           </flwor::FLWORIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+        </SequentialIterator>
+      </ReturnClause>
+    </flwor::FLWORIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-9392.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-9392.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-9392.iter	2012-06-05 08:59:24 +0000
@@ -1,45 +1,45 @@
 Iterator tree for main query:
-<flwor::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>
-  <ReturnClause>
-    <SequentialIterator>
-      <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
-        <flwor::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>
-        </flwor::FLWORIterator>
-      </CreateInternalIndexIterator>
-      <ElementIterator copyInputNodes="false">
-        <SingletonIterator value="xs:QName(,,karteikasten)"/>
-        <EnclosedIterator attr_cont="false">
-          <ElementIterator copyInputNodes="false">
-            <SingletonIterator value="xs:QName(,,gruppe)"/>
-            <AttributeIterator qname="xs:QName(,,anzahl)">
-              <FnDataIterator>
-                <FnConcatIterator>
-                  <SingletonIterator value="xs:string( )"/>
-                  <EnclosedIterator attr_cont="true">
+<ElementIterator copyInputNodes="false">
+  <SingletonIterator value="xs:QName(,,karteikasten)"/>
+  <EnclosedIterator attr_cont="false">
+    <ElementIterator copyInputNodes="false">
+      <SingletonIterator value="xs:QName(,,gruppe)"/>
+      <AttributeIterator qname="xs:QName(,,anzahl)">
+        <FnDataIterator>
+          <FnConcatIterator>
+            <SingletonIterator value="xs:string( )"/>
+            <EnclosedIterator attr_cont="true">
+              <flwor::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>
+                <ReturnClause>
+                  <SequentialIterator>
+                    <CreateInternalIndexIterator name="xs:QName(,,tempIndex0)">
+                      <flwor::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>
+                      </flwor::FLWORIterator>
+                    </CreateInternalIndexIterator>
                     <flwor::FLWORIterator>
                       <ForVariable name="anzahl">
                         <OpToIterator>
@@ -57,15 +57,15 @@
                         <ForVarIterator varname="anzahl"/>
                       </ReturnClause>
                     </flwor::FLWORIterator>
-                  </EnclosedIterator>
-                </FnConcatIterator>
-              </FnDataIterator>
-            </AttributeIterator>
-            <FnConcatIterator/>
-          </ElementIterator>
-        </EnclosedIterator>
-      </ElementIterator>
-    </SequentialIterator>
-  </ReturnClause>
-</flwor::FLWORIterator>
+                  </SequentialIterator>
+                </ReturnClause>
+              </flwor::FLWORIterator>
+            </EnclosedIterator>
+          </FnConcatIterator>
+        </FnDataIterator>
+      </AttributeIterator>
+      <FnConcatIterator/>
+    </ElementIterator>
+  </EnclosedIterator>
+</ElementIterator>
 

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-idx4.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-idx4.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/no-copy/hashjoin-idx4.iter	2012-06-05 08:59:24 +0000
@@ -76,89 +76,85 @@
               </TreatIterator>
             </HoistIterator>
           </LetVariable>
+          <ForVariable name="prefix">
+            <flwor::FLWORIterator>
+              <ForVariable name="prefixE">
+                <InScopePrefixesIterator>
+                  <TreatIterator quant="">
+                    <LetVarIterator varname="e"/>
+                  </TreatIterator>
+                </InScopePrefixesIterator>
+              </ForVariable>
+              <LetVariable name="$$opt_temp_1" materialize="true">
+                <HoistIterator>
+                  <NamespaceUriForPrefixIterator>
+                    <ForVarIterator varname="prefixE"/>
+                    <UnhoistIterator>
+                      <LetVarIterator varname="$$opt_temp_0"/>
+                    </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>
+                <ForVarIterator varname="prefixE"/>
+              </ReturnClause>
+            </flwor::FLWORIterator>
+          </ForVariable>
           <ReturnClause>
-            <flwor::FLWORIterator>
-              <ForVariable name="prefix">
-                <flwor::FLWORIterator>
-                  <ForVariable name="prefixE">
-                    <InScopePrefixesIterator>
-                      <TreatIterator quant="">
-                        <LetVarIterator varname="e"/>
-                      </TreatIterator>
-                    </InScopePrefixesIterator>
-                  </ForVariable>
-                  <LetVariable name="$$opt_temp_1" materialize="true">
-                    <HoistIterator>
-                      <NamespaceUriForPrefixIterator>
-                        <ForVarIterator varname="prefixE"/>
-                        <UnhoistIterator>
-                          <LetVarIterator varname="$$opt_temp_0"/>
-                        </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>
+            <FnConcatIterator>
+              <SingletonIterator value="xs:string( )"/>
+              <ElementIterator copyInputNodes="false">
+                <SingletonIterator value="xs:QName(,,span)"/>
+                <AttributeIterator qname="xs:QName(,,class)">
+                  <SingletonIterator value="xs:string(ns)"/>
+                </AttributeIterator>
+                <EnclosedIterator attr_cont="false">
+                  <FnConcatIterator>
+                    <ConcatStrIterator>
+                      <SingletonIterator value="xs:string(xmlns:)"/>
+                      <ForVarIterator varname="prefix"/>
+                      <SingletonIterator value="xs:string(=")"/>
+                    </ConcatStrIterator>
+                    <ElementIterator copyInputNodes="false">
+                      <SingletonIterator value="xs:QName(,,span)"/>
+                      <AttributeIterator qname="xs:QName(,,class)">
+                        <SingletonIterator value="xs:string(nsUri)"/>
+                      </AttributeIterator>
+                      <EnclosedIterator attr_cont="false">
                         <NamespaceUriForPrefixIterator>
-                          <ForVarIterator varname="prefixP"/>
+                          <ForVarIterator varname="prefix"/>
                           <UnhoistIterator>
-                            <ForVarIterator varname="$$opt_temp_2"/>
+                            <ForVarIterator varname="$$opt_temp_3"/>
                           </UnhoistIterator>
                         </NamespaceUriForPrefixIterator>
-                      </CompareIterator>
-                    </FnBooleanIterator>
-                  </WhereClause>
-                  <ReturnClause>
-                    <ForVarIterator varname="prefixE"/>
-                  </ReturnClause>
-                </flwor::FLWORIterator>
-              </ForVariable>
-              <ReturnClause>
-                <FnConcatIterator>
-                  <SingletonIterator value="xs:string( )"/>
-                  <ElementIterator copyInputNodes="false">
-                    <SingletonIterator value="xs:QName(,,span)"/>
-                    <AttributeIterator qname="xs:QName(,,class)">
-                      <SingletonIterator value="xs:string(ns)"/>
-                    </AttributeIterator>
-                    <EnclosedIterator attr_cont="false">
-                      <FnConcatIterator>
-                        <ConcatStrIterator>
-                          <SingletonIterator value="xs:string(xmlns:)"/>
-                          <ForVarIterator varname="prefix"/>
-                          <SingletonIterator value="xs:string(=")"/>
-                        </ConcatStrIterator>
-                        <ElementIterator copyInputNodes="false">
-                          <SingletonIterator value="xs:QName(,,span)"/>
-                          <AttributeIterator qname="xs:QName(,,class)">
-                            <SingletonIterator value="xs:string(nsUri)"/>
-                          </AttributeIterator>
-                          <EnclosedIterator attr_cont="false">
-                            <NamespaceUriForPrefixIterator>
-                              <ForVarIterator varname="prefix"/>
-                              <UnhoistIterator>
-                                <ForVarIterator varname="$$opt_temp_3"/>
-                              </UnhoistIterator>
-                            </NamespaceUriForPrefixIterator>
-                          </EnclosedIterator>
-                        </ElementIterator>
-                        <SingletonIterator value="xs:string(")"/>
-                      </FnConcatIterator>
-                    </EnclosedIterator>
-                  </ElementIterator>
-                </FnConcatIterator>
-              </ReturnClause>
-            </flwor::FLWORIterator>
+                      </EnclosedIterator>
+                    </ElementIterator>
+                    <SingletonIterator value="xs:string(")"/>
+                  </FnConcatIterator>
+                </EnclosedIterator>
+              </ElementIterator>
+            </FnConcatIterator>
           </ReturnClause>
         </flwor::FLWORIterator>
       </SequentialIterator>

=== modified file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/xray/ppm_10.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/xray/ppm_10.iter	2012-05-03 12:31:51 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/xray/ppm_10.iter	2012-06-05 08:59:24 +0000
@@ -354,124 +354,120 @@
       </TreatIterator>
     </UDFunctionCallIterator>
   </CtxVarDeclareIterator>
-  <flwor::FLWORIterator>
-    <LetVariable name="$$opt_temp_0" materialize="true">
-      <HoistIterator>
-        <OpToIterator>
-          <SingletonIterator value="xs:integer(1)"/>
-          <CtxVarIterator varid="2" varname="width" varkind="global"/>
-        </OpToIterator>
-      </HoistIterator>
-    </LetVariable>
-    <LetVariable name="$$opt_temp_1" materialize="true">
-      <HoistIterator>
-        <TreatIterator type="[NodeXQType elementNode content=[XQType ANY_TYPE_KIND*]]" quant="">
-          <CtxVarIterator varid="4" varname="scene" varkind="global"/>
-        </TreatIterator>
-      </HoistIterator>
-    </LetVariable>
-    <ReturnClause>
+  <FnConcatIterator>
+    <StringJoinIterator>
       <FnConcatIterator>
+        <SingletonIterator value="xs:string(P3)"/>
         <StringJoinIterator>
           <FnConcatIterator>
-            <SingletonIterator value="xs:string(P3)"/>
+            <FnStringIterator>
+              <CtxVarIterator varid="2" varname="width" varkind="global"/>
+            </FnStringIterator>
+            <FnStringIterator>
+              <CtxVarIterator varid="3" varname="height" varkind="global"/>
+            </FnStringIterator>
+          </FnConcatIterator>
+          <SingletonIterator value="xs:string( )"/>
+        </StringJoinIterator>
+        <SingletonIterator value="xs:string(255)"/>
+        <flwor::FLWORIterator>
+          <LetVariable name="$$opt_temp_1" materialize="true">
+            <HoistIterator>
+              <TreatIterator type="[NodeXQType elementNode content=[XQType ANY_TYPE_KIND*]]" quant="">
+                <CtxVarIterator varid="4" varname="scene" varkind="global"/>
+              </TreatIterator>
+            </HoistIterator>
+          </LetVariable>
+          <LetVariable name="$$opt_temp_0" materialize="true">
+            <HoistIterator>
+              <OpToIterator>
+                <SingletonIterator value="xs:integer(1)"/>
+                <CtxVarIterator varid="2" varname="width" varkind="global"/>
+              </OpToIterator>
+            </HoistIterator>
+          </LetVariable>
+          <ForVariable name="aspect-ratio">
+            <SpecificNumArithIterator_DivideOperation_DECIMAL>
+              <CtxVarIterator varid="2" varname="width" varkind="global"/>
+              <CtxVarIterator varid="3" varname="height" varkind="global"/>
+            </SpecificNumArithIterator_DivideOperation_DECIMAL>
+          </ForVariable>
+          <ForVariable name="y">
+            <OpToIterator>
+              <SingletonIterator value="xs:integer(1)"/>
+              <CtxVarIterator varid="3" varname="height" varkind="global"/>
+            </OpToIterator>
+          </ForVariable>
+          <ForVariable name="y-recentered">
+            <SpecificNumArithIterator_AddOperation_DECIMAL>
+              <SpecificNumArithIterator_DivideOperation_DECIMAL>
+                <OpNumericUnaryIterator>
+                  <ForVarIterator varname="y"/>
+                </OpNumericUnaryIterator>
+                <CtxVarIterator varid="3" varname="height" varkind="global"/>
+              </SpecificNumArithIterator_DivideOperation_DECIMAL>
+              <SingletonIterator value="xs:decimal(0.5)"/>
+            </SpecificNumArithIterator_AddOperation_DECIMAL>
+          </ForVariable>
+          <LetVariable name="$$opt_temp_2" materialize="true">
+            <HoistIterator>
+              <PromoteIterator type="xs:double">
+                <ForVarIterator varname="y-recentered"/>
+              </PromoteIterator>
+            </HoistIterator>
+          </LetVariable>
+          <ForVariable name="x">
+            <UnhoistIterator>
+              <LetVarIterator varname="$$opt_temp_0"/>
+            </UnhoistIterator>
+          </ForVariable>
+          <ReturnClause>
             <StringJoinIterator>
-              <FnConcatIterator>
-                <FnStringIterator>
-                  <CtxVarIterator varid="2" varname="width" varkind="global"/>
-                </FnStringIterator>
-                <FnStringIterator>
-                  <CtxVarIterator varid="3" varname="height" varkind="global"/>
-                </FnStringIterator>
-              </FnConcatIterator>
+              <flwor::FLWORIterator>
+                <ForVariable name="channel">
+                  <UDFunctionCallIterator>
+                    <UnhoistIterator>
+                      <LetVarIterator varname="$$opt_temp_1"/>
+                    </UnhoistIterator>
+                    <PromoteIterator type="xs:double">
+                      <SpecificNumArithIterator_MultiplyOperation_DECIMAL>
+                        <SpecificNumArithIterator_SubtractOperation_DECIMAL>
+                          <SpecificNumArithIterator_DivideOperation_DECIMAL>
+                            <ForVarIterator varname="x"/>
+                            <CtxVarIterator varid="2" varname="width" varkind="global"/>
+                          </SpecificNumArithIterator_DivideOperation_DECIMAL>
+                          <SingletonIterator value="xs:decimal(0.5)"/>
+                        </SpecificNumArithIterator_SubtractOperation_DECIMAL>
+                        <ForVarIterator varname="aspect-ratio"/>
+                      </SpecificNumArithIterator_MultiplyOperation_DECIMAL>
+                    </PromoteIterator>
+                    <UnhoistIterator>
+                      <LetVarIterator varname="$$opt_temp_2"/>
+                    </UnhoistIterator>
+                  </UDFunctionCallIterator>
+                </ForVariable>
+                <ReturnClause>
+                  <FnStringIterator>
+                    <FloorIterator>
+                      <SpecificNumArithIterator_MultiplyOperation_DOUBLE>
+                        <ForVarIterator varname="channel"/>
+                        <SingletonIterator value="xs:double(255)"/>
+                      </SpecificNumArithIterator_MultiplyOperation_DOUBLE>
+                    </FloorIterator>
+                  </FnStringIterator>
+                </ReturnClause>
+              </flwor::FLWORIterator>
               <SingletonIterator value="xs:string( )"/>
             </StringJoinIterator>
-            <SingletonIterator value="xs:string(255)"/>
-            <flwor::FLWORIterator>
-              <ForVariable name="aspect-ratio">
-                <SpecificNumArithIterator_DivideOperation_DECIMAL>
-                  <CtxVarIterator varid="2" varname="width" varkind="global"/>
-                  <CtxVarIterator varid="3" varname="height" varkind="global"/>
-                </SpecificNumArithIterator_DivideOperation_DECIMAL>
-              </ForVariable>
-              <ForVariable name="y">
-                <OpToIterator>
-                  <SingletonIterator value="xs:integer(1)"/>
-                  <CtxVarIterator varid="3" varname="height" varkind="global"/>
-                </OpToIterator>
-              </ForVariable>
-              <ForVariable name="y-recentered">
-                <SpecificNumArithIterator_AddOperation_DECIMAL>
-                  <SpecificNumArithIterator_DivideOperation_DECIMAL>
-                    <OpNumericUnaryIterator>
-                      <ForVarIterator varname="y"/>
-                    </OpNumericUnaryIterator>
-                    <CtxVarIterator varid="3" varname="height" varkind="global"/>
-                  </SpecificNumArithIterator_DivideOperation_DECIMAL>
-                  <SingletonIterator value="xs:decimal(0.5)"/>
-                </SpecificNumArithIterator_AddOperation_DECIMAL>
-              </ForVariable>
-              <LetVariable name="$$opt_temp_2" materialize="true">
-                <HoistIterator>
-                  <PromoteIterator type="xs:double">
-                    <ForVarIterator varname="y-recentered"/>
-                  </PromoteIterator>
-                </HoistIterator>
-              </LetVariable>
-              <ForVariable name="x">
-                <UnhoistIterator>
-                  <LetVarIterator varname="$$opt_temp_0"/>
-                </UnhoistIterator>
-              </ForVariable>
-              <ReturnClause>
-                <StringJoinIterator>
-                  <flwor::FLWORIterator>
-                    <ForVariable name="channel">
-                      <UDFunctionCallIterator>
-                        <UnhoistIterator>
-                          <LetVarIterator varname="$$opt_temp_1"/>
-                        </UnhoistIterator>
-                        <PromoteIterator type="xs:double">
-                          <SpecificNumArithIterator_MultiplyOperation_DECIMAL>
-                            <SpecificNumArithIterator_SubtractOperation_DECIMAL>
-                              <SpecificNumArithIterator_DivideOperation_DECIMAL>
-                                <ForVarIterator varname="x"/>
-                                <CtxVarIterator varid="2" varname="width" varkind="global"/>
-                              </SpecificNumArithIterator_DivideOperation_DECIMAL>
-                              <SingletonIterator value="xs:decimal(0.5)"/>
-                            </SpecificNumArithIterator_SubtractOperation_DECIMAL>
-                            <ForVarIterator varname="aspect-ratio"/>
-                          </SpecificNumArithIterator_MultiplyOperation_DECIMAL>
-                        </PromoteIterator>
-                        <UnhoistIterator>
-                          <LetVarIterator varname="$$opt_temp_2"/>
-                        </UnhoistIterator>
-                      </UDFunctionCallIterator>
-                    </ForVariable>
-                    <ReturnClause>
-                      <FnStringIterator>
-                        <FloorIterator>
-                          <SpecificNumArithIterator_MultiplyOperation_DOUBLE>
-                            <ForVarIterator varname="channel"/>
-                            <SingletonIterator value="xs:double(255)"/>
-                          </SpecificNumArithIterator_MultiplyOperation_DOUBLE>
-                        </FloorIterator>
-                      </FnStringIterator>
-                    </ReturnClause>
-                  </flwor::FLWORIterator>
-                  <SingletonIterator value="xs:string( )"/>
-                </StringJoinIterator>
-              </ReturnClause>
-            </flwor::FLWORIterator>
-          </FnConcatIterator>
-          <SingletonIterator value="xs:string(
-)"/>
-        </StringJoinIterator>
-        <SingletonIterator value="xs:string(
-)"/>
+          </ReturnClause>
+        </flwor::FLWORIterator>
       </FnConcatIterator>
-    </ReturnClause>
-  </flwor::FLWORIterator>
+      <SingletonIterator value="xs:string(
+)"/>
+    </StringJoinIterator>
+    <SingletonIterator value="xs:string(
+)"/>
+  </FnConcatIterator>
 </SequentialIterator>
 
 Iterator tree for scene:prepare-scene:

=== modified file 'test/rbkt/Queries/zorba/hashjoins/idx10.xq'
--- test/rbkt/Queries/zorba/hashjoins/idx10.xq	2012-03-29 21:13:41 +0000
+++ test/rbkt/Queries/zorba/hashjoins/idx10.xq	2012-06-05 08:59:24 +0000
@@ -16,7 +16,7 @@
 {
   for $i in local:bar()/@id
   for $j in local:foo()/@id
-  where xs:string($i)  eq xs:string($j)
+  where xs:string($i) eq xs:string($j)
   return $i
 }
 catch * 
@@ -25,3 +25,136 @@
 }
 
 
+(:
+
+Expression tree after optimization for main query
+flwor_expr (0x8d66cd0) 
+[
+  LET (0x8d66c88) $$opt_temp_0 (0x8d66e40)
+  [
+    hoist/1 (0x8d66c28) [ hoist/1 (0x8d6b298) [ error/0 (0x8d6ae08) [ ] ] ]
+  ]
+  LET (0x8d66f20) $$opt_temp_1 (0x8d670d8)
+  [
+    hoist/1 (0x8d66ec0) [
+      to/2 (0x8d6afa8) [
+        const_expr (0x8d6b008) [ xs:integer [ xs:integer(1) ] ]
+        const_expr (0x8d68c48) [ xs:integer [ xs:integer(10) ] ]
+      ]
+    ]
+  ]
+  RETURN
+    trycatch_expr (0x8d6f258) 
+    [
+      flwor_expr (0x8d6fca8) 
+      [
+        FOR (0x8d6b2f8) i (0x8d6e7f8)
+        [
+          sort-distinct-nodes-asc/1 (0x8d6e690) [
+            relpath_expr (0x8d6b238) [
+              function_trace_expr (0x8d6f530) [
+                flwor_expr (0x8d6b510) 
+                [
+                  FOR (0x8d6e7b0) i (0x8d6f5f0)
+                  [
+                    to/2 (0x8d6b578) [
+                      const_expr (0x8d6e6f0) [ xs:integer [ xs:integer(1) ] ]
+                      const_expr (0x8d6e748) [ xs:integer [ xs:integer(10) ] ]
+                    ]
+                  ]
+                  RETURN
+                    elem_expr (0x8d6f4c8) [
+                      copy nodes = 1
+                      const_expr (0x8d6f690) [ xs:QName [ xs:QName(,,b) ] ]
+                      attr_expr (0x8d6f470) [
+                        const_expr (0x8d6dd28) [ xs:QName [ xs:QName(,,id) ] ]
+                        =
+                        enclosed-expr/1 (0x8d6dd80) [
+                            var_ref (0x8d6dde0) [ i (0x8d6f5f0) ]
+                          ]
+                      ]
+                    ]
+                ]
+              ]
+                REL STEP attribute::match_expr [name_test(id)]
+            ]
+          ]
+        ]
+        LET (0x8d671c8) $$opt_temp_2 (0x8d67030)
+        [
+          hoist/1 (0x8d67158) [
+            cast_expr xs:string? (0x8d6f8a8) [
+              data/1 (0x8d6f848) [ var_ref (0x8d6f7b8) [ i (0x8d6e7f8) ] ]
+            ]
+          ]
+        ]
+        FOR (0x8d6f770) j (0x8d6f360)
+        [
+          sort-distinct-nodes-asc/1 (0x8d6f1f8) [
+            relpath_expr (0x8d6e8d0) [
+              function_trace_expr (0x8d692e0) [
+                flwor_expr (0x8d6ada0) 
+                [
+                  FOR (0x8d69590) $$opt_temp_0 (0x8d69510)
+                  [
+                    unhoist (0x8d66d90) [ vref(0x8d66d38) [ $$opt_temp_0 (0x8d66e40) ] ]
+                  ]
+                  FOR (0x8d68d50) i (0x8d68cb0)
+                  [
+                    unhoist (0x8d66fd0) [ vref (0x8d66f78) [ $$opt_temp_1 (0x8d670d8) ] ]
+                  ]
+                  RETURN
+                    if_expr (0x8d69280) [
+                      value-equal-integer/2 (0x8d68d98) [
+                        numeric-mod/2 (0x8d68df8) [
+                          var_ref (0x8d68e58) [ i (0x8d68cb0) ]
+                          const_expr (0x8d68ec0) [ xs:integer [ xs:integer(2) ] ]
+                        ]
+                        const_expr (0x8d68f28) [ xs:integer [ xs:integer(0) ] ]
+                      ]
+                      THEN
+                        elem_expr (0x8d69150) [
+                          copy nodes = 1
+                          const_expr (0x8d68f90) [ xs:QName [ xs:QName(,,a) ] ]
+                          attr_expr (0x8d690f8) [
+                            const_expr (0x8d68fe8) [ xs:QName [ xs:QName(,,id) ] ]
+                            =
+                              enclosed-expr/1 (0x8d69040) [
+                                var_ref (0x8d690a0) [ i (0x8d68cb0) ]
+                              ]
+                          ]
+                        ]
+                      ELSE
+                        unhoist/1 (0x8d691b8) [
+                          var_ref (0x8d69218) [ $$opt_temp_0 (0x8d69510) ]
+                        ]
+                    ]
+                ]
+              ]
+                REL STEP attribute::match_expr [name_test(id)]
+            ]
+          ]
+        ]
+        WHERE
+          boolean/1 (0x8d6fbf0) [
+            value-equal-string/2 (0x8d6fa10) [
+              unhoist/1 (0x8d67268) [
+                var_ref (0x8d67210) [ $$opt_temp_2 (0x8d67030) ]
+              ]
+              cast_expr xs:string? (0x8d6f9b8) [
+                data/1 (0x8d6f958) [
+                  var_ref (0x8d6f900) [ j (0x8d6f360) ]
+                ]
+              ]
+            ]
+          ]
+        RETURN
+          var_ref (0x8d6fc50) [ i (0x8d6e7f8) ]
+      ]
+      CATCH 
+      const_expr (0x8d6ff10) [ xs:string [ xs:string(caught) ] ]
+    ]
+]
+
+
+:)


Follow ups