|
9 | 9 |
|
10 | 10 | /** |
11 | 11 | * This interface is intended to check redundancy of a previous SORT. |
| 12 | + *<p> |
12 | 13 | * |
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, |
14 | 21 | * then we can assume that |
15 | 22 | * <p> |
16 | 23 | * <code> |
17 | | - * | SORT x | MY_COMMAND |
| 24 | + * | SORT x, y, z | MY_COMMAND | SORT a, b, c |
18 | 25 | * </code> |
19 | 26 | * <p> |
20 | 27 | * is equivalent to |
21 | 28 | * <p> |
22 | 29 | * <code> |
23 | | - * | MY_COMMAND |
| 30 | + * | MY_COMMAND | SORT a, b, c |
24 | 31 | * </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> |
25 | 65 | * <p> |
26 | 66 | * |
27 | 67 | * 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> |
29 | 95 | */ |
30 | 96 | public interface SortAware { |
31 | 97 |
|
|
0 commit comments