Greetings everyone, I'm evaluating whether BaseX 9.4.3 might be suitable for my projects and I think I've run into an XQuery optimizer bug that's easily reproducible. I've got a test database "test-db" with two identical documents containing minimal xml: "<doc title='a-document'/>". The documents are stored in separate directories:
test-db
|- a/doc.xml
|- b/doc.xml
The XQuery I'm using I believe should retrieve only the document in path a, but I'm getting different results depending on whether I write the expression in a single let statement or two separate statements:
declare function local:show-paths($nodes as node()*) as node()* {
for $p in $nodes
return <path>{$p/base-uri()}</path>
};
let $docs_1 := collection('test-db/a')/doc[@title='a-document']
let $col := collection('test-db/a')
let $docs_2 := $col/doc[@title='a-document']
return
<result>
<single-expr expr_docs="{count($docs_1)}"/>
<single-expr-paths>{local:show-paths($docs_1)}</single-expr-paths>
<split-expr collection_docs="{count($col)}" expr_docs="{count($docs_2)}"/>
<split-expr-paths>{local:show-paths($docs_2)}</split-expr-paths>
</result>
This code produces this result:
<result>
<single-expr expr_docs="1"/>
<single-expr-paths>
<path>/test-db/a/doc.xml</path>
</single-expr-paths>
<split-expr collection_docs="1" expr_docs="2"/>
<split-expr-paths>
<path>/test-db/a/doc.xml</path>
<path>/test-db/b/doc.xml</path>
</split-expr-paths>
</result>
I'd expect the expr_docs values for both single-expr and split-expr to be the same.
I'm happy to file this in the GitHub issue tracker, but as a newcomer to BaseX I thought I should checkin with the list first.
What are you thoughts and wishes?
Thanks,
-- Paul