我想用SQL_CALC_FOUND_ROWS和MYSQLI來計算我的表上的訪問者,但它很慢。它超過15秒。我能做些什麼使它更快? 我不得不提到我的表是MyISAM,總共有超過200萬行。MYSQLI行計算太慢
if ($result = $mysqli->query("SELECT SQL_CALC_FOUND_ROWS * FROM visitors_table WHERE visitor_affiliate= 'first user'")) {
/* determine number of rows result set */
$row_cnt = $result->num_rows;
printf("Result set has %d rows.\n", $row_cnt);
/* close result set */
$result->close();
}
if ($result2 = $mysqli->query("SELECT SQL_CALC_FOUND_ROWS * FROM visitors_table WHERE visitor_affiliate= 'seconduser'")) {
/* determine number of rows result set */
$row_cnt2 = $result2->num_rows;
printf("Result set has %d rows.\n", $row_cnt2);
/* close result set */
$result2->close();
}
if ($result3 = $mysqli->query("SELECT SQL_CALC_FOUND_ROWS * FROM visitors_table WHERE visitor_affiliate= 'thirduser'")) {
/* determine number of rows result set */
$row_cnt3 = $result3->num_rows;
printf("Result set has %d rows.\n", $row_cnt3);
/* close result set */
$result2->close();
}
任何幫助表示讚賞.. 提前感謝!
@anantkumarsingh SQL_CALC_FOUND_ROWS不是列 – jason88
哎呀! MyISAM和2M行很痛苦。你的'visitors_table'列是某種索引嗎? – Machavity
@anantkumarsingh這是一個[MySQL函數](https://dev.mysql.com/doc/refman/5.5/en/information-functions.html#function_found-rows) – Machavity