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

Michael Kay mhk at mhk.me.uk
Wed Apr 12 10:16:21 PDT 2006

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}
} </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

More information about the talk mailing list