-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong AUTO_INCREMENT value in SHOW CREATE TABLE output #32077
Comments
It looks like a Creating a table with
So 1..5 are allocated and the
We tried to change the Now we use force to set the
Now it works in the way we expect. I think that with #32078 this would be much easier to understand for users. Maybe we also need to extend pingcap/docs#7502 to explain this a bit better. |
I'm not sure this is a bug or something that is not documented well enough. If I understand the implementation correctly, then the PD has each tables next AUTO_INCREMENT number, but each TiDB node that has updated/inserted (possibly used) the table also has a cache of (AUTO_ID_CACHE ids, default 30000). Since when the first AUTO_INCREMENT is needed TiDB will request a set of AUTO_ID_CACHE numbers from PD or when assigning that column to a given value, it will request AUTO_ID_CACHE numbers starting from max(, ). So the more TiDB nodes there are, the more cached numbers there will be. Also when a TiDB node stops/restart, it will not hand back the cached AUTO_INCREMENT values. Setting AUTO_ID_CACHE to 1 should work more similar to MySQL, but would create much more overhead in TiDB/PD, due to the TiDB nodes always need to get a new AUTO_INCREMENT from PD for each row. My opinion is that this is an issue of documentation (and being more clear about the case in @dveeden What is the expected AUTO_INCREMENT value in |
@mjonss I am also not sure that there is a bug here. However due to the caching it behaves differently than MySQL/InnoDB. So it could just be that the documentation isn't clear enough about this. It also looks that when setting the It would also be good to add docs to https://pingcap.github.io/tidb-dev-guide/ about the inner workings of |
I agree with @mjonss ; it's somewhat ambiguous because of how the cache works, and not strictly a bug. We encounter many test-cases where the output between MySQL and TiDB is the auto increment behavior. I expect that it is not just tests, and some users will be affected. I created pingcap/docs#6911 to address the most common issue and filed pingcap/docs#7515 to mention another common problem. But we can document this aspect better too, since there is already a section of the docs which talks about the cache. |
Now we have MySQL compatible AUTO_INCREMENT #38442 |
Bug Report
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
I would expect the
AUTO_INCREMENT
in theSHOW CREATE TABLE...
output to go from 321 to 322, etc.3. What did you see instead (Required)
AUTO_INCREMENT=30321
4. What is your TiDB version? (Required)
The text was updated successfully, but these errors were encountered: