Re: Make this faster?
You should have created a single index covering (year, month), not one index for each column ;) That should then get rid of the "Using filesort" as well. If that still isn't fast enough, extending the index to cover (year, month, md5_key) might help a bit, as it will allows MySQL to simply do an index scan instead of a table scan.
The second COUNT() should not use DISTINCT I think, but that depends on the result you expect...
Let's take a glance at a imaginary set of results of:
SELECT YEAR(files.date), files.md5_key, filesystem.md5_key FROM files LEFT JOIN filesystem ON files.md5_key = filesystem.md5_key
2005 1 NULL
2005 2 2
2005 2 2
2005 2 2
2005 3 3
The number of files for 2005 is:
COUNT(DISTINCT files.md5_key) == 3 ... Duplicates are ignored
Without DISTINCT it would result in:
COUNT(files.md5_key) == 5 ... No sure how to express what this value means ;)
The number of filesystem entries for those files is:
COUNT(filesystem.md5_key) == 4
The number of files that have a filesystem entry is:
COUNT(DISTINCT filesystem.md5_key) == 2
So choose those that match the expected result :)
Subject
Views
Written By
Posted
3820
January 04, 2007 07:38AM
2297
January 04, 2007 10:21AM
2253
January 04, 2007 11:51AM
2354
January 04, 2007 03:34PM
2380
January 05, 2007 02:40AM
Re: Make this faster?
2288
January 05, 2007 05:07AM
2281
January 05, 2007 06:55AM
2312
January 05, 2007 08:31AM
2303
January 05, 2007 08:33AM
2525
January 05, 2007 08:45AM
2269
January 05, 2007 08:31AM
2348
January 05, 2007 08:45AM
2387
January 05, 2007 03:11PM
2323
January 08, 2007 02:44AM
2225
January 08, 2007 04:28AM
2311
January 08, 2007 04:41AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.