New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Boolean operations on nodes #1106
Comments
Very strange.
Commenting out the $y assignment (or swapping the two assignments) evaluates as one item, false(), but as it is this query returns no items, which is wrong, for a boolean evaluation should always result in one item. If we return
everything is fine, no matter what intervenes between $x and its evaluation, but this actually does not help explain what is going on (see below). However, if we return
we see the difference:
of course also comes out as expected, since the empty sequence and the value false here have the same effect. |
Useful insights, Jens! Particularly relating to the arbitrariness of values assigned to |
The bug is not connected to the evaluation of booleans, but more generally to query execution when a variable is bound to an empty sequence. Try
The problem is that $x is discarded. |
Wow, that's crazy! Thanks for your investigations and insights, Jens! |
Wait, shouldn't an empty member of a sequence be discarded? |
i.e., |
Yes, |
My example with |
Agreed, this is really weird. I wasn't able to see this phenomenon outside the context of boolean expressions, but who knows the extent of this issue? |
Well, returning booleans is not that common; I think we can be pretty sure that booleans behave properly in conditionals. |
@jensopetersen I'm afraid, not. That's what brought me to my original question on SO and then to open the bug report. Cf. this example:
with /db/test/test.xml as follows:
returns
|
Well, I guess I was trying to comfort myself, but it still has nothing to do with booleans, for with
you get the expected outcome. Booleans are a way to check what is going wrong, but the problem lies in how variables are handled in the flow of a query. I now see Joe's point about the potential extent of this issue. We have to see how else we can test this problem. |
Let me know if there's anything I can do to help. |
It is curious how little it takes to "wake up" the variable evaluated. You used count(), but it also works with
|
There are few bugs at BTW, is it possible to write tests for |
@shabanovd That's great news! Thank you for looking into this. I was able to find a bug with xquery version "3.1";
let $node :=
<root>
<foo/>
<bar/>
</root>
let $create-collection := xmldb:create-collection('/db', 'test')
let $store := xmldb:store('/db/test', 'test.xml', $node)
let $x := doc('/db/test/test.xml')/root
let $y := doc('/db/test/test.xml')/root
return
<test>
<result>{$x/foo or $x/bar}</result>
<result>{$y/foo or $y/bar}</result>
</test> Expected: <test>
<result>true</result>
<result>true</result>
</test> Actual: <test>
<result>false</result>
<result>true</result>
</test> I haven't been able to get the same effect with in-memory tests despite several variations of the original (e.g., binding |
…necessary optimizations. Performance tests did not show any regression. Added tests for boolean operators. Fixes issue eXist-db#1106.
I can confirm that since @wolfgangmm's PR has been merged, the test cases I provided in this issue are all returning expected results. It looks like the PR contained a thorough set of tests to prevent future regressions. Many thanks, Wolfgang! |
As reported by @dariok in #1097 and confirmed by both @dariok and me using builds of the develop branch as current as 12f422d, boolean operations on a node produce different results based on the order that the node is selected.
We have two reproducible tests, which we tested with eXide (2.2.0):
Test 1: In-memory node
Expected result:
Actual result:
Test 2: On-database node
Expected result:
Actual result:
The text was updated successfully, but these errors were encountered: