tencent cloud

문서TDSQL-C for MySQL

Data Inconsistency Between Primary and Secondary Instances

다운로드
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-11-09 11:21:40
AI 번역
This document describes the possible causes and solutions for data inconsistency between primary and secondary instances when data is queried after an auto-increment primary key is added.

Issue Symptom

When you query the primary and secondary instances separately using the same auto-increment primary key value (auto-increment ID), the data in the query results is inconsistent.

Possible Causes

When an auto-increment primary key is added to a table without a primary key, the auto-increment primary key values are assigned based on the physical storage order of the data in the table. Because a table without a primary key lacks explicit primary key constraints, the order of its rows is determined by the internal RowID of the storage engine. The RowIDs of the same data on the primary and secondary instances may differ, resulting in inconsistent physical ordering of data between the primary and secondary instances. This causes the same data to be assigned different auto-increment primary key values on different instances. Therefore, when the same auto-increment primary key value is used to query the primary and secondary instances separately, the results may differ. For details, see BUG#92949 and MySQL official documentation.

Solutions

1. Create a new table on the primary instance that is identical to the original table without a primary key, and add an auto-increment primary key to it.
2. Sort the data by all fields and insert it into the new table.
3. Delete the original table without a primary key, and rename the new table to the name of the original table without a primary key.
Examples
CREATE TABLE t2 LIKE t1;
ALTER TABLE t2 ADD id INT AUTO_INCREMENT PRIMARY KEY;
INSERT INTO t2 SELECT * FROM t1 ORDER BY col1, col2;
DROP TABLE t1;
RENAME TABLE t2 TO t1;

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백