Performance issue related with Casting.
Friday, 8 May 2015 · 2 messages
AK
ankit kumar8 May 2015 06:13 #
Hi,
I am invoking a java method inside My XQuery script, My java methods returns a string array which contains the Id of elements. Now I am taking that list in a xquery variable. It looks like this.
let $ids := javacontext:getIds(); // Java Method
return /sample_xml/category/product[@id = $ids]Now the problem is that, It is working fine with this, but when I declare variable $ids as xs:string* sequence. It performance is decreased by almost 100%. It looks like this.
let $ids as xs:string* := javacontext:getIds(); // Java Method
return /sample_xml/category/product[@id = $ids]But, for bigger no of products, and ids . when the variable $ids declared as xs:string*, it is working good, but when I removed xs:string*. it performance decreased drammatically.
I have no idea, why it is working in such a way. Any kind of help is appreciated.
Thanks,
Ankit
CG
Christian Grün8 May 2015 10:05 #
Hi Ankit,
Quoted text · ankit kumar · 2 lines
> Now the problem is that, It is working fine with this, but when I declare > variable $ids as xs:string* sequence.
The reason is the existence of the Java function: We cannot always determine statically what types the results will have. As a result, we cannot statically detect that $ids will always be a sequence of strings, and as a result, your path expression cannot be rewritten to an index request. Generally, it's always recommendable to explicitly specify type information in your query; it will improve performance in many cases.
A reminder: Check out the compilation steps in the info view, they will give you insights how your query will be compiled.
Christian
It performance is decreased by almost
Quoted text · ankit kumar · 22 lines
> 100%. It looks like this. > > let $ids as xs:string* := javacontext:getIds(); // Java Method > return /sample_xml/category/product[@id = $ids] > > > But, for bigger no of products, and ids . when the variable $ids declared as > xs:string*, it is working good, but when I removed xs:string*. it > performance decreased drammatically. > > > I have no idea, why it is working in such a way. Any kind of help is > appreciated. > > > Thanks, > Ankit > > > > >
Written for BaseX 8.1. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery