gpt4 book ai didi

sql - 关于指数的问题

转载 作者:行者123 更新时间:2023-12-01 12:59:32 25 4
gpt4 key购买 nike

如果我有一个以下列作为主键的表:Username, Title, Start Date,那么数据库将自动在其上创建索引。

  1. 如果我想按用户名和查询开始日期进行选择......它会使用上面的索引还是我需要指定一个额外的索引?
  2. 如果标题和开始日期是唯一标识,但我还将用户名添加到主键,这会使其成为 super 键吗?

最佳答案

1) If I want to select by username, and start date for a query.....will it use the index above OR do I need to specify an additional index?

你有一个复杂的条件,比如说,像这样:

username = 'blah-blah-blah' AND startdate > '01.01.2010'

如果您的表的 PK 定义如下:

PRIMARY KEY (Username, Title, StartDate)

然后索引将用于涉及用户名字段的第一部分。开始日期值将按自然顺序计算。

如果您希望索引用于复杂条件的两个部分,请在开始日期创建额外的索引或更改 PK 中字段的顺序:

PRIMARY KEY (Username,  StartDate, Title)

2) If title and start date identify uniquely but I also add username to the primary key, would that make it a superkey?

最好不要滥用带有附加字段的唯一索引。在您的情况下,在标题和开始日期上创建 PK,然后(如果需要)在用户名字段上创建单独的索引。

关于sql - 关于指数的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7380358/

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