QQ扫一扫联系
要给 MySQL 数据库表 blog 增加一个联合索引 key(postTime, isPublished) ,可以使用如下 SQL 语句:
ALTER TABLE blog ADD INDEX idx_postTime_isPublished (postTime, isPublished);
这条语句会将表 blog 中的 postTime 和 isPublished 两个字段组成一个联合索引,索引名为 idx_postTime_isPublished。在使用这个联合索引时,MySQL 会优先按照 postTime 字段进行排序,然后再按照 isPublished 字段进行排序。这样可以提高查询效率,特别是在同时涉及到 postTime 和 isPublished 两个字段的查询时。