Commit ee20eae
153067: opt: make outside-of-histogram estimates more pessimistic r=DrewKimball a=DrewKimball
#### opt: improve outside-histogram optimizer tests
This commit makes the following improvements to the `outside-histogram`
optimizer test:
* Fixes a minor mistake in the test, where the upper bounds on a histogram
for a unique column were incorrect.
* Simplifies the test code for setting session variable defaults.
* Adds comments explaining each test case.
Epic: None
Release note: None
#### opt: add unique and distinct column to outside-histogram test
This commit adds a column `u` with a unique index, and a column `d`
with a non-unique index to the outside-histogram test table. Both
columns use the same histogram as the primary key `k` (and therefore
have no duplicate values).
This commit also adds tests that are similar to `Q1`, but using the
new columns instead of `k`. This shows the optimizer's behavior when
the "good" plan requires an index join, and when filtering on `d`,
shows how the optimizer behaves when no plan limits the max cardinality
of the query.
Epic: None
Release note: None
#### opt: add outside-histogram test for missing enum value
This commit adds a pair of `outside-histogram` optimizer test cases that
simulate a query against an enum column for which one of the values was not
sampled.
Epic: None
Release note: None
#### opt: add outside-histogram tests with large table
This commit adds to the existing optimizer tests for filters that select
values outside of histograms. The new tests are against a large table
to show how the optimizer's trust of low-selectivity estimates varies
with table size.
Epic: None
Release note: None
#### opt: make outside-of-histogram estimates more pessimistic
This commit makes rowcount estimation fall back on distinct count estimates
when a constraint includes zero histogram values. This biases the optimizer
toward less risky plans when less information is known about the filtered
values.
The pessimistic logic is triggered when the estimate derived from a histogram
is smaller than `table_row_count / 10,000`. This threshold is chosen because
we choose samples such that we expect to sample *nearly* every value with
multiplicity down to `table_row_count / 10,000` (see computeNumberSamples).
Selecivity estimates from a histogram below this resolution are suspect,
since there is increasing likelihood that a value was missed either due
to being omitted from the sample, or due to staleness.
Informs cockroachdb#130201
Release note (sql change): Added a clamp for row-count estimates over very
large tables so that the optimizer assumes that at least one distinct value
will be scanned. This reduces the chances of a catastrophic underestimate.
The new logic is off by default, gated by a session setting
`optimizer_clamp_low_histogram_selectivity`.
#### opt: use pessimistic estimates for inequality filters
This commit changes row count estimates for inequality filters, so that
we expect at least `rowCount / (bucketCount * 100)` rows to "survive" the
filter. This is in line with Postgres, which clamps inequality rowcount
estimates in a similar fashion.
Informs cockroachdb#130201
Release note (sql change): Added a clamp for the estimated selectivity of
inequality predicates that are unbounded on one or both sides (ex: `x > 5`).
This reduces the chances of a catastrophic understimate causing the optimizer
to choose a poorly-constrained scan. The new logic is off by default, gated by
the session setting `optimizer_clamp_inequality_selectivity`.
#### sql/opt: add telemetry counters for selectivity clamping
This commit adds telemetry counters for the new histogram selectivity
clamping behavior, as well as log messages to indicate when the new
behavior applies in a query's trace.
Epic: None
Release note: None
155554: kvserver: split meta1 and meta2 r=iskettaneh a=iskettaneh
Previously, we used to start meta1 and meta2 in one range at bootstrap, and rely on load-based splitting to split them if needed. However, in some cases, load-based splitting doesn't work when it decides to split a point in meta1 (meta1 is not allowed to split).
This PR does two things:
1) At bootstrap, we create two separate ranges for meta1 and meta2.
2) Use spanconfig to install a split point at the start of meta2. This will prevent the two ranges from getting merged together, also, it will split meta1 and meta2 ranges for clusters that were bootstrapped before this PR.
In order to ensure that we get the descriptors correct, I started a
cluster (when meta1 and meta2 were on the same range), and manually
split them and captured the descriptors:
```
[1] Meta Key: /Meta1/""
Range r1:
StartKey: /Min
EndKey: /Meta2/""
Replicas: (n1,s1):1
Generation: 1
[2] Meta Key: /Meta1/Max
Range r79:
StartKey: /Meta2/""
EndKey: /System/NodeLiveness
Replicas: (n1,s1):1
Generation: 1
[3] Meta Key: /Meta2/System/NodeLiveness
Range r79:
StartKey: /Meta2/""
EndKey: /System/NodeLiveness
Replicas: (n1,s1):1
Generation: 1
[4] Meta Key: /Meta2/System/NodeLivenessMax
Range r2:
StartKey: /System/NodeLiveness
EndKey: /System/NodeLivenessMax
Replicas: (n1,s1):1
Generation: 0
```
After this commit, the first few ranges are bootstrapped with
the following descriptors:
```
[1] Meta Key: /Meta1/""
Range r1:
StartKey: /Min
EndKey: /Meta2/""
Replicas: (n1,s1):1
Generation: 0
[2] Meta Key: /Meta1/Max
Range r2:
StartKey: /Meta2/""
EndKey: /System/NodeLiveness
Replicas: (n1,s1):1
Generation: 0
[3] Meta Key: /Meta2/System/NodeLiveness
Range r2:
StartKey: /Meta2/""
EndKey: /System/NodeLiveness
Replicas: (n1,s1):1
Generation: 0
[4] Meta Key: /Meta2/System/NodeLivenessMax
Range r3:
StartKey: /System/NodeLiveness
EndKey: /System/NodeLivenessMax
Replicas: (n1,s1):1
Generation: 0
```
Fixes: cockroachdb#119421
Release note: None
Co-authored-by: Drew Kimball <[email protected]>
Co-authored-by: iskettaneh <[email protected]>
File tree
60 files changed
+4404
-958
lines changed- pkg
- ccl
- logictestccl/testdata/logic_test
- spanconfigccl
- spanconfigreconcilerccl/testdata
- multitenant
- spanconfigsqltranslatorccl
- testdata
- cli
- config
- kv
- kvprober
- kvserver
- loqrecovery
- server
- application_api
- spanconfig/spanconfigsqltranslator
- sql
- logictest/testdata/logic_test
- opt
- exec/execbuilder/testdata
- memo
- props
- testutils
- opttester
- testcat
- xform/testdata/coster
- sessiondatapb
- sqltelemetry
- testdata/telemetry
- util/rangedesc/testdata
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
60 files changed
+4404
-958
lines changedLines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
254 | | - | |
| 254 | + | |
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
259 | | - | |
| 259 | + | |
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
471 | 471 | | |
472 | 472 | | |
473 | 473 | | |
474 | | - | |
| 474 | + | |
475 | 475 | | |
476 | 476 | | |
477 | 477 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
| 203 | + | |
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| |||
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
120 | | - | |
| 121 | + | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
| |||
288 | 289 | | |
289 | 290 | | |
290 | 291 | | |
291 | | - | |
| 292 | + | |
292 | 293 | | |
293 | 294 | | |
294 | 295 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
| 168 | + | |
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
224 | | - | |
| 224 | + | |
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
253 | | - | |
| 253 | + | |
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
| |||
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
| 207 | + | |
208 | 208 | | |
209 | | - | |
| 209 | + | |
| 210 | + | |
210 | 211 | | |
211 | 212 | | |
212 | 213 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
217 | | - | |
| 217 | + | |
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
189 | | - | |
| 189 | + | |
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
| |||
Lines changed: 25 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | | - | |
| 55 | + | |
55 | 56 | | |
56 | | - | |
| 57 | + | |
| 58 | + | |
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| |||
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
72 | | - | |
73 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
74 | 78 | | |
75 | 79 | | |
76 | 80 | | |
77 | | - | |
| 81 | + | |
78 | 82 | | |
79 | | - | |
| 83 | + | |
| 84 | + | |
80 | 85 | | |
81 | 86 | | |
82 | 87 | | |
| |||
100 | 105 | | |
101 | 106 | | |
102 | 107 | | |
103 | | - | |
104 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
105 | 112 | | |
106 | 113 | | |
107 | 114 | | |
| |||
111 | 118 | | |
112 | 119 | | |
113 | 120 | | |
114 | | - | |
| 121 | + | |
115 | 122 | | |
116 | | - | |
| 123 | + | |
| 124 | + | |
117 | 125 | | |
118 | 126 | | |
119 | 127 | | |
120 | 128 | | |
121 | 129 | | |
122 | 130 | | |
123 | | - | |
| 131 | + | |
124 | 132 | | |
125 | 133 | | |
126 | 134 | | |
| |||
165 | 173 | | |
166 | 174 | | |
167 | 175 | | |
168 | | - | |
| 176 | + | |
169 | 177 | | |
170 | 178 | | |
171 | 179 | | |
| |||
213 | 221 | | |
214 | 222 | | |
215 | 223 | | |
216 | | - | |
| 224 | + | |
217 | 225 | | |
218 | | - | |
| 226 | + | |
| 227 | + | |
219 | 228 | | |
220 | 229 | | |
221 | 230 | | |
| |||
0 commit comments