pingcap / tiflow

This repo maintains DM (a data migration platform) and TiCDC (change data capture for TiDB)
Apache License 2.0
416 stars 277 forks source link

wrong row-level causality key for prefix UNIQUE index #3286

Open lance6716 opened 2 years ago

lance6716 commented 2 years ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a recipe for reproducing the error.

we can add an unique index on prefix of string-type columns

in TiDB:

MySQL [test]> create table t (c int primary key, c2 text, unique key c2(c2(3)));
Query OK, 0 rows affected (0.025 sec)

MySQL [test]> insert into t values (1, '1234')
    -> ;
Query OK, 1 row affected (0.004 sec)

MySQL [test]> insert into t values (2, '1235')
    -> ;
ERROR 1062 (23000): Duplicate entry '123' for key 'c2'

so when calculate causality key of c2, we should use 123 not 1234, otherwise user may face errors like duplicate entry (update '1234' to '2234' will be concurrent with insert '1235').

  1. What did you expect to see?

  2. What did you see instead?

  3. Versions of the cluster

    • DM version (run dmctl -V or dm-worker -V or dm-master -V):

      master
lance6716 commented 2 years ago

now I think more types can use prefix index

https://dev.mysql.com/doc/refman/8.0/en/create-index.html#create-index-column-prefixes

lance6716 commented 2 years ago

seems we should use https://github.com/pingcap/tidb/blob/fde18397028a3ab30f38ab4ef964b6ef8e0adf7a/tablecodec/tablecodec.go#L1277-L1284

WizardXiao commented 2 years ago

https://github.com/pingcap/ticdc/pull/3467 just support prefix index, and we will support function index or expression index in other pr.