• +49-(0)721-402485-12
Your experts for XML, XQuery and XML Databases

Cancellation of the sorting

If, from the view of the application, a sorting is completely refused, it can be communicated to the system with the help of the fn:unordered() function. The hint that a sorting order (also the document order) does not have to be taken into account, opens the executing system new kinds of freedom for optimising and performing more efficiently the XQuery query.

The fn:unordered() function expects as a parameter a sequence and returns this sequence with an order which is not deterministically predictable. Since the cancellation of a sorting order is realised in XQuery as a function, the sorting can be used for an entire FLWOR expression or also just for individual parts or subexpressions.

If, for example, prices for medical devices shall be converted to another currency and in doing so, an explicit sorting shall be refused, the sorting can already be cancelled when evaluating the path expression for the initialisation of the control variables via all medical devices.

for $i in fn:unordered(fn:doc("Consumables.xml")//Article)
<USD-Price>{ $i/UnitPrice div 1.21 }</USD-Price>

Alternatively, the cancellation of the sorting is also applicable at the level of the entire FLWOR expression:

fn:unordered(for $i in fn:doc("Consumables.xml")//Article
<USD-Price>{ $i/UnitPrice div 1.21 }</USD-Price>)

While the optimisation potential for simple FLWOR expressions keeps within limits, the cancellation of the sorting for join and nested FLWOR expressions enables a significant freedom to make the query execution more efficient.

However, it should be noted here that, in general, the document order applies which must explicitly be superposed with an application-specific sorting criterion or cancelled by the application of the fn:unordered() function.


Source: "XQuery – Grundlagen und fortgeschrittene Methoden", dpunkt-Verlag, Heidelberg (2004)

<< backnext >>