Streaming: effect of "/" versus "!"
Test case sx-intersect-313
This may be a problem in the spec rather than in the Saxon implementation.
(A intersect B) / (.+1) is streamable, while
(A intersect B) ! (.+1) is not. This seems unreasonable, since they are obviously equivalent.
Updated by Michael Kay 3 months ago
An observation: the spec says that given the expression (A § B) where § is
except, then if A and B are both striding, the result is crawling.
This is legitimate in the case of union, because for example
(A/B union */*/C) can contain two nodes where one is an ancestor of the other. But it is unnecessarily restrictive for
except, because with these operators, every node in the result is present in the value of the LH operand, and therefore if the LH operand is striding (contains no nested nodes) then the result is striding as well.
For union, we can make the result striding if the two operands have the same "constant depth" (the number of child selections). But the spec doesn't have the machinery to calculate the "constant depth" of an expression. In Saxon we possibly do, in the form of the path maps used for analysis of XQuery projection.
Updated by Michael Kay 25 days ago
As regards the original problem, there is in fact a reason for the distinction: "/" forces the results into document order, while "!" does not. This means that the expression with "/" is a "scanning expression" - it can be evaluated using a scan in document order, testing each node against the expression treated as a pattern.
I propose that we change the rules for
(A intersect B) (and likewise
(A except B) so that the result is striding if A is striding; and this is likely to make use of "!" acceptable in many cases.
Please register to edit this issue