"empty greatest" 和 "empty least" 在 Order By 中的作用是什么
What is role of "empty greatest" and "empty least" in Order By
在阅读 MarkLogic Query Performance and Tuning Guide
时,我了解了 empty greatest
和 empty least
以及如何将其与 order by
一起使用。但是,除此之外,没有太多细节或示例可供理解:
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
谁能帮我理解 empty greatest
和 empty least
的实际用例?
在 XQuery 规范中 https://www.w3.org/TR/xquery-31/#id-order-by-clause 它被解释为
For the purpose of determining their relative position in the ordering
sequence, the greater-than relationship between two orderspec values W
and V is defined as follows:
When the orderspec specifies empty least, the following rules are
applied in order:
If V is an empty sequence and W is not an empty sequence, then W
greater-than V is true.
If V is NaN and W is neither NaN nor an empty sequence, then W
greater-than V is true.
If a specific collation C is specified, and V and W are both of type
xs:string or are convertible to xs:string by subtype substitution
and/or type promotion, then:
If fn:compare(V, W, C) is less than zero, then W greater-than V is
true; otherwise W greater-than V is false.
If none of the above rules apply, then:
If W gt V is true, then W greater-than V is true; otherwise W
greater-than V is false.
When the orderspec specifies empty greatest, the following rules are
applied in order:
If W is an empty sequence and V is not an empty sequence, then W
greater-than V is true.
If W is NaN and V is neither NaN nor an empty sequence, then W
greater-than V is true.
If a specific collation C is specified, and V and W are both of type
xs:string or are convertible to xs:string by subtype substitution
and/or type promotion, then:
If fn:compare(V, W, C) is less than zero, then W greater-than V is
true; otherwise W greater-than V is false.
If none of the above rules apply, then:
If W gt V is true, then W greater-than V is true; otherwise W
greater-than V is false.
基本上,如果在 order by 子句中使用的表达式为要排序的项目提供空序列,则 empty least
声明将其排序在具有非空排序键的项目之前,而 empty greatest
在这些项目之后排序。
一个简单的例子:
XQuery
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method 'xml';
declare option output:indent 'yes';
for $item in root/item
order by $item/name, $item/cat empty greatest
return $item
排序
<root>
<item>
<name>a</name>
<cat>z</cat>
</item>
<item>
<name>a</name>
</item>
<item>
<name>a</name>
<cat>d</cat>
</item>
</root>
进入
<item>
<name>a</name>
<cat>d</cat>
</item>
<item>
<name>a</name>
<cat>z</cat>
</item>
<item>
<name>a</name>
</item>
在阅读 MarkLogic Query Performance and Tuning Guide
时,我了解了 empty greatest
和 empty least
以及如何将其与 order by
一起使用。但是,除此之外,没有太多细节或示例可供理解:
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
谁能帮我理解 empty greatest
和 empty least
的实际用例?
在 XQuery 规范中 https://www.w3.org/TR/xquery-31/#id-order-by-clause 它被解释为
For the purpose of determining their relative position in the ordering sequence, the greater-than relationship between two orderspec values W and V is defined as follows:
When the orderspec specifies empty least, the following rules are applied in order:
If V is an empty sequence and W is not an empty sequence, then W greater-than V is true.
If V is NaN and W is neither NaN nor an empty sequence, then W greater-than V is true.
If a specific collation C is specified, and V and W are both of type xs:string or are convertible to xs:string by subtype substitution and/or type promotion, then:
If fn:compare(V, W, C) is less than zero, then W greater-than V is true; otherwise W greater-than V is false.
If none of the above rules apply, then:
If W gt V is true, then W greater-than V is true; otherwise W greater-than V is false.
When the orderspec specifies empty greatest, the following rules are applied in order:
If W is an empty sequence and V is not an empty sequence, then W greater-than V is true.
If W is NaN and V is neither NaN nor an empty sequence, then W greater-than V is true.
If a specific collation C is specified, and V and W are both of type xs:string or are convertible to xs:string by subtype substitution and/or type promotion, then:
If fn:compare(V, W, C) is less than zero, then W greater-than V is true; otherwise W greater-than V is false.
If none of the above rules apply, then:
If W gt V is true, then W greater-than V is true; otherwise W greater-than V is false.
基本上,如果在 order by 子句中使用的表达式为要排序的项目提供空序列,则 empty least
声明将其排序在具有非空排序键的项目之前,而 empty greatest
在这些项目之后排序。
一个简单的例子:
XQuery
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method 'xml';
declare option output:indent 'yes';
for $item in root/item
order by $item/name, $item/cat empty greatest
return $item
排序
<root>
<item>
<name>a</name>
<cat>z</cat>
</item>
<item>
<name>a</name>
</item>
<item>
<name>a</name>
<cat>d</cat>
</item>
</root>
进入
<item>
<name>a</name>
<cat>d</cat>
</item>
<item>
<name>a</name>
<cat>z</cat>
</item>
<item>
<name>a</name>
</item>