0

I have couple very small sql queries that takes too much time to run.

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"];
}
}

So it takes 0.7605552s "SELECT uri FROM styles WHERE id=1"

And second style code

if (!$ss_uri) {
($r = mysql_query("SELECT uri FROM styles WHERE id=1")) or die(mysql_error());

Other little queries that takes too much time.

0.5507469 SELECT COUNT(id) AS problems FROM helpdesk WHERE solved = 'no'

Code:

$res = mysql_query("SELECT COUNT(id) AS problems FROM helpdesk WHERE solved = 'no'");

$arr     = mysql_fetch_assoc($res);
$problems = $arr['problems'];

Is there any way to optimizing these or something?

Dotooj
  • 21
  • 3
  • 1
    Is your table big? If yes: how big? Is 'id' an index? If not, why not? :) – Allmighty Oct 27 '14 at 12:07
  • Can you provide more info? Mysql version, OS, tables size. – ste1inbeck Oct 27 '14 at 12:07
  • see [**this**](http://stackoverflow.com/questions/13944956/the-mysql-extension-is-deprecated-and-will-be-removed-in-the-future-use-mysqli).... `mysql_*` is deprecated (officially in php 5.5) – itachi Oct 27 '14 at 12:15

1 Answers1

0

Indexes might help. I would suggest trying:

create index idx_styles_id_uri on style(id, uri)
create index idx_helpdesk_solved_id on helpdesk(solved, id)
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786