View Single Post

   
  #4 (permalink)  
Old 02-28-2008, 10:25 AM
Luuk
 
Posts: n/a
Default Re: how to optimize the dbase


"Mark" <mccartney@emiggeas.it> schreef in bericht
news:46bb611e$0$37205$4fafbaef@reader3.news.tin.it ...
>> Peter H. Coffin ha scritto:
>>> On Thu, 09 Aug 2007 19:56:00 +0200, Mark wrote:
>>>> Hi
>>>> on my website home page there's an heavy and repetitive number of query
>>>> that slow down the speed of the page opening.
>>>> Could you suggest me some link or 'how to' to optimize the queries or
>>>> to improve the page loading time?
>>>
>>> More RAM, better indexing, prebuilding "dynamic" pages that are actually
>>> semi-static. That's roughly in order of simplicity, though the last is
>>> actually fiendishly powerful done right.
>>>

>>

>
> For example whith these queries:
>
> $qtot="SELECT COUNT(id) FROM news WHERE argomento='alfa' AND mostra='si'";
> $qtotb=mysql_query($qtot) or die('errore'.mysql_error());
> $indc=mysql_fetch_array($qtotb);
> mysql_free_result($qtotb);
>
> $qtot="SELECT COUNT(id) FROM news WHERE argomento='beta' AND mostra='si'";
> $qtotb=mysql_query($qtot) or die('errore');
> $indd=mysql_fetch_array($qtotb);
> mysql_free_result($qtotb);
>
> $qtot="SELECT COUNT(id) FROM news WHERE argomento='gamma' AND
> mostra='si'";
> $qtotb=mysql_query($qtot) or die('errore');
> $inde=mysql_fetch_array($qtotb);
> mysql_free_result($qtotb);
>
> $qtot="SELECT COUNT(id) FROM news WHERE argomento='delta' AND
> mostra='si'";
> $qtotb=mysql_query($qtot) or die('errore');
> $indf=mysql_fetch_array($qtotb);
> mysql_free_result($qtotb);
>
> $qtot="SELECT COUNT(id) FROM news WHERE argomento='eta' AND mostra='si'";
> $qtotb=mysql_query($qtot) or die('errore');
> $indg=mysql_fetch_array($qtotb);
> mysql_free_result($qtotb);
>
> $qtot="SELECT COUNT(id) FROM news WHERE argomento='teta' AND mostra='si'";
> $qtotb=mysql_query($qtot) or die('errore');
> $indh=mysql_fetch_array($qtotb);
> mysql_free_result($qtotb);
>
> is there a way to optimize or unite them in a single faster query?
> I'm a beginner with MySQL so please have patience.
>
> Regards
>
> Mark


you could add an INDEX on 'argomento' and/or on 'mostra'.....




Reply With Quote