我当前正在运行以下查询,当这些查询中的多个命中我的数据库时,该查询会导致数据库堵塞:
select * from ip_lookup where addr_type = 'ipv4' and ip_start <= '<9d>)Ü<86>' order by ip_start desc limit 1;
# Time: 200102 8:25:19
# User@Host: root[root] @ localhost []
# Query_time: 593.831791 Lock_time: 0.000090 Rows_sent: 1 Rows_examined: 3697391ip_start为varbinary,addr_type为枚举
对于这些领域,基于性能最好的索引是什么?
发布于 2020-01-03 03:59:34
您可以对枚举和varbinary列使用普通B树索引。
ALTER TABLE ip_lookup ADD INDEX (addr_type, ip_start)列的顺序很重要。首先命名在相等条件(如addr_type = ?)中使用的列,然后可以命名在不等式条件(ip_start <= ?)或ORDER BY中使用的列。
https://stackoverflow.com/questions/59567084
复制相似问题