An index on domain cannot be used to satisfy your WHERE clause, because you
are comparing the result of a function performed on domain to a value. As
soon as you feed your column to a function, you lose the use of an index on
that column. So, each and every one of these queries performs a full
First create a table with the "fixed" domain names:
CREATE TABLE FixedDomains
SELECT DISTINCT domain, left( domain, instr( domain, '.'> ) -1 ) as
newdomain
FROM url_cat
Index your new table (for speed):
ALTER FixedDomains ADD INDEX (Domain)
*** NOTE: You really want to review (and modify, if n