Project

Profile

Help

Bug #2013

closed

saxon:stream() in XQuery not streaming when it should

Added by Michael Kay over 10 years ago. Updated over 10 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Streaming
Sprint/Milestone:
-
Start date:
2014-02-25
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

Gunther Rademacher reports on saxon-help:

However I found that the extra FLWOR does make a difference. These queries are streaming:

for $x in saxon:stream(doc('uri')/*/*) return string($x)
 
for $x in saxon:stream(doc('uri')/*/*) return $x
 
for $x in saxon:stream(doc('uri')/*/*) return $x/*

but these are not:

saxon:stream(doc('uri')/*/*)/string()
 
saxon:stream(doc('uri')/*/*)
 
saxon:stream(doc('uri')/*/*)/*

To which I responded:

You might find it helpful to do this kind of investigation by running from the command line, for example:

java net.sf.saxon.Query -qs:"saxon:stream(doc('temp/test.xml')//)/string()" -explain -qversion:3.0

The -explain output in this case tells you:

OPT ======================================

OPT : Cannot use streaming copy: expression is not provably in document order

OPT ======================================

though it's a little bit confusing because some of the expressions that can be streamed give you the same message, followed by

OPT ======================================

OPT : Using streaming copy

OPT ======================================

because the optimizer succeeds on its second attempt. But it's a lot better than trying to work out what's streaming and what isn't by measuring the time and memory usage.

On 24 Feb 2014, at 10:56, Rademacher, Gunther wrote:

Thanks for the advice. I now have streaming queries working as I want them.

However I found that the extra FLWOR does make a difference. These queries are streaming:

for $x in saxon:stream(doc('uri')/*/*) return string($x)
 
for $x in saxon:stream(doc('uri')/*/*) return $x
 
for $x in saxon:stream(doc('uri')/*/*) return $x/*

but these are not:

saxon:stream(doc('uri')/*/*)/string()
 
saxon:stream(doc('uri')/*/*)
 
saxon:stream(doc('uri')/*/*)/*

What's happening here is that in all 6 cases, the first attempt to convert to a streaming expression happens before the analysis that the expression doesn't need sorting, and therefore fails. In the first three cases there is a second attempt (because it tries again after inlining the variable), and the second attempt succeeds. But in the last three cases there is no second attempt. I will fix this.

Please register to edit this issue

Also available in: Atom PDF