List:General Discussion« Previous MessageNext Message »
From:Eugene Kosov Date:June 21 2006 9:44pm
Subject:Re: query slow
View as plain text  
luiz Rafael wrote:
> SELECT  * FROM  `sav00_sava0400_dbf`   WHERE 2000 = YEAR(`emissao`) OR 
> (1999 = YEAR(`emissao`) AND 12 < MONTH(`emissao`))  ORDER BY emissao ASC
Are you sure this is what you really want? MONTH() is never greater than 
12, so your query is equal to:
    SELECT  * FROM  `sav00_sava0400_dbf`   WHERE 2000 = YEAR(`emissao`) 
ORDER BY emissao

In order to make your query work faster you should create an index on 
`emissao` and rewrite it using date ranges.
So you query will become something like this (if you actually meant 
December'99 and whole year 2000):
  SELECT * FROM `sav00_sava0400_dbf` WHERE `emissao` BETWEEN '1999-12-01 
00:00:00' AND '2000-12-31 23:59:59';

--
BR,
Eugene Kosov
Thread
Just need script for creating tablesXiaobo Chen21 Jun
  • Re: Just need script for creating tablesDaniel da Veiga21 Jun
  • RE: Just need script for creating tablesPeter Lauri21 Jun
    • query slowluiz Rafael21 Jun
      • Re: query slowJay Pipes21 Jun
        • Re: query slowEugene Kosov21 Jun
      • Re: query slowEugene Kosov21 Jun
    • Re: query slowluiz Rafael21 Jun
    • reclaim disk spaceluiz Rafael21 Jun
      • Re: reclaim disk spaceDan Buettner21 Jun
      • Re: reclaim disk spaceDan Nelson21 Jun
    • Re: query slowluiz Rafael25 Jun
  • Re: Just need script for creating tablesMartin Jespersen21 Jun
RE: reclaim disk spaceGeorge Law21 Jun