我有几个非常小的SQL查询需要花费太多时间才能运行。
if ($USER) {
$ss_a = mysql_fetch_array(mysql_query("SELECT uri FROM styles WHERE id=".$USER["styles"]));
if ($ss_a) {
$ss_uri = $ss_a["uri"];
}
}
所以需要0.7605552s“SELECT uri FROM styles WHERE id = 1”
第二个样式代码
if (!$ss_uri) {
($r = mysql_query("SELECT uri FROM styles WHERE id=1")) or die(mysql_error());
其他需要花费太多时间的小问题。
0.5507469 SELECT COUNT(id)AS问题FROM helpdesk WHERE solve ='no'
代码:
$res = mysql_query("SELECT COUNT(id) AS problems FROM helpdesk WHERE solved = 'no'");
$arr = mysql_fetch_assoc($res);
$problems = $arr['problems'];
有没有办法优化这些或什么?
答案 0 :(得分:0)
索引可能有所帮助。我建议尝试:
create index idx_styles_id_uri on style(id, uri)
create index idx_helpdesk_solved_id on helpdesk(solved, id)