English 中文(简体)
你们将做些什么来优化我的SQL在这一案例中的业绩?
原标题:What will you do to optimize MySQL performance in this case?
  • 时间:2009-09-21 17:08:48
  •  标签:
$query = "select * from a ...";
if($result = mysql_query($query,$con))
{while($row = mysql_fetch_array($result);)
        $arr[0][] = $row;
}
$query = "select * from b ...";
if($result = mysql_query($query,$con))
{
    while($row = mysql_fetch_array($result);)
        $arr[1][] = $row;
}
$query = "select * from c ...";
if($result = mysql_query($query,$con))
{
    while($row = mysql_fetch_array($result);)
        $arr[2][] = $row;
}

The 3 queries retrieves multiple rows with different structure, 3 queries need 3 round-trip, 10 queries will need 10 round-trip.

你们将如何优化这一案件?

问题回答

选择实际需要的栏目,而不是选择

除此以外,在不了解你需要什么数据以及它们如何关联的情况下,说的话也不少。

你可以尝试一个联合国构想:

$query = "SELECT  a  AS tablename, a.* FROM a
UNION
SELECT  b  AS tablename, b.* FROM b
UNION
SELECT  c  AS tablename, c.* FROM c";
if($result = mysql_query($query,$con))
{while($row = mysql_fetch_array($result);)

switch ($row[ tablename ]) {
    case "a":
        $arr[0][] = $row;
        break;
    case "b":
$arr[1][] = $row;
        break;
    case "c":
        $arr[2][] = $row;
        break;
}
}

我的特赦,不是我的专长领域:





相关问题
热门标签