在这种情况下,您将如何优化 MySQL 性能?
$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;
}
这 3 个查询检索具有不同结构的多行, 3次查询需要3次往返, 10 个查询将需要 10 个往返。
您将如何优化这个案例?
$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.
How will you optimize this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
选择您实际需要的列而不是 select *
除此之外,在不知道您需要什么数据以及它们如何关联的情况下,没什么好说的。
Select the columns you actually need instead of select *
Other than that, not much to say without knowing what data you need and how they relate.
你可以尝试 UNION:
请原谅我的 php,这不是我的专业领域:)
You could try a UNION:
pardon my php, it's not my area of expertise :)