Skip to content

UPDATE and INSERT ON DUPLICATE KEY doesn't update index containing generated column #58400

@joechenrh

Description

@joechenrh

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Case1:

CREATE TABLE t3 (
    id int,
    time1 datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    time2 datetime GENERATED ALWAYS AS (date_add(time1, interval 1 day)) VIRTUAL,
    KEY idx (id, time2)
);

insert into t3 set id = 1;

update t3 set id = 2;

admin check table t3;

Case2:

drop table tmv;
CREATE TABLE tmv (
  J1 json, J2 json GENERATED ALWAYS AS (j1) VIRTUAL,
  UNIQUE KEY i1 ((cast(j1 as signed array))),
  KEY i2 ((cast(j2 as signed array)))
);

insert into tmv set j1 = '[1]';

insert ignore into tmv set j1 = '[1]' on duplicate key update j1 = '[2]';

admin check table tmv;

2. What did you expect to see? (Required)

Both admin check table passed.

3. What did you see instead (Required)

ERROR 8223 (HY000): data inconsistency in table: t3, index: idx, handle: 1, index-values:"handle: 1, values: [KindInt64 2 KindMysqlTime 2024-12-20 10:33:33]" != record-values:"handle: 1, values: [KindInt64 2 KindMysqlTime 2024-12-20 10:33:38]"
                                    
ERROR 8134 (HY000): data inconsistency in table: tmv, index: i2, col: _V$_i2_0, handle: "1",
 index-values:"KindInt64 1" != record-values:"KindMysqlJSON [2]", compare err:<nil> 

4. What is your TiDB version? (Required)

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-6.1This bug affects the 6.1.x(LTS) versions.affects-6.5This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.affects-8.5This bug affects the 8.5.x(LTS) versions.component/ddlThis issue is related to DDL of TiDB.impact/inconsistencyincorrect/inconsistency/inconsistentseverity/majortype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions