MySQL Forums
Forum List  »  Optimizer & Parser

Make this faster?
Posted by: Levi Tedder
Date: January 04, 2007 07:38AM

Hi

I hope I'm posting in the correct group, forgive me if this isn't so.

I'm having trouble making a search/query go faster, and hope to get some advice here.

I have these two tables (innodb):

CREATE TABLE "files" (
"md5_key" varchar(50) NOT NULL,
"date" datetime NOT NULL default '0000-00-00 00:00:00',
"type1" varchar(128) default NULL,
"type2" varchar(128) default NULL,
"counter" int(11) default NULL,
"filename" varchar(255) NOT NULL,
"text" varchar(255) NOT NULL,
PRIMARY KEY ("md5_key"),
KEY "type1" ("type1"),
KEY "type2" ("type2"),
KEY "date" ("date")
);

CREATE TABLE "filesystem" (
"md5_key" varchar(50) NOT NULL,
"deletes" varchar(255) NOT NULL,
"executes" varchar(255) NOT NULL,
KEY "md5_key" ("md5_key")
);


ALTER TABLE `filesystem`
ADD CONSTRAINT "filesystem_ibfk_1" FOREIGN KEY ("md5_key") REFERENCES "files" ("md5_key") ON DELETE CASCADE;

From this I want to list per month (ascending) total number of records in files and number of matching records in filesystem (unique count would be best but not important) where the column deletes is '1'.

I created this query:

SELECT Year(date), Month(date), Count(files.md5_key), Count(filesystem.md5_key),
CONCAT(monthname(date),' ',YEAR(date))
FROM files LEFT JOIN filesystem ON files.md5_key = filesystem.md5_key
AND deletes = '1'
GROUP BY Year(date), Month(date) order by date asc;

files has about 1 million records, and filesystem about 500k (not all files has filesystem "incidents"). The first time I run this query it takes about 15 seconds (status=copying to tmp table), second time faster since its cached.
Is there anything I can do with my tables or query to make this go faster?

Forgive me if I haven't explained it well enough, if so, just ask.

Thanks for any help/advice
Levi

Options: ReplyQuote


Subject
Views
Written By
Posted
Make this faster?
3819
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
2287
January 05, 2007 05:07AM
2280
January 05, 2007 06:55AM
2312
January 05, 2007 08:31AM
2303
January 05, 2007 08:33AM
2525
January 05, 2007 08:45AM
2268
January 05, 2007 08:31AM
2348
January 05, 2007 08:45AM
2387
January 05, 2007 03:11PM
2322
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.