mysql> EXPLAIN SELECT col1, col2 FROM t WHERE col1 REGEXP '^foobar_[0-9]{4}$';
+----+-------------+---------------+------+---------------+------+---------+------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------------+------+---------------+------+---------+------+--------+-------------+
| 1 | SIMPLE | t | ALL | NULL | NULL | NULL | NULL | 757000 | Using where |
+----+-------------+---------------+------+---------------+------+---------+------+--------+-------------+
1 row in set (0.15 sec)
mysql> DESCRIBE t;
+------------------------+------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+------------------------+------+-----+---------+-------+
| col2 | varchar(255) | NO | MUL | {} | |
| col1 | varbinary(255) | NO | PRI | | |
+------------------------+------------------------+------+-----+---------+-------+
2 rows in set (0.22 sec)
mysql> EXPLAIN SELECT col1, col2 FROM t WHERE col1 REGEXP ‘^foobar_[0-9]{4}$’; +—-+————-+—————+——+—————+——+———+——+——–+————-+ | id
Share
if you have a index on col1, and add a
LIKElike this:you should get abit more speed.
you can also make an index of (col1, col2) to make mysql store a copy of that table in memeory