Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-scratch 
into lp:zorba.

Commit message:
Fixed bug in probing multi-key value-range indexes

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/141812

Fixed bug in probing multi-key value-range indexes
-- 
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/141812
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2013-01-03 09:04:01 +0000
+++ ChangeLog	2013-01-03 20:26:24 +0000
@@ -36,6 +36,7 @@
   * Fixed bug #1062093 (bug in var reference iterators with an associated
     position that is negative)
   * Fixed bug #1073978 (FOTS: option default ns not supported)
+  * Fixed bug in probing multi-key value-range indexes
   * Fixed bug #1061222 (bad message for errors in index key type declaration)
   * Fixed bug #1065175 (preceding::node()[1] returns wrong results)
   * Fixed bug #1065321 (following:text() doesn't return results in doc order)

=== modified file 'src/store/naive/simple_index_value.cpp'
--- src/store/naive/simple_index_value.cpp	2012-09-19 21:16:15 +0000
+++ src/store/naive/simple_index_value.cpp	2013-01-03 20:26:24 +0000
@@ -792,10 +792,11 @@
 /******************************************************************************
 
 ********************************************************************************/
-void ProbeValueTreeIndexIterator::init(const store::IndexCondition_t& cond,
-                                       const xs_integer& aSkip)
+void ProbeValueTreeIndexIterator::init(
+    const store::IndexCondition_t& cond,
+    const xs_integer& skip)
 {
-  theSkip = aSkip;
+  theSkip = skip;
 
   if (cond->getKind() != store::IndexCondition::BOX_VALUE &&
       cond->getKind() != store::IndexCondition::POINT_VALUE)
@@ -907,13 +908,23 @@
     if (haveLowerBound)
     {
       if (!flags[i].theHaveLowerBound)
-        lowerBounds[i] = IndexConditionImpl::theNegInf;
+      {
+        if (lowIncl)
+          lowerBounds[i] = IndexConditionImpl::theNegInf;
+        else
+          lowerBounds[i] = IndexConditionImpl::thePosInf;
+      }
     }
 
     if (haveUpperBound)
     {
       if (!flags[i].theHaveUpperBound)
-        upperBounds[i] = IndexConditionImpl::thePosInf;
+      {
+        if (highIncl)
+          upperBounds[i] = IndexConditionImpl::thePosInf;
+        else
+          upperBounds[i] = IndexConditionImpl::theNegInf;
+      }
     }
 
     if (flags[i].theHaveLowerBound && flags[i].theHaveUpperBound)
@@ -984,22 +995,35 @@
 ********************************************************************************/
 void ProbeValueTreeIndexIterator::reset()
 {
+  theResultSet = NULL;
+
   if (theMapBegin != theIndex->theMap.end())
   {
     theMapIte = theMapBegin;
 
-    theResultSet = theMapIte->second;
-    theIte = theResultSet->begin();
-    theEnd = theResultSet->end();
-
-    // primitive skip
-    store::Item_t lDummy;
-    for (long l = 0; l < to_xs_long(theSkip); ++l)
-    {
-      if(!next(lDummy))
+    while (theMapIte != theMapEnd)
+    {
+      if (!theDoExtraFiltering || theBoxCond->test(*(theMapIte->first)))
+        break;
+
+      ++theMapIte;
+    }
+
+    if (theMapIte != theMapEnd)
+    {
+      theResultSet = theMapIte->second;
+      theIte = theResultSet->begin();
+      theEnd = theResultSet->end();
+
+      // primitive skip
+      store::Item_t lDummy;
+      for (long l = 0; l < to_xs_long(theSkip); ++l)
       {
-        // no more values
-        break;
+        if(!next(lDummy))
+        {
+          // no more values
+          break;
+        }
       }
     }
   }
@@ -1032,7 +1056,7 @@
     }
 
     theResultSet = NULL;
-    theMapIte++;
+    ++theMapIte;
 
     while (theMapIte != theMapEnd)
     {
@@ -1044,7 +1068,7 @@
         break;
       }
 
-      theMapIte++;
+      ++theMapIte;
     }
   }
 
