W3C home > Mailing lists > Public > www-ql@w3.org > April to June 2004

RE: Question about Let clause

From: Michael Rys <mrys@microsoft.com>
Date: Sat, 26 Jun 2004 23:50:42 -0700
Message-ID: <EB0A327048144442AFB15FCE18DC96C70343383F@RED-MSG-31.redmond.corp.microsoft.com>
To: "Michael Kay" <mhk@mhk.me.uk>, "Houman Khorasani" <khorasani@web.de>, <www-ql@w3.org>

Actually, a let should only be evaluated once if it contains a node
construction. Otherwise it depends on the query processor/optimizer.

Best regards
Michael

> -----Original Message-----
> From: www-ql-request@w3.org [mailto:www-ql-request@w3.org] On Behalf
Of
> Michael Kay
> Sent: Saturday, June 26, 2004 9:43 AM
> To: 'Houman Khorasani'; www-ql@w3.org
> Subject: RE: Question about Let clause
> 
> 
> >
> > 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 Sunday, 27 June 2004 02:50:45 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 22 July 2006 00:10:19 GMT