Я учусь, используя условие индекса в mariadb
Это для Centos7 и работает Mariadb 10.2
это мой SQL.
создать индекс
create index ixnn_product__updated_at
on product (updated_at);
объяснение
explain extended
select * from product
where updated_at BETWEEN '2018-06-10 00:00:00' AND '2019-06-10 23:59:59'
результат
id: 1
select_type: SIMPLE
table: product
type: range
possible_keys: ixnn_product__updated_at
key: ixnn_product__updated_at
key_len: 5
ref: NULL
rows: 2431232
filtered: 100.00
Extra: Using index condition
Я ожидал использовать индекс в дополнительном, но я видел Использование условия индекса
Итак, я добавил тест.
объяснить
explain extended
select updated_at from product
where updated_at BETWEEN '2018-06-10 00:00:00' AND '2019-06-10 23:59:59'
результат
id: 1
select_type: SIMPLE
table: product
type: range
possible_keys: ixnn_product__updated_at
key: ixnn_product__updated_at
key_len: 5
ref: NULL
rows: 2431232
filtered: 100.00
Extra: Using where; Using index
Почему это происходит?