diff --git a/character-set-and-collation.md b/character-set-and-collation.md
index ce8c15f548820..b1febe9bba67c 100644
--- a/character-set-and-collation.md
+++ b/character-set-and-collation.md
@@ -542,7 +542,7 @@ INSERT INTO t VALUES ('a');
```
```sql
-ERROR 1062 (23000): Duplicate entry 'a' for key 'PRIMARY' # TiDB is compatible with the case-insensitive collation of MySQL.
+ERROR 1062 (23000): Duplicate entry 'a' for key 't.PRIMARY' # TiDB is compatible with the case-insensitive collation of MySQL.
```
```sql
@@ -550,7 +550,7 @@ INSERT INTO t VALUES ('a ');
```
```sql
-ERROR 1062 (23000): Duplicate entry 'a ' for key 'PRIMARY' # TiDB modifies the `PADDING` behavior to be compatible with MySQL.
+ERROR 1062 (23000): Duplicate entry 'a ' for key 't.PRIMARY' # TiDB modifies the `PADDING` behavior to be compatible with MySQL.
```
> **Note:**
diff --git a/constraints.md b/constraints.md
index 7a8dd31df27ad..165d475096f0c 100644
--- a/constraints.md
+++ b/constraints.md
@@ -114,7 +114,7 @@ COMMIT;
```
```
-ERROR 1062 (23000): Duplicate entry 'bill' for key 'username'
+ERROR 1062 (23000): Duplicate entry 'bill' for key 'users.username'
```
In the preceding optimistic example, the unique check was deferred until the transaction is committed. This resulted in a duplicate key error, because the value `bill` was already present.
@@ -154,7 +154,7 @@ INSERT INTO users (username) VALUES ('jane'), ('chris'), ('bill');
```
```
-ERROR 1062 (23000): Duplicate entry 'bill' for key 'username'
+ERROR 1062 (23000): Duplicate entry 'bill' for key 'users.username'
```
The first `INSERT` statement caused a duplicate key error. This causes additional network communication overhead and may reduce the throughput of insert operations.
@@ -177,7 +177,7 @@ INSERT INTO users (username) VALUES ('jane'), ('chris'), ('bill');
```
```
-ERROR 1062 (23000): Duplicate entry 'bill' for key 'username'
+ERROR 1062 (23000): Duplicate entry 'bill' for key 'users.username'
```
To achieve better performance of pessimistic transactions, you can set the [`tidb_constraint_check_in_place_pessimistic`](/system-variables.md#tidb_constraint_check_in_place_pessimistic-new-in-v630) variable to `OFF`, which allows TiDB to defer the unique constraint check of a unique index (to the next time when this index requires a lock or to the time when the transaction is committed) and skip the corresponding pessimistic lock. When using this variable, pay attention to the following:
@@ -215,7 +215,7 @@ To achieve better performance of pessimistic transactions, you can set the [`tid
```
```
- ERROR 1062 (23000): Duplicate entry 'bill' for key 'username'
+ ERROR 1062 (23000): Duplicate entry 'bill' for key 'users.username'
```
- When this variable is disabled, committing a pessimistic transaction that needs to write data might return a `Write conflict` error. When this error occurs, TiDB rolls back the current transaction.
@@ -267,9 +267,11 @@ To achieve better performance of pessimistic transactions, you can set the [`tid
```
```
- ERROR 8147 (23000): transaction aborted because lazy uniqueness check is enabled and an error occurred: [kv:1062]Duplicate entry 'bill' for key 'username'
+ ERROR 8147 (23000): transaction aborted because lazy uniqueness check is enabled and an error occurred: [kv:1062]Duplicate entry 'bill' for key 'users.username'
```
+- When this variable is disabled, the `1062 Duplicate entry` error might be not from the current SQL statement. Therefore, when a transaction operates on multiple tables that have indexes with the same name, you need to check the `1062` error message to find which index the error is actually from.
+
## PRIMARY KEY
Like MySQL, primary key constraints contain unique constraints, that is, creating a primary key constraint is equivalent to having a unique constraint. In addition, other primary key constraints of TiDB are also similar to those of MySQL.
diff --git a/log-redaction.md b/log-redaction.md
index dcd33c11f9ddb..04c8ff7965de9 100644
--- a/log-redaction.md
+++ b/log-redaction.md
@@ -26,13 +26,13 @@ create table t (a int, unique key (a));
Query OK, 0 rows affected (0.00 sec)
insert into t values (1),(1);
-ERROR 1062 (23000): Duplicate entry '1' for key 'a'
+ERROR 1062 (23000): Duplicate entry '1' for key 't.a'
```
The error log for the `INSERT` statement above is printed as follows:
```
-[2020/10/20 11:45:49.539 +08:00] [INFO] [conn.go:800] ["command dispatched failed"] [conn=5] [connInfo="id:5, addr:127.0.0.1:57222 status:10, collation:utf8_general_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="insert into t values ( ? ) , ( ? )"] [txn_mode=OPTIMISTIC] [err="[kv:1062]Duplicate entry '?' for key 'a'"]
+[2020/10/20 11:45:49.539 +08:00] [INFO] [conn.go:800] ["command dispatched failed"] [conn=5] [connInfo="id:5, addr:127.0.0.1:57222 status:10, collation:utf8_general_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="insert into t values ( ? ) , ( ? )"] [txn_mode=OPTIMISTIC] [err="[kv:1062]Duplicate entry '?' for key 't.a'"]
```
From the error log above, you can see that all sensitive information is shielded using `?` after `tidb_redact_log` is enabled. In this way, data security risks are avoided.
diff --git a/system-variables.md b/system-variables.md
index 36499ad9a424e..dd7784ec8c400 100644
--- a/system-variables.md
+++ b/system-variables.md
@@ -901,7 +901,7 @@ MPP is a distributed computing framework provided by the TiFlash engine, which a
tidb> insert into t values (1);
Query OK, 1 row affected
tidb> commit; -- Check only when a transaction is committed.
- ERROR 1062 : Duplicate entry '1' for key 'PRIMARY'
+ ERROR 1062 : Duplicate entry '1' for key 't.PRIMARY'
```
- When setting `tidb_constraint_check_in_place` to `ON` and using optimistic transactions:
@@ -910,7 +910,7 @@ MPP is a distributed computing framework provided by the TiFlash engine, which a
tidb> set @@tidb_constraint_check_in_place=ON;
tidb> begin optimistic;
tidb> insert into t values (1);
- ERROR 1062 : Duplicate entry '1' for key 'PRIMARY'
+ ERROR 1062 : Duplicate entry '1' for key 't.PRIMARY'
```
### `tidb_constraint_check_in_place_pessimistic` New in v6.3.0
@@ -945,7 +945,7 @@ MPP is a distributed computing framework provided by the TiFlash engine, which a
```
```
- ERROR 1062 : Duplicate entry '1' for key 'PRIMARY'
+ ERROR 1062 : Duplicate entry '1' for key 't.PRIMARY'
```
- When setting `tidb_constraint_check_in_place_pessimistic` to `ON` and using pessimistic transactions:
@@ -957,7 +957,7 @@ MPP is a distributed computing framework provided by the TiFlash engine, which a
```
```
- ERROR 1062 : Duplicate entry '1' for key 'PRIMARY'
+ ERROR 1062 : Duplicate entry '1' for key 't.PRIMARY'
```
### tidb_cost_model_version New in v6.2.0
diff --git a/transaction-overview.md b/transaction-overview.md
index 257c075722727..3f5860cc0e80b 100644
--- a/transaction-overview.md
+++ b/transaction-overview.md
@@ -221,7 +221,7 @@ mysql> INSERT INTO t1 VALUES (2);
Query OK, 1 row affected (0.00 sec)
mysql> COMMIT; -- It is successfully committed in MySQL; TiDB returns an error and the transaction rolls back.
-ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
+ERROR 1062 (23000): Duplicate entry '1' for key 't1.PRIMARY'
mysql> SELECT * FROM t1; -- MySQL returns 1 2; TiDB returns 1.
+----+
| id |
@@ -268,7 +268,7 @@ Query OK, 1 row affected (0.02 sec)
mysql> INSERT INTO tset VALUES (2); -- Statement does not take effect because "test" is misspelled as "tset".
ERROR 1146 (42S02): Table 'test.tset' doesn't exist
mysql> INSERT INTO test VALUES (1),(2); -- Entire statement does not take effect because it violates a PRIMARY KEY constraint
-ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
+ERROR 1062 (23000): Duplicate entry '1' for key 'test.PRIMARY'
mysql> INSERT INTO test VALUES (3);
Query OK, 1 row affected (0.00 sec)