PDA

View Full Version : Reset indexes?


iceflyin
11-15-2007, 03:03 PM
How do I reset the indexes on a table?

Because... I assume that with index skips, eg... 4-5-7-8-12... Where stuff got deleted. This code here might become inefficient?


$gotConf = false;
while ($gotConf == false){
$confData = mysql_query("SELECT * FROM confession WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM confession) AND active=1 ORDER BY id LIMIT 1;", $conn) or die ('Confession select failed');
$confInfo = mysql_fetch_array($confData);
if (isset($confInfo[text]{2})){
$gotConf= true;
}
}

Fumigator
11-15-2007, 07:34 PM
When you say "reset index", do you mean re-sequence the primary key? In other words, the actual data changes? Because that's not necessary in a well designed schema.

GJay
11-16-2007, 01:19 AM
As fumigator said, re-sequencing isn't a good idea.

Your query can be replaced with something like:

SELECT * FROM confession ORDER BY RAND() LIMIT 1;