The following query should give a result, but it doesn't:
let $id as xs:string := 'bwbr0002221/2002-01-01/0/wet'
let $d-roots as element()* := collection('cwb')/work
let $d := $d-roots//*[@id = $id]/descendant-or-self::component
return $d
This is caused by the way BaseX optimizes this query to
The optimized version finds an id attribute node with the right value, then takes the parent, which is the element with the id attribute. The predicate between [] does not do much. The query then finds descendant::components, whereas the original query had descendant-or-self::component. This is important, because in this specific case the <component> contains the right id attribute.
When I change the query a little bit:
let $id as xs:string := 'bwbr0002221/2002-01-01/0/wet'
let $d-roots as element(work)* := collection('cwb')/*
let $d := $d-roots//*[@id = $id]/descendant-or-self::component
return $d
I do get the expected <component id="bwbr0002221/2002-01-01/0/wet"/>. Then the optimized query is:
((db:open-pre("cwb", 0), ...)/* treat as element(work)+)/descendant::*[(@id = "bwbr0002221/2002-01-01/0/wet")]/descendant-or-self::component
Expected Behavior
The first query
let $id as xs:string := 'bwbr0002221/2002-01-01/0/wet'
let $d-roots as element()* := collection('cwb')/work
let $d := $d-roots//*[@id = $id]/descendant-or-self::component
return $d
let $id as xs:string := 'bwbr0002221/2002-01-01/0/wet'
let $d-roots as element()* := collection('cwb')/work
let $d := $d-roots//*[@id = $id]/descendant-or-self::component
return $d
and
let $id as xs:string := 'bwbr0002221/2002-01-01/0/wet'
let $d-roots as element(work)* := collection('cwb')/*
let $d := $d-roots//*[@id = $id]/descendant-or-self::component
return $d
and observe the difference.
Do you have an idea how to solve the issue?
The optimizer generates a descendant::component, which should be descendant-or-self::component.
This happens when the query begins with db:attribute(). Note that db:attribute returns an attribute node, and maybe the query optimizer thinks it returns the element containing that attribute node?
Thanks for the concise bug report. New maven artifacts have been uploaded.
BaseX 10 will be released next week; BaseX 9.7.4 can be expected soon after.
Description of the Problem
The following query should give a result, but it doesn't:
This is caused by the way BaseX optimizes this query to
The optimized version finds an
id
attribute node with the right value, then takes the parent, which is the element with theid
attribute. The predicate between[]
does not do much. The query then findsdescendant::component
s, whereas the original query haddescendant-or-self::component
. This is important, because in this specific case the<component>
contains the rightid
attribute.When I change the query a little bit:
I do get the expected
<component id="bwbr0002221/2002-01-01/0/wet"/>
. Then the optimized query is:Expected Behavior
The first query
should be optimized to
which gives the correct result. (Instead of
descendant::component
, usedescendant-or-self::component
.)Steps to Reproduce the Behavior
cwb
database:and
and observe the difference.
Do you have an idea how to solve the issue?
The optimizer generates a
descendant::component
, which should bedescendant-or-self::component
. This happens when the query begins withdb:attribute()
. Note thatdb:attribute
returns an attribute node, and maybe the query optimizer thinks it returns the element containing that attribute node?What is your configuration?