gpt4 book ai didi

mysql - 用于日期范围查询的聚簇索引与非聚簇索引

转载 作者:行者123 更新时间:2023-11-29 07:32:51 24 4
gpt4 key购买 nike

我在 mySql 中有这个查询:

SELECT field1
FROM table1
WHERE tdate > '2018-6-01' OR (tdate BETWEEN '2015-4-07' AND 2016-6-07);

tdate 上的索引或 (tdate, field1) 上的覆盖索引,什么会提高查询性能?

最佳答案

您可以使用 included columns 创建索引:

Redesign nonclustered indexes with a large index key size so that only columns used for searching and lookups are key columns. Make all other columns that cover the query into nonkey columns. In this way, you will have all columns needed to cover the query, but the index key itself is small and efficient.

CREATE INDEX my_idx_name ON tab_name(tdate) INCLUDE (field1)

关于mysql - 用于日期范围查询的聚簇索引与非聚簇索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50397689/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com