【问题标题】:Do we need to add primary key to multiple columns index?我们是否需要将主键添加到多列索引?
【发布时间】:2017-05-13 09:15:51
【问题描述】:

我们需要将主键添加到多列索引吗?还是会自动放在那里?

ALTER TABLE `wp_posts`
  ADD PRIMARY KEY (`ID`),
  ADD KEY `post_name` (`post_name`(191)),
  ADD KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`),
  ADD KEY `post_parent` (`post_parent`),
  ADD KEY `post_author` (`post_author`);

【问题讨论】:

标签: mysql sql wordpress


【解决方案1】:

我得出一个结论,他们将 ID 放在那里,因为使用“ORDER BY ID”会更快,因为引擎不需要排序,而是遵循 索引

good/doesn't matter/bad to include Primary Key in covering index?

【讨论】:

    猜你喜欢
    • 2013-01-28
    • 2011-03-04
    • 2021-01-08
    • 1970-01-01
    • 2012-11-15
    • 2013-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多