[xquery-talk] FLWOR Question

Misztur, Chris CMisztur at macleanfogg.com
Sat Jan 11 13:24:40 PST 2014


The date format was my mistake.

Thank you for the explanation.  That clears up the FLWOR acronym.

________________________________________
From: Christian Grün [christian.gruen at gmail.com]
Sent: Saturday, January 11, 2014 12:27 PM
To: Misztur, Chris
Cc: talk at x-query.com
Subject: Re: [xquery-talk] FLWOR Question

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

________________________________

The contents of this message may be privileged and confidential. Therefore, if this message has been received in error, please delete it without reading it. Your receipt of this message is not intended to waive any applicable privilege. Please do not disseminate this message without the permission of the author.

Please consider the environment before printing this e-mail




More information about the talk mailing list