MySQL Forums
Forum List  »  Optimizer & Parser

Bad performance caused by DISTINCT?
Posted by: Heist TheAlmighty
Date: November 13, 2006 02:02PM

This is the query:
SELECT DAY(date_time) "day", COUNT( DISTINCT session_id ) "count"
FROM application_requests
WHERE (retailer_id = '111111-1111-11111')
AND(year_for_reports = 2006)
AND(month_for_reports = 9)
GROUP BY DAY( date_time );

EXPLAIN returns this:
"1" | "SIMPLE" | "application_requests" | "ref" | "index_for_reports" | "index_for_reports" | "53" | "const,const,const" | "998840" | "Using where; Using filesort"

index_for_reports is (retailer_id, year_for_reports, month_for_reports)

Table structure goes as follow:
id(int)
retailer_id(varchar[40])
date_time(datetime)
session_id(varchar[255])
controller(varchar[255])
action(varchar[255])
parameters(text)
product_line_id(int)
merchandise_id(int)
month_for_reports(int)
year_for_reports(int)

Any idea how I could make this faster? Right now I'm clocking at 555703 ms, which is intolerable.

Options: ReplyQuote


Subject
Views
Written By
Posted
Bad performance caused by DISTINCT?
8503
November 13, 2006 02:02PM
4352
November 19, 2006 09:29PM
3392
December 13, 2006 04:46AM


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.