Skip to content

[Bug]: INSERT ON DUPLICATE KEY UPDATE does not properly update unique index entries #23637

@XuPeng-SH

Description

@XuPeng-SH

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Please provide the following information to help us understand the issue.

Branch Name

main,3.0-dev

Commit ID

e.g., a1b2c3d

Other Environment Information

  • Hardware parameters:
  • OS type:
  • Others:

Actual Behavior

When executing INSERT ... ON DUPLICATE KEY UPDATE with duplicate key values, the unique index is not properly updated. The index table contains orphaned entries with NULL primary keys.

Expected Behavior

The unique index should be properly maintained during the UPDATE operation. All index entries should have valid primary key references.

Steps to Reproduce

DROP TABLE IF EXISTS repro_insert_on_dup_bug;
CREATE TABLE repro_insert_on_dup_bug (
    id INT,
    a VARCHAR(20) NOT NULL,
    UNIQUE KEY uk_repro_insert_on_dup_bug (a)
);
INSERT INTO repro_insert_on_dup_bug VALUES (1,'x'),(2,'y'),(3,'z');
INSERT INTO repro_insert_on_dup_bug VALUES (2,'y'),(4,'w') ON DUPLICATE KEY UPDATE id=VALUES(id);

-- Check index table
SET @sql = CONCAT('SELECT * FROM `', (SELECT DISTINCT index_table_name FROM mo_catalog.mo_indexes WHERE name = "uk_repro_insert_on_dup_bug"), '` ORDER BY `__mo_index_idx_col`');
PREPARE stmt FROM @sql;
EXECUTE stmt;
+--------------------+--------------------+
| __mo_index_idx_col | __mo_index_pri_col |
+--------------------+--------------------+
| w                  |               NULL |
| x                  |                  1 |
| y                  |                  2 |
| z                  |                  3 |
+--------------------+--------------------+
4 rows in set (0.000 sec)

Additional information

The issue occurs specifically with ON DUPLICATE KEY UPDATE operations on tables with unique indexes. Index maintenance is not synchronized with the update operation.

Metadata

Metadata

Assignees

Labels

kind/bugSomething isn't workingseverity/s0Extreme impact: Cause the application to break down and seriously affect the use

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions