[xquery-talk] where clause

Liam R E Quin liam at w3.org
Thu Mar 28 23:35:38 PST 2013


On Wed, 2013-03-27 at 13:26 +0000, deBakker, Bas wrote:
> Wouldn't that be equivalent to
> 
>     for $a in expr1, $b in expr2, $c in expr3[$a = $b + .]
>     return $a

I notice that BaseX does exactly that rewrite.

In SQL with a WHERE clause some of the values may be NULL, but that
can't occur in XQuery today; if it could, there might be tuples without
a value for $c, in which case the rewrite wouldn't work.

A smart optimizer with knowledge of the input could rewrite at runtime
to put the [predicate] on the expression likely to have the fewest
nodes, or could rewrite to say, for $a in expr1[. ge min($b) + min($c)];
this sort of rewrite can turn a theoretically O(n^3) operation into O(n)
in practice.

I think the answer is, use "where" when it makes the query more
readable, or if there are positional or grouping clauses. Some
implementatins do more optimizatoins than others, though, so sometimes
readability ends up second to speed.

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml



More information about the talk mailing list