MySQL 索引冗余?
Action Keyname Type Unique Packed Column Cardinality Collation Null Comment
Edit Drop PRIMARY BTREE Yes No TickerID 23200 A
Timestamp 13897209 A
Edit Drop TickerID BTREE No No TickerID 11737 A
Edit Drop Timestamp BTREE No No Timestamp 18 A
~99,424,209 InnoDB utf8_general_ci 5.1 GiB
好吧,在我尝试通过删除不需要的索引来“优化”该数据库之前,我想我会在这里问。该表受到很多打击,因此我想加快插入性能。我在网上阅读了 5 篇文章,这些文章似乎表明 TickerID 上的单个索引是多余的,因为如果我仅对 TickerID 运行查询,则将使用多个索引(TickerID、Timestamp)。
偶尔,我会喜欢做 EOD 报告,这样我就可以做类似 SELECT * WHERE Timestamp > > 的事情。 Today() - 1 天
或类似的东西。我还需要时间戳索引吗?
Action Keyname Type Unique Packed Column Cardinality Collation Null Comment
Edit Drop PRIMARY BTREE Yes No TickerID 23200 A
Timestamp 13897209 A
Edit Drop TickerID BTREE No No TickerID 11737 A
Edit Drop Timestamp BTREE No No Timestamp 18 A
~99,424,209 InnoDB utf8_general_ci 5.1 GiB
OK before I try to "optimize" this DB by deleting unneeded indexes I thought I'd ask here. This table gets hit a lot so I want to speed up insert performance. I read 5 articles on the net that seem to indicate that the single index on TickerID is redundant because the multiple index (TickerID,Timestamp) will be used if I ever run a query on just tickerID.
Occasionally, I will like to do EOD reporting, so that I might just do something like SELECT * WHERE Timestamp > Today() - 1 day
or something like that. Do I need the timestamp index as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
tickerId, timestamp
上的索引可供所有只能使用tickerId
上的索引的查询使用。但是,对于这样的查询:
将不会使用
(tickerId, timestamp
) 上的索引,因为tickerId
上没有相等过滤器。对于此查询,您应该仅在
timestamp
上创建索引或重写您的查询:但是,后一个查询效率较低,特别是如果
tickerId
中有很多不同的值。This index on
tickerId, timestamp
can be used by all queries which can use an index ontickerId
only.However, for a query like that:
an index on
(tickerId, timestamp
) will not be used, since there is no equality filter ontickerId
.For this query, you should create an index on
timestamp
only or rewrite thу query:However, the latter query is less efficient, especially if you have lots of distinct values in
tickerId
.