- From: Michael Kay <mhk@mhk.me.uk>
- Date: Sat, 26 Jun 2004 17:42:49 +0100
- To: "'Houman Khorasani'" <khorasani@web.de>, <www-ql@w3.org>
> > After the main return, the parser jumps back to beginning to > get into the > next for clauses and so on. But does it skip the very first > let clause or > does it re-calculate everytime the whole nested FLWOR > expression and store > it everytime in $temptltt? I'm a little confused by your question. Are you asking a question about the XQuery language, or about a specific implementation (such as Saxon)? And when you say "parser", do you really mean parser (the syntax analyzer) or are you asking about what the query processor does at run-time? The way in which FLWR expressions are executed will vary from one query processor to another. I would be a little surprised if any query processor evaluated the first "let" assignment more than once, but it could do so if it wanted to. You can get some indication of how Saxon evaluates this query by running it with the -e option on the command line. This outputs the expression tree after optimization rewrites. Saxon at the moment isn't especially advanced in its optimization of FLWR expressions, but it does do things like moving subexpressions (such as [$wbtt/dat = '200...'] in your example) out of loops to avoid repeated evaluation. I'm starting to observe a coding pattern where people who come to XQuery from SQL write everything as FLWR expressions, when a simple path expression would sometimes be much more concise. For example: let $totalDelay_distinctMin := for $i in ($temptltt) where ($i/min = $distinctMin) return $i/dlay is something I would naturally write as: let $totalDelay_distinctMin := $tempt1tt[min=$distinctMin]/dlay (They aren't strictly equivalent, because path expressions deliver results in document order with duplicates eliminated). Because of Saxon's history, it is currently better at optimizing path expressions than FLWR expressions. But other query processors may differ. Michael Kay > > I really need to know it for my paper, > > Best regards > Houman > > > > let $temptltt := for $wbtt in > doc("wisc_berkeley_tracetime.xml")//row > for $wb in doc("wisc_berkeley_3days.xml")//row > where ( ($wbtt/dat = '20000801000000') > and ($wb/dat > = '20000801000000') and ($wbtt/min = (round($wb/tick div 600000))) ) > return <g> { $wbtt/min } > { $wb/dlay } > { $wbtt/dat } > { $wbtt/rID } </g> > > for $distinctMin in distinct-values($temptltt//min) > > let $totalDelay_distinctMin := for $i in ($temptltt) > where ($i/min = $distinctMin) > return $i/dlay > > let $rID := for $i in $temptltt > where ($i/min = $distinctMin) > return $i/rID > > let $dat := for $i in $temptltt > where ($i/min = $distinctMin) > return $i/dat > > return > <ROW> > { $rID[1] } > <min>{ $distinctMin }</min> > { $dat[1] } > <avgDelay> { round-half-to-even( > (avg($totalDelay_distinctMin)),4 ) } </avgDelay> > </ROW> > > > > >
Received on Saturday, 26 June 2004 12:45:24 UTC