• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Why do IDs of deleted nodes remain in the database?

Luxus

Well-known member
#1
Each node has a unique ID assigned to it, but if I delete a node I expect the node ID to be deleted too, but it's not. For example if you have 10 nodes and delete all of them, then create another node, this node will get the node ID of 11.

Any reason for this?
 

Chris D

XenForo developer
Staff member
#2
This is just how MySQL works.

The node ID is an auto increment value. The index of these values remain, even after its associated record is removed.

I believe the only way to resolve this is to somehow remove the index.

I believe truncating a table will do this (as well as removing all the data from it) so not really useful.
 

Chris D

XenForo developer
Staff member
#4
Yeah basically.

MySQL docs describes the AUTO_INCREMENT attribute as "a unique identity for new rows".

So for it to remain unique it mustn't be reused.
 
S

Syndol

Guest
#6
If you are absolutely sure that your last node ID was not referenced anywhere, you could reset the auto increment thus:
ALTER TABLE xf_node AUTO_INCREMENT = X;
Where X will be the ID of the next node you insert.
 

HWS

Well-known member
#7
If you are absolutely sure that your last node ID was not referenced anywhere, you could reset the auto increment thus:
ALTER TABLE xf_node AUTO_INCREMENT = X;
Where X will be the ID of the next node you insert.
IF you do that you will wonder why so many threads appear in your brand new forum node after you set it up. :D