Skip to content

sql: SCRUB reports incorrect key ordering errors #32874

@thoszhang

Description

@thoszhang

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.

Metadata

Metadata

Assignees

Labels

C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions