PDA

View Full Version : Optimizing MySQL Databases...


deadimp
09-05-2004, 02:31 AM
Well, I bet you're about to say "Well, use the OPTIMIZE function."
See, the problem is that the OPTIMIZE function isn't what I'm looking for. In all honesty, I don't even know what the OPTIMIZE function can do, but I know what it can't.
Here's an example of the problem

ID | Bytes | Field | ...
---+-------+-------+
1 | 0001 | ????? | (Ignore the data)
2 | 0010 | ????? |
3 | 0011 | ????? |
5 | 0101 | ????? | <-- Here's the problem
6 | 0110 | ????? |

Well, I think you get the idea. The problem is the gap in between the auto_increment value ID from row 3 to 5. What I'm wanting it do is 'compress' the rows and get rid of that little increment gap, like this:

ID | Bytes | Field | ...
---+-------+-------+
1 | 0001 | ????? |
2 | 0010 | ????? |
3 | 0011 | ????? |
4 | 0101 | ????? | <-- Here's the fixed problem
5 | 0110 | ????? |

So, would anyone know any MySQL or PHP to help this out?

oracleguy
09-05-2004, 05:31 AM
Is there a specific reason you wish to do this? The reason the optimize function doesn't do that because it kind of defeats the purpose of an auto increment field. The field is supposed to be unique and once it assigns a number, not to use it again.

If you changed the numbers it could potentially reek havok with your db if you are using the data relationally, as in linking using those auto increment fields.

deadimp
09-05-2004, 04:17 PM
Well, the reason is that I'm not sure what will happen if the mysql_result() scans over an empty ID field when I select all of the rows.
I guess I don't really need this. Thanks for the reply.

oracleguy
09-05-2004, 08:05 PM
It isn't really empty, it is gone. So there shouldn't be a problem.