[xquery-talk] unordered {} and fn:unordered()
Michael Kay
mhk at mhk.me.uk
Thu Jan 19 11:10:24 PST 2006
>
> I am wondering whether you have noticed that your favorite XQuery
> processor indeed realizes such an advantage when it processes
> expressions of the form unordered {e} or fn:unordered(e)?
I think the facility was added primarily for people who are mapping XQuery
to SQL, because generating/executing a SQL expression that produces results
in the right order can be a lot of work. Native XML storage tends to have
intrinsic support for ordering, so it's less of an issue. There may be
optimisations one can do in unordered mode, but as far as I'm concerned
they're not very high up my list - apart from anything else, it's much more
important to optimize badly written queries than to optimize well-written
ones (and I don't regard setting the default to "unordered" as viable in a
world where people think of their data in XML terms rather than in
relational terms).
When Saxon finds that it needs to do a sort, it's either because the user
asked for it, or because it's delivering results "in document order with
duplicates eliminated". Since "unordered" doesn't remove the obligation to
remove duplicates, and since the simplest way of removing duplicates is to
sort, "unordered" doesn't actually help much in this scenario. There are a
very few exceptions, for example unordered(preceding-sibling::x) will return
the siblings in reverse document order. (The danger, of course, is that
people will rely on that!)
Michael Kay
http://www.saxonica.com/
More information about the talk
mailing list