|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
XQuery variable declaration (again :-)
by Marko Bozikovic-2
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message Hi all,
I haven't received any answers to my previous mail, and reading it I realized the question might not have been completely clear. I will try again :-) This is a test query that I have: declare function local:foo($year as xs:string) as xs:string { (: do something :) }; declare variable $year := '2005'; <foo> { let $u := local:foo($year) return $u } </foo> This query executes in about half a second (function foo performs a query from a database) However, I need a 'global' variable, so I changed the query to: declare function local:foo($year as xs:string) as xs:string { (: do something :) }; declare variable $year := '2005'; declare variable $u := local:foo($year); <foo> {$u} </foo> This query takes 7-8 seconds to execute. Any ideas why? Current query use our project database, but maybe I can create a minimal example that reproduces the problem is needed. TIA, -- Marko Božiković Tellus d.o.o. Tel. +385 1 3691 975 Fax +385 1 3691 976 E-Mail: marko.bozikovic@... Ogrizovićeva 40a 10000 Zagreb Hrvatska ------------------------------------------ To remove yourself from this list, send an email to xml-unsubscribe@... |
|
|
Re: XQuery variable declaration (again :-)
by John Snelson-4
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message Hi Marko,
The statistics you quote are very strange, and I will certainly be looking into why that might be the case. In the mean time, maybe you could try a query like this, and let me know how it performs: declare function local:foo($year as xs:string) as xs:string { (: do something :) }; declare variable $year := '2005'; let $u := local:foo($year) return <foo> {$u} </foo> John Marko Bozikovic wrote: > Hi all, > > I haven't received any answers to my previous mail, and reading it I realized > the question might not have been completely clear. I will try again :-) > > This is a test query that I have: > > declare function local:foo($year as xs:string) as xs:string > { > (: do something :) > }; > > declare variable $year := '2005'; > > <foo> > { > let $u := local:foo($year) > return $u > } > </foo> > > This query executes in about half a second (function foo performs a query from > a database) > > > However, I need a 'global' variable, so I changed the query to: > > declare function local:foo($year as xs:string) as xs:string > { > (: do something :) > }; > > declare variable $year := '2005'; > declare variable $u := local:foo($year); > > <foo> > {$u} > </foo> > > This query takes 7-8 seconds to execute. > > Any ideas why? Current query use our project database, but maybe I can create > a minimal example that reproduces the problem is needed. > > TIA, ------------------------------------------ To remove yourself from this list, send an email to xml-unsubscribe@... |
|
|
Re: XQuery variable declaration (again :-)
by Marko Bozikovic-2
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message John Snelson wrote:
> Hi Marko, > > The statistics you quote are very strange, and I will certainly be > looking into why that might be the case. In the mean time, maybe you > could try a query like this, and let me know how it performs: > > declare function local:foo($year as xs:string) as xs:string > { > (: do something :) > }; > > declare variable $year := '2005'; > > let $u := local:foo($year) > return > > <foo> > {$u} > </foo> Thanks, this works faster :) Here's a test setup that reproduces the problem: Create XML files: <foo id="U-XXX-YY-ZZ" year="20YY"> <data>foo</data> </foo> Filename format is U-XXX-YY-ZZ.xml. XXX is 0-499, YY is 04-06 and YY is 01-03 (this gives 4500 files). Create a test container (default: indexed nodes). Create indexes for id and year attributes, both node-attribute-equality-string. Import XML files. This is the query: declare function local:foo($year as xs:string) as xs:string* { for $i in distinct-values( collection('test.dbxml') /*[starts-with(@id, 'U-') and (@year = $year)] /substring(string(@id), 3, 3) ) return collection('test.dbxml') /*[@id = string( max( collection('test.dbxml') /*[starts-with(@id, concat('U-', $i, '-', substring($year, 3, 2)))] /string(@id) ) ) ] /string(@id) }; declare variable $a := local:foo($year); <doc name='Foo' year='{substring($year, 3, 2)}'> { $a } </doc> This query takes approx. 17 seconds (and yes, I struggle a bit with XQuery formatting :-) Changing the last part to: <doc name='Foo' year='{substring($year, 3, 2)}'> { let $a := local:foo($year) return $a } </doc> This query takes approx. 2 seconds to complete. Another interesting thing is that using computed contructor text in the first example improves speed: declare variable $a := text{local:foo($year)}; <doc name='Foo' year='{substring($year, 3, 2)}'> { $a } </doc> This query also takes approx. 2 seconds to complete. Thank you, -- Marko Božiković Tellus d.o.o. Tel. +385 1 3691 975 Fax +385 1 3691 976 E-Mail: marko.bozikovic@... Ogrizovićeva 40a 10000 Zagreb Hrvatska ------------------------------------------ To remove yourself from this list, send an email to xml-unsubscribe@... |
| Free embeddable forum powered by Nabble | Forum Help |