我想知道,哪些代碼在thory需要更長的時間:時間複雜度從MySQL數據庫中讀取
1.
$query = "SELECT Something1, Something2 FROM base WHERE SomeCondition";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
//We do something with $row[0] and row[1]
}
2.
$query = "SELECT Something1 FROM base WHERE SomeCondition";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
//We do something with $row[0]
}
$query = "SELECT Something2 FROM base WHERE SomeCondition";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
//We do something with $row[0]
}
現在1.應更快,因爲雖然統計以O(n)時間執行,而另一個以O(2 * n)執行,但是第一個必須一次查詢兩列,而在2中必須查詢一列列,但兩次。現在我想知道一次一列或兩列一次性的mysql_query和mysql_fetch_array性能如何?
查看詳情感謝您的解釋! – 2010-12-10 19:05:29