Jump to content

[SOLVED] Filling in row gaps while autoincremented


lordvader

Recommended Posts

My primary key is unique id numbers, but because of the nature of my php scripts, they get inserted out of order. I assume that this slows down queries, since the engine has to search the entire db to find a specific primary key. But if it was autoincremented, it would know exactly where to look... Right?

 

But my problem is that not every sequential number gets used... there's lots of gaps because the script will not re-use id numbers that belong to the data entries that get deleted before making it into the db.

 

So if I have lets say, 10 entries in the db, # 1-10, and then I need to add a new row at the end of the table whose id is 15... will mysql with autoincrementing turned on, create rows #11-14? Or do I have to do it myself?

 

If i have to do it myself, do I do a select on rows 11-14, to see if they exist yet? Or is there something more efficient?

thanks

But my problem is that not every sequential number gets used... there's lots of gaps because the script will not re-use id numbers that belong to the data entries that get deleted before making it into the db.

It's never supposed to re-use UIDs... and it never should... and neither should you.

 

You shouldn't be using these values for anything meaningful in your application -- if you are, you've made a mistake.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.