【问题标题】:Index structure for secondary keyword search二级关键词搜索的索引结构
【发布时间】:2017-12-21 03:24:13
【问题描述】:

我有一个表格(文章),结构如下:

id int(10) unsigned not_null auto_increment
title varchar(32)
system_id int(10) unsigned default 0
last_update int(10) unsigned default 0

为该查询提供最佳性能的表的推荐索引结构是什么:

"SELECT * FROM Articles where system_id = {ID} order by last_update desc"

【问题讨论】:

  • system_idlast_update 上的索引应该会提高性能。

标签: mysql indexing database-performance query-performance


【解决方案1】:

正如讨论的 here ,从 = 列 (system_id) 开始,然后是“范围”列 (last_update):

INDEX(system_id, last_update)

【讨论】:

    【解决方案2】:

    我将添加这两个索引并检查 EXPLAIN 计划以查看使用了哪些。 MySQL 有时会选择排序索引而不是过滤索引,因此在某些情况下第二个可能会更好。

    ALTER TABLE `Articles` ADD INDEX `articles_index_1` (system_id, last_update);
    ALTER TABLE `Articles` ADD INDEX `articles_index_1` (last_update);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-06
      • 2012-02-20
      • 2014-03-26
      • 2015-12-06
      • 2015-11-05
      • 1970-01-01
      相关资源
      最近更新 更多