开发者

Question on indices

If I have a table with the following columns as the primary key: Username, Title, Start Date, then the database will automatically create an index on it.

  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 additi开发者_如何学Goonal index?
  2. If title and start date identify uniquely but I also add username to the primary key, would that make it a superkey?


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?

You have a complex condition, say, like this:

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

If your table's PK defined like:

PRIMARY KEY (Username, Title, StartDate)

Then index will be used for first part involving username field. startdate values will be evaluated in natural order.

If you want index to be used for both parts of complex condition, either create additional index on startdate or change order of fields in the 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?

It is a good practice not to abuse an unique index with additional fields. In your case create PK on title and start date and then (if necessarily) create separate index on user name field.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