I'm trying to run the below query and it's taking hours and hours. We've got a dedicated server for the queries (not running on localhost).
It's an InnoDB table with around 74 million rows. I've indexed the two columns involved in the grouping (TRAN_URN, UCI) in a hope to speed up the query.
insert into data.urn_uci_lookup (TRAN_URN, UCI, `Count`)
select TRAN_URN,UCI, count(*) as `Count`
from data.diablo18
group by TRAN_URN, UCI
Is this inefficient for some reason? How can I improve it?
EDIT: Here is the EXPLAIN plan
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE diablo18 ALL \N \N \N \N 74631102 Using temporary; Using filesort
Cheers, Lucas
count(*)
column. If you expect very low (i.e. <3) results for most rows incount(*)
then the query is going to be slow no matter what you do. How many distinct values of(TRAN_URN,UCI)
do you have? – Jim Garrison