Commit 481e179
Merge #154914
154914: rowexec: fix inverted join with prefix columns with DESC direction r=yuzefovich a=yuzefovich
This commit fixes a bug that was added long time ago when we added support for inverted joins on multi-column inverted indexes (i.e. such indexes that have a prefix of "forward" columns that we can constrain using an equality filter) in d3f9a8b. In particular, in that change we added tricky logic which prepended the prefix to the encoded inverted key; however, we then didn't change how we use the `span.Builder`. That guy assumes that it receives datums for each index column (both prefix and inverted) whereas we only provided the inverted bytes (with the prepended prefix). This led to us being confused about which key column is being encoded during span construction.
Consider an example where we have one prefix key column like `i INT DESC` (followed by the inverted column). In this case, when calling `MakeKeyFromEncDatums` we'd try to encode the single EncDatum using the DESC key direction. The EncDatum internally stores the prefix + inverted key using ASC key direction, so we'd try to decode it and fail - because of the prepended prefix. After this patch, we'll correctly only use a single column in the call to `MakeKeyFromEncDatums`.
Note that if prefix columns had only ASC directions, then we would simply get lucky. Namely, since we have EncDatumRow with a single EncDatum AND that EncDatum already has encoded value of ASC direction stored, we'd just reuse it and exit.
The code here is quite difficult to follow and perhaps it could be refactored (e.g. the comment on `SpansFromInvertedSpans` says that multi-column inverted indexes are expected to use non-nil constraint, yet in the inverted joiner we always pass nil), but I chose a more targetted fix that seems reasonable.
Additionally, to simplify the change a bit, I inlined the code for `rowenc.MakeSpanFromEncDatums` into two call sites (which also allows us to avoid constructing the unnecessary end key for the inverted spans case).
Fixes: #153499.
Release note (bug fix): Previously, CockroachDB would hit an internal error when performing an inverted join using an inverted index in which the first prefix column had DESC direction. The bug has been present since 21.1 and is now fixed.
Co-authored-by: Yahor Yuzefovich <[email protected]>File tree
7 files changed
+43
-37
lines changed- pkg/sql
- logictest/testdata/logic_test
- opt/exec/execbuilder/testdata
- rowenc
- rowexec
- span
7 files changed
+43
-37
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | | - | |
| 285 | + | |
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
Lines changed: 5 additions & 5 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 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
| 141 | + | |
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
| 182 | + | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | 144 | | |
165 | 145 | | |
166 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
499 | 499 | | |
500 | 500 | | |
501 | 501 | | |
502 | | - | |
| 502 | + | |
| 503 | + | |
503 | 504 | | |
504 | 505 | | |
505 | 506 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
113 | 117 | | |
114 | 118 | | |
115 | 119 | | |
| |||
408 | 412 | | |
409 | 413 | | |
410 | 414 | | |
411 | | - | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
412 | 424 | | |
413 | 425 | | |
414 | 426 | | |
415 | 427 | | |
416 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
417 | 433 | | |
418 | 434 | | |
419 | 435 | | |
420 | 436 | | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
421 | 440 | | |
422 | 441 | | |
423 | 442 | | |
| |||
453 | 472 | | |
454 | 473 | | |
455 | 474 | | |
456 | | - | |
| 475 | + | |
457 | 476 | | |
458 | 477 | | |
459 | | - | |
| 478 | + | |
460 | 479 | | |
461 | 480 | | |
462 | 481 | | |
| |||
471 | 490 | | |
472 | 491 | | |
473 | 492 | | |
474 | | - | |
| 493 | + | |
475 | 494 | | |
476 | 495 | | |
477 | 496 | | |
| |||
489 | 508 | | |
490 | 509 | | |
491 | 510 | | |
492 | | - | |
493 | | - | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
494 | 519 | | |
495 | 520 | | |
496 | 521 | | |
| |||
0 commit comments