When I set a primary key as AUTO INCREMENT, the ordinal number continue increase when I delete a key.
For example, I have a record with id=5 in my table, then I delete it, and when I insert a new record it never re-use id=5 again. I think it wastes a lot resources (please correct me if my thought is wrong). How can I re-use these deleted id number?
It doesn’t waste that many resources, you’d need to delete and insert a lot of rows before you ran out. The INT size in Mysql is ~2 billion rows. If you used unsigned it’s 4 billion.
The problem with re-using the keys is, if you have a table with the first table as a foreign key, and your delete doesn’t cascade you could accidentally link the wrong rows together when joining the tables.