I have tables which will have millions of records in them. What is the best way to create the unique ID of these tables?
According to MySQL, there is the use of AUTO_INCREMENT, but at a certain number of registers it slows down each time.
In the case of ID generation from PHP I have the following code:
private function crearIdentificacion(){
$min = 1;
$max = 0;
switch(PHP_INT_SIZE) {
case 4:
$max = 2147483648;
break;
case 8:
$max = 9223372036854775807;
break;
default:
break;
}
$diferencia = bcadd(bcsub($min,$max),1);
$rand_percent = bcdiv(mt_rand(), mt_getrandmax(), 8);
return abs(bcadd($min, bcmul($diferencia, $rand_percent, 8), 0));
}
Which creates an ID and its size depends on whether it is 32bit or 64bit, but I am in doubt. Because I know that when a table contains too much information access to it is getting slower.