cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

sql: SCRUB reports incorrect key ordering errors

Open thoszhang opened this issue 7 years ago • 0 comments

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:

[email protected]: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

[email protected]:63898/defaultdb> select * from test;
  id | val
+----+-----+
   1 |   2
   2 |   1
(2 rows)

Time: 653µs

[email protected]: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 avatar Dec 05 '18 21:12 thoszhang