From 766d5a61234303887a4b0833027c030053389305 Mon Sep 17 00:00:00 2001 From: Airton Lastori Date: Mon, 31 Mar 2025 12:39:22 -0400 Subject: [PATCH 1/5] Update bot.yaml - prevent bot workflow from running on fork Add repository check condition to bot.yaml to ensure PR reminder workflow only runs on the original pingcap/docs repository. This prevents workflow failures on forks due to missing webhook secrets. --- .github/workflows/bot.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/bot.yaml b/.github/workflows/bot.yaml index a2bad7c629706..0b929d26f8fd4 100644 --- a/.github/workflows/bot.yaml +++ b/.github/workflows/bot.yaml @@ -6,6 +6,7 @@ on: - cron: "30 1 * * 1-5" jobs: + if: github.repository == 'pingcap/docs' pr_reminder: runs-on: ubuntu-latest steps: From 2fbabd1fd60a66cdfd475662318e3bf4ddbb81c8 Mon Sep 17 00:00:00 2001 From: Airton Lastori Date: Mon, 31 Mar 2025 12:41:17 -0400 Subject: [PATCH 2/5] Update link.yaml - prevent workflow from running on fork Add repository check condition to link.yaml to ensure PR reminder workflow only runs on the original pingcap/docs repository. This prevents workflow failures on forks due to missing webhook secrets. --- .github/workflows/link.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/link.yaml b/.github/workflows/link.yaml index 5a31c2df21dbd..80722fc6e58f2 100644 --- a/.github/workflows/link.yaml +++ b/.github/workflows/link.yaml @@ -7,6 +7,7 @@ on: - cron: "0 0 * * 1" jobs: + if: github.repository == 'pingcap/docs' linkChecker: runs-on: ubuntu-latest steps: From 1e664699c23b29906d3b2eac83759ed06d70b8c2 Mon Sep 17 00:00:00 2001 From: Airton Lastori Date: Mon, 31 Mar 2025 12:56:27 -0400 Subject: [PATCH 3/5] Update link.yaml --- .github/workflows/link.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/link.yaml b/.github/workflows/link.yaml index 80722fc6e58f2..692b0e794f041 100644 --- a/.github/workflows/link.yaml +++ b/.github/workflows/link.yaml @@ -7,8 +7,8 @@ on: - cron: "0 0 * * 1" jobs: - if: github.repository == 'pingcap/docs' linkChecker: + if: github.repository == 'pingcap/docs' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From 8d296181c97b7f298580669ebd4b2218a8a949e6 Mon Sep 17 00:00:00 2001 From: Airton Lastori Date: Mon, 31 Mar 2025 12:56:40 -0400 Subject: [PATCH 4/5] Update bot.yaml --- .github/workflows/bot.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bot.yaml b/.github/workflows/bot.yaml index 0b929d26f8fd4..3305df45eaae7 100644 --- a/.github/workflows/bot.yaml +++ b/.github/workflows/bot.yaml @@ -6,8 +6,8 @@ on: - cron: "30 1 * * 1-5" jobs: - if: github.repository == 'pingcap/docs' pr_reminder: + if: github.repository == 'pingcap/docs' runs-on: ubuntu-latest steps: - name: Run PR reminder From 99af287b700314345ffbbd927683462ba9a104a0 Mon Sep 17 00:00:00 2001 From: Airton Lastori Date: Thu, 10 Apr 2025 00:13:09 -0400 Subject: [PATCH 5/5] docs: clarify AUTO_RANDOM_BASE usage and explicit insert behavior (#20732) --- auto-random.md | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/auto-random.md b/auto-random.md index 041e9974c9ae1..683b8af122201 100644 --- a/auto-random.md +++ b/auto-random.md @@ -166,31 +166,32 @@ TiDB implicitly allocates values to `AUTO_RANDOM` columns similarly to `AUTO_INC ## Clear the auto-increment ID cache -Explicitly inserting data into an `AUTO_RANDOM` column behaves the same as with an `AUTO_INCREMENT` column, so you also need to clear the auto-increment ID cache. For more details, see [Clear the auto-increment ID cache](/auto-increment.md#clear-the-auto-increment-id-cache). +When you insert data with explicit values into an `AUTO_RANDOM` column, it works similarly to an `AUTO_INCREMENT` column regarding potential ID collisions. If you insert many explicit values, you might accidentally use an ID value that TiDB would have generated automatically later, which can lead to errors. -You can run the `ALTER TABLE` statement to set `AUTO_RANDOM_BASE=0` to clear the auto-increment ID cache on all TiDB nodes in the cluster. For example: +Here's how the collision can happen: each `AUTO_RANDOM` ID contains an auto-incrementing part alongside random bits. TiDB uses an internal counter for this auto-incrementing part. If you explicitly insert an ID where this part matches the counter's next value, TiDB might later try to generate the same ID automatically, leading to a duplicate key error. -```sql -ALTER TABLE t AUTO_RANDOM_BASE=0; -``` +Although `AUTO_RANDOM` doesn't keep track of a single specific "next ID" like `AUTO_INCREMENT` does, inserting many explicit values might still require you to adjust the starting point (`AUTO_RANDOM_BASE`) for the auto-incrementing part of future automatically generated IDs to avoid these potential errors. -``` -Query OK, 0 rows affected, 1 warning (0.52 sec) -``` +To change the base value (`AUTO_RANDOM_BASE`) used for the auto-increment part of future ID generations on an existing table, you must use the `FORCE` keyword. + +> **Note:** +> +> * If you try to alter `AUTO_RANDOM_BASE` without the `FORCE` keyword, the value will not change. You will only see a warning message like `Can't reset AUTO_INCREMENT to 0 without FORCE option, using XXX instead`, but the base value stays unchanged. +> * You cannot set `AUTO_RANDOM_BASE` to `0`, even with the `FORCE` keyword. If you try this (`ALTER TABLE t FORCE AUTO_RANDOM_BASE=0;`), you will get an error. +> * You must use a non-zero positive integer value when using `FORCE`. + +To set a new base value (for example, `1000`) for the auto-increment part of future implicitly generated IDs for table `t`, use the following statement: ```sql -SHOW WARNINGS; +ALTER TABLE t FORCE AUTO_RANDOM_BASE = 1000; ``` ``` -+---------+------+-------------------------------------------------------------------------+ -| Level | Code | Message | -+---------+------+-------------------------------------------------------------------------+ -| Warning | 1105 | Can't reset AUTO_INCREMENT to 0 without FORCE option, using 101 instead | -+---------+------+-------------------------------------------------------------------------+ -1 row in set (0.00 sec) +Query OK, 0 rows affected (0.XX sec) ``` +This command modifies the starting point for the auto-increment bits used in subsequent `AUTO_RANDOM` value generations across all TiDB nodes. It does not affect already allocated IDs. + ## Restrictions Pay attention to the following restrictions when you use `AUTO_RANDOM`: