Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: SCRUB reports incorrect key ordering errors #32874

Closed
thoszhang opened this issue Dec 5, 2018 · 0 comments · Fixed by #32908
Closed

sql: SCRUB reports incorrect key ordering errors #32874

thoszhang opened this issue Dec 5, 2018 · 0 comments · Fixed by #32908
Assignees
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

Comments

@thoszhang
Copy link
Contributor

For indexes containing more than one column, SCRUB incorrectly reports an index_key_decoding_error during a PHYSICAL check table scan whenever it detects a value in a column that is earlier in sorted order than the value in the previous row.

In the below example, the val column is not in sorted order because it's not the first column in the primary key:

root@127.0.0.1:63898/defaultdb> show create test;
  table_name |                    create_statement
+------------+---------------------------------------------------------+
  test       | CREATE TABLE test (
             |     id INT NOT NULL,
             |     val INT NOT NULL,
             |     CONSTRAINT "primary" PRIMARY KEY (id ASC, val ASC),
             |     FAMILY "primary" (id, val)
             | )
(1 row)

Time: 4.194ms

root@127.0.0.1:63898/defaultdb> select * from test;
  id | val
+----+-----+
   1 |   2
   2 |   1
(2 rows)

Time: 653µs

root@127.0.0.1:63898/defaultdb> experimental scrub table test with options physical;
  job_uuid |        error_type        | database  | table | primary_key |            timestamp             | repaired |                                                                      details
+----------+--------------------------+-----------+-------+-------------+----------------------------------+----------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  NULL     | index_key_decoding_error | defaultdb | test  | (2,1)       | 2018-12-05 21:51:18.954254+00:00 |  false   | {"error_message": "key ordering did not match datum ordering. IndexDescriptor=ASC", "index_name": "primary", "row_data": {"id": "2", "val": "1"}}
(1 row)

Time: 934µs

The logic in https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/row/fetcher.go#L1244 needs to be fixed.

@thoszhang thoszhang added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Dec 5, 2018
@thoszhang thoszhang self-assigned this Dec 5, 2018
thoszhang pushed a commit to thoszhang/cockroach that referenced this issue Dec 6, 2018
Previously `SCRUB` would erroneously report that index keys were out of order
for columns other than the first column in an index. This fixes the bug.

Fixes cockroachdb#32874.

Release note (bug fix): Fixed bug where SCRUB would erroneously report that
index keys were out of order.
craig bot pushed a commit that referenced this issue Dec 6, 2018
32908: sql: fix SCRUB index key order checking r=lucy-zhang a=lucy-zhang

Previously `SCRUB` would erroneously report that index keys were out of order
for columns other than the first column in an index. This fixes the bug.

Fixes #32874.

Release note (bug fix): Fixed bug where SCRUB would erroneously report that
index keys were out of order.

Co-authored-by: Lucy Zhang <lucy-zhang@users.noreply.github.com>
@craig craig bot closed this as completed in #32908 Dec 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant