Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
97151: opt: fix incorrect results from zigzag join with different index directions r=rytaft a=rytaft Prior to this commit, the optimizer could plan a zigzag join between two indexes where the matching column(s) had ascending values in one index and descending values in the other. This could cause incorrect results, because it broke an assumption of the `zigzagJoiner`. For example, consider this table and query: ``` CREATE TABLE t ( c INT NOT NULL, l INT NOT NULL, r INT NOT NULL, INDEX (l ASC, c DESC), INDEX (r ASC, c ASC) ); INSERT INTO t VALUES (1, 1, -1), (2, 1, -2); SELECT * FROM t@{FORCE_ZIGZAG} WHERE l = 1 AND r = -1; ``` This query should produce 1 row, but prior to this commit it produced 0 rows. This was due to the fact that the direction of `c` was different between the two indexes. This commit fixes the issue by preventing the optimizer from planning a zigzag join in such cases. Fixes cockroachdb#97090 Release note (bug fix): Fixed a bug in the query engine that could cause incorrect results in some cases when a zigzag join was planned. The bug could occur when the two indexes used for the zigzag join had a suffix of matching columns but with different directions. For example, planning a zigzag join with `INDEX(a ASC, b ASC)` and `INDEX(c ASC, b DESC)` could cause incorrect results. This bug has existed since at least v19.1. It is now fixed, because the optimizer will no longer plan a zigzag join in such cases. 97435: tree: fix DatumPrev for collated string r=yuzefovich a=yuzefovich This commit removes the support of collated strings from `DatumPrev`. As it turns out, the comparison of collated strings is done by comparing their collation keys, and the current method of generating the previous string (simply subtracting 1 from the last non-zero byte) doesn't work. Similar bug in `DatumNext` was fixed in 1902d3d (which added the collated strings into randomly generated types), but I didn't stress the test to catch this bug. The impact of the bug is minor since it's only used in `debug statement-bundle recreate` command. Epic: None Release note: None Co-authored-by: Rebecca Taft <[email protected]> Co-authored-by: Yahor Yuzefovich <[email protected]>
- Loading branch information