@@ -1053,9 +1077,9 @@
 
 
 /******************************************************************************
- The implementation here doesn't really give anything in terms of
- performance but other implementations might be able to provide more
- efficient ones.
+  The implementation here doesn't really give anything in terms of
+  performance but other implementations might be able to provide more
+  efficient ones.
 ********************************************************************************/
 void ProbeValueTreeIndexIterator::count(store::Item_t& result)
 {

=== added file 'test/rbkt/ExpQueryResults/zorba/index/multi_key_01.xml.res'
--- test/rbkt/ExpQueryResults/zorba/index/multi_key_01.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/index/multi_key_01.xml.res	2013-01-03 20:26:24 +0000
@@ -0,0 +1,2 @@
+<doc key1="foo2" key2="boo1"/><doc key1="foo2" key2="boo2"/>
+<doc key1="foo1" key2="boo1"/><doc key1="foo1" key2="boo2"/>

=== added file 'test/rbkt/ExpQueryResults/zorba/index/multi_key_02.xml.res'
--- test/rbkt/ExpQueryResults/zorba/index/multi_key_02.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/index/multi_key_02.xml.res	2013-01-03 20:26:24 +0000
@@ -0,0 +1,1 @@
+<doc key1="20" key2="5" key3="30"/>

=== modified file 'test/rbkt/Queries/zorba/index/keys_mod.xqlib'
--- test/rbkt/Queries/zorba/index/keys_mod.xqlib	2012-07-13 21:13:30 +0000
+++ test/rbkt/Queries/zorba/index/keys_mod.xqlib	2013-01-03 20:26:24 +0000
@@ -16,7 +16,8 @@
 
 declare %ann:automatic %ann:value-range index keys-lib:FooIdx3
   on nodes dml:collection(xs:QName("keys-lib:foo"))
-  by xs:string(./@id) as xs:string, (if (./@name) then xs:string(./@name) else ()) as xs:string?;
+  by xs:string(./@id) as xs:string,
+     (if (./@name) then xs:string(./@name) else ()) as xs:string?;
 
 declare %ann:automatic %ann:general-equality index keys-lib:FooIdx-general
   on nodes dml:collection(xs:QName("keys-lib:foo"))

=== added file 'test/rbkt/Queries/zorba/index/multi_key_01.xq'
--- test/rbkt/Queries/zorba/index/multi_key_01.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/index/multi_key_01.xq	2013-01-03 20:26:24 +0000
@@ -0,0 +1,51 @@
+import module namespace d = "www.data.com" at "multi_key_01.xqlib";
+
+import module namespace ddl = 
+"http://www.zorba-xquery.com/modules/store/static/collections/ddl";;
+
+import module namespace dml = 
+"http://www.zorba-xquery.com/modules/store/static/collections/dml";;
+
+import module namespace iddl = 
+"http://www.zorba-xquery.com/modules/store/static/indexes/ddl";;
+
+import module namespace idml = 
+"http://www.zorba-xquery.com/modules/store/static/indexes/dml";;
+
+declare namespace an = "http://www.zorba-xquery.com/annotations";;
+
+
+declare variable $doc11 := 
+<doc key1="foo1" key2="boo1"/>;
+
+declare variable $doc21 := 
+<doc key1="foo2" key2="boo1"/>;
+
+declare variable $doc12 := 
+<doc key1="foo1" key2="boo2"/>;
+
+declare variable $doc22 := 
+<doc key1="foo2" key2="boo2"/>;
+
+
+ddl:create($d:documents);
+
+dml:insert($d:documents, ($doc11, $doc21, $doc12, $doc22));
+
+iddl:create($d:idx);
+
+idml:probe-index-range-value(
+    $d:idx,
+    "foo1", (), true(),  false(), false(), false(),
+    (),     (), false(), false(), false(), false())
+,
+"
+"
+,
+idml:probe-index-range-value(
+     $d:idx,
+     (), "foo2", false(), true(),  false(), false(),
+     (), (),     false(), false(), false(), false())
+,
+"
+"

=== added file 'test/rbkt/Queries/zorba/index/multi_key_01.xqlib'
--- test/rbkt/Queries/zorba/index/multi_key_01.xqlib	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/index/multi_key_01.xqlib	2013-01-03 20:26:24 +0000
@@ -0,0 +1,30 @@
+module namespace data = "www.data.com";
+
+import module namespace ddl = 
+"http://www.zorba-xquery.com/modules/store/static/collections/ddl";;
+
+import module namespace dml = 
+"http://www.zorba-xquery.com/modules/store/static/collections/dml";;
+
+import module namespace iddl = 
+"http://www.zorba-xquery.com/modules/store/static/indexes/ddl";;
+
+import module namespace idml = 
+"http://www.zorba-xquery.com/modules/store/static/indexes/dml";;
+
+declare namespace an = "http://www.zorba-xquery.com/annotations";;
+
+declare construction strip;
+
+
+declare collection data:documents as node()*;
+
+declare variable $data:documents as xs:QName := xs:QName('data:documents');
+
+
+declare %private %an:automatic %an:unique %an:value-range index data:idx
+on nodes dml:collection(xs:QName('data:documents'))
+by string(./@key1) as xs:string,
+   string(./@key2) as xs:string;
+
+declare variable $data:idx as xs:QName := xs:QName('data:idx');

=== added file 'test/rbkt/Queries/zorba/index/multi_key_02.xq'
--- test/rbkt/Queries/zorba/index/multi_key_02.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/index/multi_key_02.xq	2013-01-03 20:26:24 +0000
@@ -0,0 +1,45 @@
+import module namespace d = "www.data.com" at "multi_key_02.xqlib";
+
+import module namespace ddl = 
+"http://www.zorba-xquery.com/modules/store/static/collections/ddl";;
+
+import module namespace dml = 
+"http://www.zorba-xquery.com/modules/store/static/collections/dml";;
+
+import module namespace iddl = 
+"http://www.zorba-xquery.com/modules/store/static/indexes/ddl";;
+
+import module namespace idml = 
+"http://www.zorba-xquery.com/modules/store/static/indexes/dml";;
+
+declare namespace an = "http://www.zorba-xquery.com/annotations";;
+
+
+declare variable $doc11 := 
+<doc key1="10" key2="5" key3="3"/>;
+
+declare variable $doc12 := 
+<doc key1="10" key2="6" key3="5"/>;
+
+declare variable $doc21 := 
+<doc key1="20" key2="5" key3="4"/>;
+
+declare variable $doc22 := 
+<doc key1="20" key2="5" key3="30"/>;
+
+
+ddl:create($d:documents);
+
+dml:insert($d:documents, ($doc11, $doc21, $doc12, $doc22));
+
+iddl:create($d:idx);
+
+idml:probe-index-range-value(
+     $d:idx,
+     10, (), true(),  false(), false(), false(),
+     (), (), false(), false(), false(), false(),
+     20, (), true(), false(), false(), false())
+,
+"
+"
+

=== added file 'test/rbkt/Queries/zorba/index/multi_key_02.xqlib'
--- test/rbkt/Queries/zorba/index/multi_key_02.xqlib	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/index/multi_key_02.xqlib	2013-01-03 20:26:24 +0000
@@ -0,0 +1,31 @@
+module namespace data = "www.data.com";
+
+import module namespace ddl = 
+"http://www.zorba-xquery.com/modules/store/static/collections/ddl";;
+
+import module namespace dml = 
+"http://www.zorba-xquery.com/modules/store/static/collections/dml";;
+
+import module namespace iddl = 
+"http://www.zorba-xquery.com/modules/store/static/indexes/ddl";;
+
+import module namespace idml = 
+"http://www.zorba-xquery.com/modules/store/static/indexes/dml";;
+
+declare namespace an = "http://www.zorba-xquery.com/annotations";;
+
+declare construction strip;
+
+
+declare collection data:documents as node()*;
+
+declare variable $data:documents as xs:QName := xs:QName('data:documents');
+
+
+declare %private %an:automatic %an:unique %an:value-range index data:idx
+on nodes dml:collection(xs:QName('data:documents'))
+by xs:integer(./@key1) as xs:integer,
+   xs:integer(./@key2) as xs:integer,
+   xs:integer(./@key3) as xs:integer;
+
+declare variable $data:idx as xs:QName := xs:QName('data:idx');

=== modified file 'test/rbkt/Queries/zorba/index/paging.xqlib'
--- test/rbkt/Queries/zorba/index/paging.xqlib	2012-09-05 12:08:14 +0000
+++ test/rbkt/Queries/zorba/index/paging.xqlib	2013-01-03 20:26:24 +0000
@@ -18,6 +18,7 @@
 declare %an:nonunique %an:value-range %an:automatic index data:idx-age-range-val
 on nodes dml:collection(xs:QName("data:people"))
 by xs:integer(./age/text()) as xs:integer;
+
 declare variable $data:idx-age-range-val := xs:QName("data:idx-age-range-val");
 
 declare %an:sequential function data:init()

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to