I have another follow-up from this question. Although the LIKE
pattern search (because of the collation set) uses the index and is much faster than LIKE BINARY
, doing an explain over both of the queries seems to say that both queries use the index.
explain select count(*) from TransactionApp_transactions where merchantId like 'VCARD000%'
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------------------------+-------+--------------------------------------+--------------------------------------+---------+------+----------+--------------------------+
| 1 | SIMPLE | TransactionApp_transactions | range | TransactionApp_transactions_fc3e7169 | TransactionApp_transactions_fc3e7169 | 767 | NULL | 12906834 | Using where; Using index |
And I get the exact same EXPLAIN
output for explain select count(*) from TransactionApp_transactions where merchantId like binary 'VCARD000%';
(with the rows
being a slightly smaller number)
The key
column contains the index name for both EXPLAIN
outputs, but the LIKE BINARY
takes 26 seconds, compared to just 2 seconds for the simple LIKE
.