bug in XPath evaluation

Sunday, 20 August 2017 · 4 messages · last reply 22 Aug 2017
ND
nikos dimitrakas20 Aug 2017 15:29 #
Hi! I discovered a strange behavior i BaseX (8.6.5): I evaluate //S/@k/parent::* or //S/@k/.. and it works I evaluate //S[.//@m="V"] and it works But when I evaluate //S/@k/parent::*[.//@m="V"] or //S/@k/..[.//@m="V"] it does not work. There is no error, just no result. At first I thought that there was an error with going to a parent of an attribute node, but that works. Then I thought the problem was with ".//@" in the predicate, but that also works. It appears that it is the combination that confuses the engine. Here is an xml to test the above expressions:
<Root>
   <B>
     <S k="AAA">
       <P m="V" a="1000"/>
       <P m="V" a="800"/>
       <P m="G" a="1000"/>
       <P m="E" a="900"/>
     </S>
     <S k="AA">
       <P m="V" a="2000"/>
       <P m="G" a="2500"/>
       <P m="E" a="2900"/>
     </S>
     <S k="D">
       <P m="V" a="4000"/>
     </S>
     <S k="C">
       <P m="V" a="4000"/>
       <P m="G" a="4000"/>
     </S>
   </B>
   <B>
     <S k="AAA">
       <P m="V" a="1200"/>
       <P m="V" a="800"/>
       <P m="G" a="1200"/>
     </S>
     <S k="AA">
       <P m="V" a="2900"/>
     </S>
     <S k="C">
       <P m="G" a="5400"/>
     </S>
   </B>
   <B>
     <S k="AAA">
       <P m="V" a="1100"/>
       <P m="E" a="900"/>
     </S>
     <S k="AA">
       <P m="V" a="2700"/>
       <P m="G" a="2500"/>
     </S>
   </B>
</Root>
I hope you can find the problem and fix it in a new version soon. Regards /nikos
MH
Martin Honnen20 Aug 2017 17:08 #
Quoted text · nikos dimitrakas · 7 lines
On 20.08.2017 15:29, nikos dimitrakas wrote: > I discovered a strange behavior i BaseX (8.6.5): > But when I evaluate > //S/@k/parent::*[.//@m="V"] > or > //S/@k/..[.//@m="V"] > it does not work. There is no error, just no result.
When I run your path expression directly against your posted sample with
<Root>
   <B>
     <S k="AAA">
       <P m="V" a="1000"/>
       <P m="V" a="800"/>
       <P m="G" a="1000"/>
       <P m="E" a="900"/>
     </S>
     <S k="AA">
       <P m="V" a="2000"/>
       <P m="G" a="2500"/>
       <P m="E" a="2900"/>
     </S>
     <S k="D">
       <P m="V" a="4000"/>
     </S>
     <S k="C">
       <P m="V" a="4000"/>
       <P m="G" a="4000"/>
     </S>
   </B>
   <B>
     <S k="AAA">
       <P m="V" a="1200"/>
       <P m="V" a="800"/>
       <P m="G" a="1200"/>
     </S>
     <S k="AA">
       <P m="V" a="2900"/>
     </S>
     <S k="C">
       <P m="G" a="5400"/>
     </S>
   </B>
   <B>
     <S k="AAA">
       <P m="V" a="1100"/>
       <P m="E" a="900"/>
     </S>
     <S k="AA">
       <P m="V" a="2700"/>
       <P m="G" a="2500"/>
     </S>
   </B>
</Root>//S/@k/..[.//@m="V"]
in the BaseX GUI I get the following result
<S k="AAA">
   <P m="V" a="1000"/>
   <P m="V" a="800"/>
   <P m="G" a="1000"/>
   <P m="E" a="900"/>
</S>
<S k="AA">
   <P m="V" a="2000"/>
   <P m="G" a="2500"/>
   <P m="E" a="2900"/>
</S>
<S k="D">
   <P m="V" a="4000"/>
</S>
<S k="C">
   <P m="V" a="4000"/>
   <P m="G" a="4000"/>
</S>
<S k="AAA">
   <P m="V" a="1200"/>
   <P m="V" a="800"/>
   <P m="G" a="1200"/>
</S>
<S k="AA">
   <P m="V" a="2900"/>
</S>
<S k="AAA">
   <P m="V" a="1100"/>
   <P m="E" a="900"/>
</S>
<S k="AA">
   <P m="V" a="2700"/>
   <P m="G" a="2500"/>
</S>
So how do you run your query when you say you get an empty result?
CG
Christian Grünin reply to nikos dimitrakas, 20 Aug 2017, 15:2920 Aug 2017 17:17 #
Hi Nikos, I had a look at the optimized query plans. Apparently, one of the index rewriting rules composes the inversed path in a wrong way:
  db:open('bug')//@a/..[@* = "x"]
…is rewritten to…
  db:attribute("bug", "x")/..[a/..]
…while it should be…
  db:attribute("bug", "x")/..[@a/..]
…or (further optimized)…
  db:attribute("bug", "x")/..[@a]
