简体   繁体   中英

Why is Mysql not using a part index?

So I have a table of IP addresses and RIR ranges and so want to link on the first 3 characters of the IP address in a join.

I have created the following index: CREATE INDEX My_range ON ranges ( Range (3))

I then run the following query:

EXPLAIN SELECT * FROM ips JOIN ranges rt ON SUBSTR(IPAddress,1,3) = SUBSTR( Range ,1,3) WHERE IPID = 17054

And I don't see any indexes available on the rt line. What am I missing??

The following quote is from @juergend in comments.

Indexes can only be used on raw column data and not on data that is processed by a function like substr() .

To add on what he said, you may want to create another indexed column to hold the substring'd value and join on that instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM