V
V
Vladimir Romantsov2018-06-22 12:09:54
MySQL
Vladimir Romantsov, 2018-06-22 12:09:54

Composite index Does the order in Where matter?

Let's say I create a table and index the columns in this order last_name, first_name, address

CREATE TABLE customer (
id INT NOT NULL,
last_name CHAR(30) NOT NULL,
first_name CHAR(30) NOT NULL,
address CHAR(30) NOT NULL,
PRIMARY KEY (id),
INDEX name (last_name,first_name,address)
);

Does the order of columns in after where matter, for example First "first_name" after "last_name" :
"SELECT * FROM customer WHERE first_name = 'Joe' and last_name='Don'

that is, in the index ( col1,col2,col3) and in the selection I specify where col2='val' and col1='val'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2018-06-22
@romancov_vladimir

No, it doesn't. The query planner will deal with this on its own.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question