I have created a new issue [1], maybe I can fix it tomorrow. Thanks, Christian [1] https://github.com/BaseXdb/basex/issues/1490
Quoted text · nikos dimitrakas · 72 lines
On Sun, Aug 20, 2017 at 3:29 PM, nikos dimitrakas <nikos at dsv.su.se> wrote: > Hi! > I discovered a strange behavior i BaseX (8.6.5): > I evaluate > //S/@k/parent::* > or > //S/@k/.. > and it works > I evaluate > //S[.//@m="V"] > and it works > But when I evaluate > //S/@k/parent::*[.//@m="V"] > or > //S/@k/..[.//@m="V"] > it does not work. There is no error, just no result. > At first I thought that there was an error with going to a parent of an > attribute node, but that works. Then I thought the problem was with ".//@" > in the predicate, but that also works. It appears that it is the combination > that confuses the engine. > > Here is an xml to test the above expressions: > <Root> > <B> > <S k="AAA"> > <P m="V" a="1000"/> > <P m="V" a="800"/> > <P m="G" a="1000"/> > <P m="E" a="900"/> > </S> > <S k="AA"> > <P m="V" a="2000"/> > <P m="G" a="2500"/> > <P m="E" a="2900"/> > </S> > <S k="D"> > <P m="V" a="4000"/> > </S> > <S k="C"> > <P m="V" a="4000"/> > <P m="G" a="4000"/> > </S> > </B> > <B> > <S k="AAA"> > <P m="V" a="1200"/> > <P m="V" a="800"/> > <P m="G" a="1200"/> > </S> > <S k="AA"> > <P m="V" a="2900"/> > </S> > <S k="C"> > <P m="G" a="5400"/> > </S> > </B> > <B> > <S k="AAA"> > <P m="V" a="1100"/> > <P m="E" a="900"/> > </S> > <S k="AA"> > <P m="V" a="2700"/> > <P m="G" a="2500"/> > </S> > </B> > </Root> > > I hope you can find the problem and fix it in a new version soon. > > Regards > /nikos
CG
Christian Grün22 Aug 2017 14:37 #
The erroneous index rewriting has been resolved (it only occurred if downward and upward attribute axes were mixed) [1]. A new snapshot is available [2]. Cheers, Christian [1] https://github.com/BaseXdb/basex/issues/1490 [2] http://files.basex.org/releases/latest/
Quoted text · Christian Grün · 102 lines
On Sun, Aug 20, 2017 at 5:17 PM, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Nikos, > > I had a look at the optimized query plans. Apparently, one of the > index rewriting rules composes the inversed path in a wrong way: > > db:open('bug')//@a/..[@* = "x"] > > …is rewritten to… > > db:attribute("bug", "x")/..[a/..] > > …while it should be… > > db:attribute("bug", "x")/..[@a/..] > > …or (further optimized)… > > db:attribute("bug", "x")/..[@a] > > I have created a new issue [1], maybe I can fix it tomorrow. > > Thanks, > Christian > > [1] https://github.com/BaseXdb/basex/issues/1490 > > > > On Sun, Aug 20, 2017 at 3:29 PM, nikos dimitrakas <nikos at dsv.su.se> wrote: >> Hi! >> I discovered a strange behavior i BaseX (8.6.5): >> I evaluate >> //S/@k/parent::* >> or >> //S/@k/.. >> and it works >> I evaluate >> //S[.//@m="V"] >> and it works >> But when I evaluate >> //S/@k/parent::*[.//@m="V"] >> or >> //S/@k/..[.//@m="V"] >> it does not work. There is no error, just no result. >> At first I thought that there was an error with going to a parent of an >> attribute node, but that works. Then I thought the problem was with ".//@" >> in the predicate, but that also works. It appears that it is the combination >> that confuses the engine. >> >> Here is an xml to test the above expressions: >> <Root> >> <B> >> <S k="AAA"> >> <P m="V" a="1000"/> >> <P m="V" a="800"/> >> <P m="G" a="1000"/> >> <P m="E" a="900"/> >> </S> >> <S k="AA"> >> <P m="V" a="2000"/> >> <P m="G" a="2500"/> >> <P m="E" a="2900"/> >> </S> >> <S k="D"> >> <P m="V" a="4000"/> >> </S> >> <S k="C"> >> <P m="V" a="4000"/> >> <P m="G" a="4000"/> >> </S> >> </B> >> <B> >> <S k="AAA"> >> <P m="V" a="1200"/> >> <P m="V" a="800"/> >> <P m="G" a="1200"/> >> </S> >> <S k="AA"> >> <P m="V" a="2900"/> >> </S> >> <S k="C"> >> <P m="G" a="5400"/> >> </S> >> </B> >> <B> >> <S k="AAA"> >> <P m="V" a="1100"/> >> <P m="E" a="900"/> >> </S> >> <S k="AA"> >> <P m="V" a="2700"/> >> <P m="G" a="2500"/> >> </S> >> </B> >> </Root> >> >> I hope you can find the problem and fix it in a new version soon. >> >> Regards >> /nikos

⚡Generated with XQuery