Commit 3308496
[SPARK-26065][SQL] Change query hint from a
## What changes were proposed in this pull request?
The existing query hint implementation relies on a logical plan node `ResolvedHint` to store query hints in logical plans, and on `Statistics` in physical plans. Since `ResolvedHint` is not really a logical operator and can break the pattern matching for existing and future optimization rules, it is a issue to the Optimizer as the old `AnalysisBarrier` was to the Analyzer.
Given the fact that all our query hints are either 1) a join hint, i.e., broadcast hint; or 2) a re-partition hint, which is indeed an operator, we only need to add a hint field on the Join plan and that will be a good enough solution for the current hint usage.
This PR is to let `Join` node have a hint for its left sub-tree and another hint for its right sub-tree and each hint is a merged result of all the effective hints specified in the corresponding sub-tree. The "effectiveness" of a hint, i.e., whether that hint should be propagated to the `Join` node, is currently consistent with the hint propagation rules originally implemented in the `Statistics` approach. Note that the `ResolvedHint` node still has to live through the analysis stage because of the `Dataset` interface, but it will be got rid of and moved to the `Join` node in the "pre-optimization" stage.
This PR also introduces a change in how hints work with join reordering. Before this PR, hints would stop join reordering. For example, in "a.join(b).join(c).hint("broadcast").join(d)", the broadcast hint would stop d from participating in the cost-based join reordering while still allowing reordering from under the hint node. After this PR, though, the broadcast hint will not interfere with join reordering at all, and after reordering if a relation associated with a hint stays unchanged or equivalent to the original relation, the hint will be retained, otherwise will be discarded. For example, the original plan is like "a.join(b).hint("broadcast").join(c).hint("broadcast").join(d)", thus the join order is "a JOIN b JOIN c JOIN d". So if after reordering the join order becomes "a JOIN b JOIN (c JOIN d)", the plan will be like "a.join(b).hint("broadcast").join(c.join(d))"; but if after reordering the join order becomes "a JOIN c JOIN b JOIN d", the plan will be like "a.join(c).join(b).hint("broadcast").join(d)".
## How was this patch tested?
Added new tests.
Closes apache#23036 from maryannxue/query-hint.
Authored-by: maryannxue <maryannxue@apache.org>
Signed-off-by: gatorsmile <gatorsmile@gmail.com>LogicalPlan to a field1 parent 695db1e commit 3308496
File tree
47 files changed
+680
-283
lines changed- sql
- catalyst/src
- main/scala/org/apache/spark/sql/catalyst
- analysis
- dsl
- optimizer
- parser
- planning
- plans/logical
- statsEstimation
- test/scala/org/apache/spark/sql/catalyst
- analysis
- optimizer
- plans
- statsEstimation
- core/src
- main/scala/org/apache/spark/sql
- execution
- columnar
- test/scala/org/apache/spark/sql
- execution/joins
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
47 files changed
+680
-283
lines changedLines changed: 9 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
943 | 943 | | |
944 | 944 | | |
945 | 945 | | |
946 | | - | |
| 946 | + | |
947 | 947 | | |
948 | 948 | | |
949 | 949 | | |
| |||
2249 | 2249 | | |
2250 | 2250 | | |
2251 | 2251 | | |
2252 | | - | |
| 2252 | + | |
2253 | 2253 | | |
2254 | | - | |
2255 | | - | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
2256 | 2257 | | |
2257 | 2258 | | |
2258 | | - | |
| 2259 | + | |
2259 | 2260 | | |
2260 | 2261 | | |
2261 | 2262 | | |
| |||
2360 | 2361 | | |
2361 | 2362 | | |
2362 | 2363 | | |
2363 | | - | |
| 2364 | + | |
| 2365 | + | |
2364 | 2366 | | |
2365 | 2367 | | |
2366 | 2368 | | |
| |||
2401 | 2403 | | |
2402 | 2404 | | |
2403 | 2405 | | |
2404 | | - | |
| 2406 | + | |
2405 | 2407 | | |
2406 | 2408 | | |
2407 | 2409 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
175 | | - | |
| 175 | + | |
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
| |||
609 | 609 | | |
610 | 610 | | |
611 | 611 | | |
612 | | - | |
| 612 | + | |
613 | 613 | | |
614 | 614 | | |
615 | 615 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
232 | | - | |
| 232 | + | |
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
328 | | - | |
| 328 | + | |
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
| |||
Lines changed: 64 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
34 | 68 | | |
35 | 69 | | |
36 | 70 | | |
| |||
40 | 74 | | |
41 | 75 | | |
42 | 76 | | |
| 77 | + | |
| 78 | + | |
43 | 79 | | |
44 | 80 | | |
45 | | - | |
46 | | - | |
47 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
48 | 84 | | |
49 | | - | |
| 85 | + | |
50 | 86 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
55 | 92 | | |
56 | 93 | | |
57 | 94 | | |
58 | 95 | | |
59 | | - | |
60 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
61 | 101 | | |
62 | 102 | | |
63 | 103 | | |
| |||
75 | 115 | | |
76 | 116 | | |
77 | 117 | | |
78 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
79 | 121 | | |
80 | | - | |
81 | | - | |
82 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
83 | 127 | | |
84 | 128 | | |
85 | | - | |
| 129 | + | |
86 | 130 | | |
87 | | - | |
| 131 | + | |
88 | 132 | | |
89 | 133 | | |
90 | 134 | | |
91 | 135 | | |
92 | 136 | | |
93 | 137 | | |
94 | | - | |
| 138 | + | |
95 | 139 | | |
96 | 140 | | |
97 | 141 | | |
98 | | - | |
| 142 | + | |
99 | 143 | | |
100 | 144 | | |
101 | 145 | | |
| |||
295 | 339 | | |
296 | 340 | | |
297 | 341 | | |
298 | | - | |
| 342 | + | |
299 | 343 | | |
300 | 344 | | |
301 | 345 | | |
| |||
Lines changed: 59 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
0 commit comments