<分区>
尝试了 3 种不同的方式。
第一名
explain select * from test where create_time like '2019-10%';
id|select_type|table|partitions|type|possible_keys |key|key_len|ref|rows |filtered|Extra |
--|-----------|-----|----------|----|--------------------|---|-------|---|-----|--------|-----------|
1|SIMPLE |test | |ALL |test_create_time_IDX| | | |10376| 11.11|Using where|
第二名
explain select * from test where create_time between '2019-10-01 00:00:00' and '2019-10-31 23:59:59';
id|select_type|table|partitions|type |possible_keys |key |key_len|ref|rows|filtered|Extra |
--|-----------|-----|----------|-----|--------------------|--------------------|-------|---|----|--------|---------------------|
1|SIMPLE |test | |range|test_create_time_IDX|test_create_time_IDX|6 | | 5| 100|Using index condition|
第三
explain select * from test where date_format(create_time,'%Y-%m') = '2019-10';
id|select_type|table|partitions|type|possible_keys|key|key_len|ref|rows |filtered|Extra |
--|-----------|-----|----------|----|-------------|---|-------|---|-----|--------|-----------|
1|SIMPLE |test | |ALL | | | | |10376| 100|Using where|
我被告知“like 'pattern%'”将使用索引。“like '%pattern%'”,“like '%pattern'”不会。
但是在1st条件下它并没有像我想的那样。是因为create_time的列类型是DATETIME吗?
我在官方引用手册中找不到与索引交互时所有这些“类似”SQL 的差异的详细信息。
谁能给我一个官方链接吗?(我得到的都是道听途说)