O
O
Obivankinobi2019-02-19 13:30:37
MySQL
Obivankinobi, 2019-02-19 13:30:37

Why is LIKE request processed faster than EQUAL?

We have a simple table for ~ 3 million records.

CREATE TABLE `MTRIVI` (
  `id` int(11) NOT NULL,
  `numero` varchar(45) NOT NULL,
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

ALTER TABLE `MTRIVI`
  ADD PRIMARY KEY (`id`),
  ADD KEY `numero` (`numero`);

We create two requests.
1. SELECT * FROM `MTRIVI` WHERE numero =1000410001 LIMIT 0 , 30 ; 12 total, Query took 9.4297 sec
5c6bd9e648a7a500081211.jpeg
2.SELECT * FROM `MTRIVI` WHERE numero LIKE '1000410001'; 12 total, Query took 0.0009 sec
5c6bda29828cc383836661.jpeg
All the time I thought that like query is slower than = .
How to explain it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman MySQL, 2019-02-19
@Obivankinobi

because in the first example, the comparison is not with a string, but with a number, hence the type casting and the query goes past the index, which is clearly displayed in the plan. key column

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question