Project

Profile

Help

Bug #2664

closed

XQuery optimize leads to stackoverflow

Added by Matthew Halverson over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
XQuery conformance
Sprint/Milestone:
-
Start date:
2016-03-06
Due date:
% Done:

100%

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

Description

In Saxon-HE 9.7.0.2J, the following xquery (ran with @java -cp saxon9he.jar net.sf.saxon.Query test.xqy@)

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "text";
declare context item := doc('test.xml'); (: error occurs with or without this line :)

for $x in distinct-values(doc('test.xml')/report//section//title)
where count(/report//section[title=string($x)]) > 1
return $x

causes a stackoverflow error when ran against the following xml

<report>
    <title>Main title</title>
    <section>
        <title>sec1</title>
    </section>

    <section>
        <title>sec1</title>
        <section>
            <title>sec21</title>
        </section>
    </section>      
</report>

The error does not occur in the following three variants:

loop uses default context

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "text";
declare context item := doc('test.xml');

for $x in distinct-values(/report//section//title)
where count(doc('test.xml')/report//section[title=string($x)]) > 1
return $x

loop and where uses explicit context

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "text";
declare context item := doc('test.xml');

for $x in distinct-values(doc('test.xml')/report//section//title)
where count(doc('test.xml')/report//section[title=string($x)]) > 1
return $x

both loop and where uses default context

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "text";
declare context item := doc('test.xml');

for $x in distinct-values(/report//section//title)
where count(/report//section[title=string($x)]) > 1
return $x

The original query and xml as well as the complete stack trace is attached.


Files

test.xqy (291 Bytes) test.xqy XQuery causing error Matthew Halverson, 2016-03-06 08:52
test.xml (251 Bytes) test.xml XML causing error Matthew Halverson, 2016-03-06 08:52
stacktrace.txt (69.4 KB) stacktrace.txt Complete stacktrace Matthew Halverson, 2016-03-06 08:54

Please register to edit this issue

Also available in: Atom PDF