Home » Performance » MySQL » Performance Issue with Group by
Performance Issue with Group by [message #615] Sat, 20 January 2007 22:19 Go to next message
ppanwar  is currently offline ppanwar
Messages: 2
Registered: January 2007
Junior Member
Hi,

We have been working on a links service and currently testing the system with 30,000 records...

This query uses group by to find most vouched links and it is very slow...takes up to 10 sec. We have tried everything to optimize it but no help. The problem is putting order by on the calculated fields as we want to display mostvouched

select sum(vouch_count) as vouch_count,linkvouchcountsortingdisplay.url as turl,linkuserId,linkId,title,linkvouchcountsortingdisplay.ur l as url from linkvouchcountsortingdisplay INNER JOIN sharelinkuser ON linkvouchcountsortingdisplay.url=sharelinkuser.url where vouch_date>=DATE_ADD(CURRENT_DATE,INTERVAL -7 DAY) and vouch_date<=CURRENT_DATE group by url ORDER BY vouch_count DESC

As soon as we put order by it takes a long time. Without order by it works fine......

All the indexes are placed properly and they work with other queries
Re: Performance Issue with Group by [message #629 is a reply to message #615 ] Mon, 22 January 2007 13:33 Go to previous messageGo to next message
inner  is currently offline inner
Messages: 13
Registered: November 2006
Location: Lithuania
Junior Member
Hi, ppanwar

Looks like this query creates a very huge temporary table on a disk. Could you please provide us with an EXPLAIN for this query for both - query with the "ORDER BY" and without it. Also, show index for both tables would help.

Aurimas
Re: Performance Issue with Group by [message #630 is a reply to message #615 ] Mon, 22 January 2007 20:52 Go to previous message
ppanwar  is currently offline ppanwar
Messages: 2
Registered: January 2007
Junior Member
In general i have seen, that group by takes a long time with order by.

What alternatives are there. I don't want to use group by and one of the scenario is similar to mention here For e.g. If there is Table 1 and Table 2

Table 1 has 3 unique URL (for e.g. hotmail.com) and Table 2 has 4 records of (hotmail.com)...The only way to display the combination for a particular URL is to use group by.

If I use inner join from Table 1 to table 2 ON URL, it still shows 4 records of that url, though i only want to show the first one if repeat record occur.

Regarding the query mention..

Explain with both ORDER BY and without is same

It uses index on sharelinkuser but doesn't uses the index on
linkvouchcountsortingdisplay table
Previous Topic:NDB and Character Indexes
Next Topic:Connecting to Mysql with ODBC vs C library
Goto Forum:
  


Current Time: Sun Jul 5 16:49:08 EDT 2009

Total time taken to generate the page: 0.01052 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.