MySQL Forums
Forum List  »  General

Re: count distinct optimization + Specified key was too long error
Posted by: Rick James
Date: May 30, 2014 11:18AM

> "Specified key was too long; max key length is 1000 bytes"

On the one hand, you are hitting a 'hard limit'. On the other hand, it is telling you "you are doing something wrong".

To make the query run faster, you would need
CREATE INDEX i on tbl ( a,b,c,d,e, col)
but that is even bigger, not not possible.

"Prefix" indexing won't help, since it needs the entire values of a,b,c,d,e.

Are they VARCHAR(255)? Do you _really_ need 255? Do a few SELECT MAX(LENGTH(a)) queries to see how long the columns really are. Perhaps ALTERing the TABLE to MODIFY COLUMN would make your technique work better.

Show us
SHOW TABLE STATUS LIKE 'tbl';
SHOW CREATE TABLE tbl;
EXPLAIN SELECT ...
There may be other workarounds. Some possibilities: PRIMARY KEY, order of fields, ENGINE being used, datatypes, summary tables, etc.

Options: ReplyQuote


Subject
Written By
Posted
Re: count distinct optimization + Specified key was too long error
May 30, 2014 11:18AM


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.