MySQL groupby with sum -


i have query group , sum. have close 1 million records. when run query taking 2.5s. if remove group clause taking 0.89s. there way can optimize query using group , sum together.

 select aggei.ei_uuid uuid,aggei.companydm_id companyid,aggei.rating       rating,aggei.ei_name name,  compdm.company_name companyname,sum(aggei.count) activity       agg_externalindividual aggei       join companydm compdm on aggei.companydm_id = compdm.companydm_id       aggei.ei_uuid not null         , aggei.companydm_id in (8)         , aggei.datedm_id = 20130506          , aggei.topicgroupdm_id in (1,2,3,4,5,6,7)         , aggei.rating >= 0         , aggei.rating <= 100  group aggei.ei_uuid,aggei.companydm_id limit 0,200000 

explain result below:

  1 simple  compdm  const   primary,companydm_id_unique,comp_idx    primary 8       const   1   using temporary; using filesort   1 simple  aggei   ref       primary,datedm_id_unique,agg_ei_comdm_fk_idx,agg_ei_datedm_fk_idx,agg_ei_topgrp_fk_idx,uid_comp_ei_dt_idx,uid_comp_dt_idx,comp_idx    datedm_id_unique    4   const   197865  using 

also didn't understand why compdm table executed first. can explain?

i have index on agg_externalindividual table combination of ei_uuid,companydm_id,datedm_id. same shown on aggei table under possible keys uid_comp_dt_idx. aggei table taking datedmid_unique key. didn't understand behavior.

can explain?

explain has run dependent queries before can run main one.

you need check indexing on agg_externalindividual.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -