搜索 SQL BIGINT 的最大值。几年前,当我在 32 位机器上编写这个脚本时,它曾经溢出。现在问题少了很多!
http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html
http://www.laprbass.com/RAY_integer_overflow.php
<?php // RAY_integer_overflow.php
error_reporting(E_ALL);
echo "<pre>\n";
// CONNECTION AND SELECTION VARIABLES FOR THE DATABASE
$db_host = "localhost"; // PROBABLY THIS IS OK
$db_name = "??"; // GET THESE FROM YOUR HOSTING COMPANY
$db_user = "??";
$db_word = "??";
// OPEN A CONNECTION TO THE DATA BASE SERVER
// MAN PAGE: http://us2.php.net/manual/en/function.mysql-connect.php
if (!$dbcx = mysql_connect("$db_host", "$db_user", "$db_word"))
{
$errmsg = mysql_errno() . ' ' . mysql_error();
echo "<br/>NO DB CONNECTION: ";
echo "<br/> $errmsg <br/>";
}
// SELECT THE MYSQL DATA BASE
// MAN PAGE: http://us2.php.net/manual/en/function.mysql-select-db.php
if (!$db_sel = mysql_select_db($db_name, $dbcx))
{
$errmsg = mysql_errno() . ' ' . mysql_error();
echo "<br/>NO DB SELECTION: ";
echo "<br/> $errmsg <br/>";
die('NO DATA BASE');
}
// CREATE A TABLE AND ALTER IT TO A HIGH INDEX NUMBER
$sql = "CREATE TEMPORARY TABLE noise ( id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY ) ENGINE=MEMORY";
if (!$res = mysql_query($sql)) die(mysql_error());
$sql = "ALTER TABLE noise AUTO_INCREMENT = 2147483646";
if (!$res = mysql_query($sql)) die(mysql_error());
// INSERT DATA TO ADD TO THE AUTO_INCREMENT INDEX
$kount = 0;
while ($kount < 15)
{
$sql = "INSERT INTO noise () VALUES ()";
if (!$res = mysql_query($sql)) die(mysql_error());
$nid = mysql_insert_id($dbcx);
var_dump($nid);
$kount++;
}
根据我的粗略计算,如果您以每秒 1,000 条的速度聚合消息,并且您使用 UNSIGNED BIGINT 作为 AUTO_INCREMENT 键,那么您将在大约 570,000,000 年内遇到溢出。因此,或多或少地,如果您以每秒 1,000,000,000 条的速度收集消息,那么您将在更短的时间内遇到问题——也许从现在起大约 570 年。但好消息是,如果你以每秒 100,000 条的速度收集消息,VC 社区就会向你砸钱!