From 50bf2913cbb4882122ffaa8eb0050a564054a2b0 Mon Sep 17 00:00:00 2001 From: ekexium Date: Thu, 20 Oct 2022 11:37:33 +0800 Subject: [PATCH 1/7] complement errors relating to lazy uniqueness check Signed-off-by: ekexium --- character-set-and-collation.md | 4 ++-- constraints.md | 12 +++++++----- log-redaction.md | 4 ++-- system-variables.md | 8 ++++---- transaction-overview.md | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) 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..1491e42ec167d 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 does not necessarily happen in the currently executing SQL statement. Therefore, when a transaction operates on multiple tables that have indexes with the same name, please check the `1062` error message to find which actual index the error is 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) From 75580cc42322d17bde167e7d5fb90436540cc402 Mon Sep 17 00:00:00 2001 From: ekexium Date: Thu, 20 Oct 2022 16:45:07 +0800 Subject: [PATCH 2/7] Update constraints.md --- constraints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constraints.md b/constraints.md index 1491e42ec167d..fed6293d93eb1 100644 --- a/constraints.md +++ b/constraints.md @@ -270,7 +270,7 @@ 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 'users.username' ``` -- When this variable is disabled, the `1062` Duplicate entry error does not necessarily happen in the currently executing SQL statement. Therefore, when a transaction operates on multiple tables that have indexes with the same name, please check the `1062` error message to find which actual index the error is from . +- When this variable is disabled, the `1062 Duplicate entry` error does not necessarily happen in the currently executing SQL statement. Therefore, when a transaction operates on multiple tables that have indexes with the same name, please check the `1062` error message to find which actual index the error is from . ## PRIMARY KEY From 79911a38b09c9462f02b8b2839bc55f3963abf26 Mon Sep 17 00:00:00 2001 From: ekexium Date: Fri, 21 Oct 2022 16:27:21 +0800 Subject: [PATCH 3/7] Update constraints.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniël van Eeden --- constraints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constraints.md b/constraints.md index fed6293d93eb1..f8ba275a94e01 100644 --- a/constraints.md +++ b/constraints.md @@ -270,7 +270,7 @@ 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 'users.username' ``` -- When this variable is disabled, the `1062 Duplicate entry` error does not necessarily happen in the currently executing SQL statement. Therefore, when a transaction operates on multiple tables that have indexes with the same name, please check the `1062` error message to find which actual index the error is from . +- When this variable is disabled, the `1062 Duplicate entry` error does not necessarily happen in the currently executing SQL statement. Therefore, when a transaction operates on multiple tables that have indexes with the same name, please check the `1062` error message to find which actual index the error is from. ## PRIMARY KEY From ba24f33a01abb643687cb7b3775a4a768114a723 Mon Sep 17 00:00:00 2001 From: ekexium Date: Mon, 24 Oct 2022 15:01:07 +0800 Subject: [PATCH 4/7] remove v6.3 related stuff Signed-off-by: ekexium --- constraints.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/constraints.md b/constraints.md index f8ba275a94e01..0f244ed4d3f92 100644 --- a/constraints.md +++ b/constraints.md @@ -270,8 +270,6 @@ 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 'users.username' ``` -- When this variable is disabled, the `1062 Duplicate entry` error does not necessarily happen in the currently executing SQL statement. Therefore, when a transaction operates on multiple tables that have indexes with the same name, please check the `1062` error message to find which actual index the error is 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. From 0c0585016bbafc64ac5fd32ac3c36b5ba2fbf116 Mon Sep 17 00:00:00 2001 From: ekexium Date: Mon, 24 Oct 2022 15:06:27 +0800 Subject: [PATCH 5/7] Revert "remove v6.3 related stuff" This reverts commit ba24f33a01abb643687cb7b3775a4a768114a723. --- constraints.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/constraints.md b/constraints.md index 0f244ed4d3f92..f8ba275a94e01 100644 --- a/constraints.md +++ b/constraints.md @@ -270,6 +270,8 @@ 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 'users.username' ``` +- When this variable is disabled, the `1062 Duplicate entry` error does not necessarily happen in the currently executing SQL statement. Therefore, when a transaction operates on multiple tables that have indexes with the same name, please check the `1062` error message to find which actual index the error is 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. From 39edce242bac77b320b3f98fca2a116296ad189c Mon Sep 17 00:00:00 2001 From: ekexium Date: Wed, 26 Oct 2022 15:30:53 +0800 Subject: [PATCH 6/7] Update constraints.md Co-authored-by: Aolin --- constraints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constraints.md b/constraints.md index f8ba275a94e01..555d5fe78c939 100644 --- a/constraints.md +++ b/constraints.md @@ -270,7 +270,7 @@ 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 'users.username' ``` -- When this variable is disabled, the `1062 Duplicate entry` error does not necessarily happen in the currently executing SQL statement. Therefore, when a transaction operates on multiple tables that have indexes with the same name, please check the `1062` error message to find which actual index the error is from. +- When this variable is disabled, the `1062 Duplicate entry` error does not indicates that it occurs in the current SQL statement. Therefore, when a transaction operates on multiple tables that have indexes with the same name, please check the `1062` error message to find which actual index the error is from. ## PRIMARY KEY From 3f3e76d46d1f89acddd88702f0847608dc2816a0 Mon Sep 17 00:00:00 2001 From: ekexium Date: Wed, 2 Nov 2022 15:40:51 +0800 Subject: [PATCH 7/7] Update constraints.md Co-authored-by: Grace Cai --- constraints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constraints.md b/constraints.md index 555d5fe78c939..165d475096f0c 100644 --- a/constraints.md +++ b/constraints.md @@ -270,7 +270,7 @@ 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 'users.username' ``` -- When this variable is disabled, the `1062 Duplicate entry` error does not indicates that it occurs in the current SQL statement. Therefore, when a transaction operates on multiple tables that have indexes with the same name, please check the `1062` error message to find which actual index the error is from. +- 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