[xquery-talk] FLWOR Question
Christian Grün
christian.gruen at gmail.com
Sat Jan 11 10:27:04 PST 2014
Hi Chris,
> Can the below code be improved to retrieve the current effective price
> (4000) given the following:
each query processor may benefit from different optimizations, but
this is what I noticed:
> xs:date($price/@effective/string())
Your input (01/01/2014) doesn’t seem to be valid (2014-01-01); did you
already have some thoughts on this? If you work with a valid date
format, you could as well get rid of the date conversion, as all
values can also be sorted as strings, which is usually faster.
Next, it seems that you are requesting the effective price twice. It
could be faster to bind it to a variable instead. Your resulting query
could then look as follows:
let $current := string(current-date())
for $iap in //iap
let $effective-price := (
for $price in $iap/price
let $effective := $price/@effective/string()
where $current >= $effective
order by $effective descending
return $price
)[1]
return element { $iap/@name/string() } { $effective-price }
You may have noted that I have flattened the FLWOR expressions to a
single one. This is sth. that’s already done automatically by some
processors.
Hope this helps,
Christian
More information about the talk
mailing list