I know that varchar_pattern_ops
exists in Postgresql for fast, index-based searches in a LIKE
query, but is there any similar functionality for MySQL?
I currently have a Django-MySQL setup where I have this query which runs on a non-indexed field and with a BINARY LIKE
operation, and it takes over a minute to complete.
My query is a partial search from the beginning of the text - text%
.
This is the table structure. The table actually contains over 20 fields, but I've included just the primary key and the field I'm searching on
+---------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------------+---------------+------+-----+--
| id | varchar(255) | NO | PRI | NULL | |
| mid | varchar(255) | NO | MUL | NULL | |
And this is the query -
select count(*) from table where mid binary like 'text%';
These are the indexes -
PRIMARY KEY index has cardinality 102820460
mid index has cardinality 756032