While reading MarkLogic Query Performance and Tuning Guide, I got to know about empty greatest and empty least and how it can be used with order by. However, there is not much detail or examples available for this to understand other than this:
You can specify either empty greatest or empty least, but empties always need to be at the end for the order by optimizations to work. For example, empty greatest is optimized with ascending; empty least is optimized with descending. If neither is specified, MarkLogic chooses the order that is optimized. The following example goes against the default. It orders the list by $doc/document/modified_date, ascending order, with empty least:
xquery version "1.0-ml";
for $doc in fn:doc()
order by $doc/document/modified_date ascending empty least
return $doc
Could any one help me to understand the actual use case of empty greatest and empty least?