Skip to content

Commit 2d34e50

Browse files
Better description for SortAware
1 parent 7a9c8ab commit 2d34e50

File tree

1 file changed

+70
-4
lines changed
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical

1 file changed

+70
-4
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/SortAware.java

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,89 @@
99

1010
/**
1111
* This interface is intended to check redundancy of a previous SORT.
12+
*<p>
1213
*
13-
* Eg. if a MY_COMMAND that implements this interface is used after a sort, and if dependsOnInputOrder() = false,
14+
* An example is with commands that compute values record by record, regardless of the input order
15+
* and that don't rely on the context (intended as previous/next records).
16+
*
17+
* <hr>
18+
* <p>
19+
*
20+
* Example 1: if a MY_COMMAND that implements this interface is used between two sorts, and if dependsOnInputOrder() = false,
1421
* then we can assume that
1522
* <p>
1623
* <code>
17-
* | SORT x | MY_COMMAND
24+
* | SORT x, y, z | MY_COMMAND | SORT a, b, c
1825
* </code>
1926
* <p>
2027
* is equivalent to
2128
* <p>
2229
* <code>
23-
* | MY_COMMAND
30+
* | MY_COMMAND | SORT a, b, c
2431
* </code>
32+
*
33+
* <hr>
34+
* <p>
35+
*
36+
* Example 2: commands that make previous order irrelevant, eg. because they collapse the results;
37+
* STATS is one of them, eg.
38+
*
39+
* <p>
40+
* <code>
41+
* | SORT x, y, z | STATS count(*)
42+
* </code>
43+
* <p>
44+
* is equivalent to
45+
* <p>
46+
* <code>
47+
* | STATS count(*)
48+
* </code>
49+
* <p>
50+
*
51+
* and if MY_COMMAND implements this interface and if dependsOnInputOrder() = false, then
52+
*
53+
* <p>
54+
* <code>
55+
* | SORT x, y, z | MY_COMMAND | STATS count(*)
56+
* </code>
57+
* <p>
58+
* is equivalent to
59+
* <p>
60+
* <code>
61+
* | MY_COMMAND | STATS count(*)
62+
* </code>
63+
*
64+
* <hr>
2565
* <p>
2666
*
2767
* In all the other cases, eg. if the command does not implement this interface, or if dependsOnInputOrder() = true
28-
* then we assume that the SORT is still relevant and cannot be pruned.
68+
* then we assume that the previous SORT is still relevant and cannot be pruned.
69+
*
70+
* <hr>
71+
* <p>
72+
*
73+
* Eg. LIMIT does <b>not</b> implement this interface, because
74+
*
75+
* <p>
76+
* <code>
77+
* | SORT x, y, z | LIMIT 10 | SORT a, b, c
78+
* </code>
79+
* <p>
80+
* is <b>NOT</b> equivalent to
81+
* <p>
82+
* <code>
83+
* | LIMIT 10 | SORT a, b, c
84+
* </code>
85+
*
86+
* <hr>
87+
* <p>
88+
*
89+
* For n-ary plans that implement this interface,
90+
* we assume that the above applies to all the children, ie.
91+
* <ul>
92+
* <li>if dependsOnInputOrder() = false, sorts can be pruned on all the children</li>
93+
* <li>if dependsOnInputOrder() = true, sorts cannot be pruned on any of the children</li>
94+
* </ul>
2995
*/
3096
public interface SortAware {
3197

0 commit comments

Comments
 (0)