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
3938
January 04, 2007 07:38AM
2368
January 04, 2007 10:21AM
2319
January 04, 2007 11:51AM
2440
January 04, 2007 03:34PM
2442
January 05, 2007 02:40AM
Re: Make this faster?
2353
January 05, 2007 05:07AM
2342
January 05, 2007 06:55AM
2370
January 05, 2007 08:31AM
2362
January 05, 2007 08:33AM
2600
January 05, 2007 08:45AM
2347
January 05, 2007 08:31AM
2433
January 05, 2007 08:45AM
2457
January 05, 2007 03:11PM
2384
January 08, 2007 02:44AM
2286
January 08, 2007 04:28AM
2370
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.