[xquery-talk] XQuery coding style: nested FLWOR expressions

Bas de Bakker bas at x-hive.com
Tue Apr 18 14:37:07 PDT 2006


As another possible cause, you should take a look at the XML Query Use 
Cases from the W3C XQuery working group, which many people use as 
examples to see how queries are written. Here's one of them:

<results>
   {
     for $t in doc("books.xml")//(chapter | section)/title
     where contains($t/text(), "XML")
     return $t
   }
</results>

which has many of the problems you've mentioned (redundant flwor 
expression, uses text() step). This is just an example, most of the use 
cases are written in the style you are questioning.

Regards,
Bas de Bakker
X-Hive Corporation


Michael Kay wrote:
> I've been looking again recently at some of the XMark benchmark queries.
> 
> I'm wondering what it is about the language that makes people write things
> like this (Q9):
> 
> for $p in /site/people/person
> let $a := for $t in /site/closed_auctions/closed_auction
>           let $n := for $t2 in /site/regions/europe/item
>                        where  $t/itemref/@item = $t2/@id
>                        return $t2
>              where $p/@id = $t/buyer/@person
>              return <item> {$n/name} </item>
> return <person name="{$p/name}">{ $a }</person>
> 
> when they could have written
> 
> for $p in /site/people/person
> return <person name="{$p/name}"> { 
>   for $t in /site/closed_auctions/closed_auction[buyer/@person = $p/@id]
>   return <item> {/site/regions/europe/item[@id = $t/itemref/@item]/name}
> </item> 
> } </person>
> 
> Is it just a torture test for optimizers? Did the author think this was the
> best/easiest way to write the query? Does anyone else think it is? Is it the
> way SQL users' brains are wired?
> 
> Michael Kay
> http://www.saxonica.com/ 
> 
> 
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
> 
> 


More information about the talk mailing list