简体   繁体   English

找到关系中最多的候选键?

[英]finding largest number of candidate keys that a relation has?

I am trying to solve this question which has to do with candidate keys in a relation. 我正在尝试解决这个与关系中的候选键有关的问题。 This is the question: 这是问题:

    Consider table R with attributes A, B, C, D, and E. What is the largest number of
candidate keys that R could simultaneously have?

the answer is 10 but i have no clue how it was done, nor how does the word simultaneously plays into effect when calculating the answer. 答案是10但我不知道它是如何完成的,也不知道单词在计算答案时如何同时生效。

Sets that are not subsets of other sets. 不是其他集合的子集的集合。
For example {AB} and {A,B,C} can't be candidates keys simultaneously, because {A,B} is a subset of {A,B,C}. 例如,{AB}和{A,B,C}不能同时作为候选键,因为{A,B}是{A,B,C}的子集。
Combinations of 2 attributes or 3 attributes generates the maximum number of simultaneous candidates keys. 2个属性或3个属性的组合生成同时候选键的最大数量。
See how the 3 attributes sets are actually complements of the 2 attributes sets, eg {C,D,E} is the complement of {A,B}. 看看3个属性集实际上是2个属性集的补充,例如{C,D,E}是{A,B}的补充。

         2               3    
     attributes      attributes
       sets            sets

   1.  {A,B}    -     {C,D,E}
   2.  {A,C}    -     {B,D,E}
   3.  {A,D}    -     {B,C,E}
   4.  {A,E}    -     {B,C,D}
                -     
   5.  {B,C}    -     {A,D,E}
   6.  {B,D}    -     {A,C,E}
   7.  {B,E}    -     {A,C,D}
                -     
   8.  {C,D}    -     {A,B,E}
   9.  {C,E}    -     {A,B,D}
                -     
   10. {D,E}    -     {A,B,C}

If I would take sets of a single attribute I would have only 4 options 如果我将单个属性设置为集合,则只有4个选项

{A},{B},{C},{D}

Any set with more than 1 element will contain one of the above and therefore will not be qualified. 任何包含1个以上元素的集合将包含上述元素之一,因此将不合格。

If I would take sets of 4 attributes I would have only 4 options 如果我要设置4个属性的集合,那么我将只有4个选项

{A,B,C,D},{A,B,C,E},{A,B,D,E},{B,C,D,E}

Any set with more than 4 element will contain one of the above and therefore will not be qualified. 任何包含4个以上元素的集合都将包含上述之一,因此将不合格。 Any set with less than 4 element will be contained by one of the above and therefore will not be qualified. 少于4个元素的任何集合将包含在上述元素之一中,因此将不合格。

etc. 等等

For 5 keys, it is probably best to do this by brute force. 对于5个键,最好是用蛮力进行。 Understanding the ideas is more important than the calculation (DuDu/David gives a good example of 10 candidate keys, showing that a set of 10 keys is possible so the maximum is at least this large). 理解这些概念比计算更重要(DuDu / David给出了10个候选密钥的一个很好的示例,显示了10个密钥的集合是可能的,因此最大值至少要这么大)。

What is the idea? 有什么想法? A candidate key is a combination of attributes that is unique. 候选键是唯一属性的组合。 So, if A is unique, then A with any other column is also unique. 因此,如果A是唯一的,则A和其他任何列也都是唯一的。 One set of candidate keys is simply: 一组候选键很简单:

  • A 一种
  • B
  • C C
  • D d
  • E Ë

If each of these are unique, then any combination of keys is going to contain at least one of these attributes and the combination will also be unique. 如果它们中的每一个都是唯一的,则任何键组合都将包含这些属性中的至少一个,并且组合也将是唯一的。 Hence, the uniqueness of these five would imply the uniqueness of any other combination. 因此,这五个的唯一性将暗示任何其他组合的唯一性。

5 is not the largest number of candidate keys with this property. 5不是具有此属性的最大候选键数。

It gets a bit more complicated. 它变得更加复杂。 If {A, B, C, D, E} is unique (and no subset is a candidate key), then there is exactly 1 candidate key. 如果{A,B,C,D,E}是唯一的(并且没有子集是候选关键字),则恰好有1个候选关键字。 Rearranging the columns doesn't change the set (sets are unordered). 重新排列列不会更改集合(集合是无序的)。

One thing we might postulate is that the biggest set of candidate keys has keys all of the same length. 我们可能假设的一件事是,最大的候选键集具有相同长度的键。 This is in fact true. 这是事实。 Why? 为什么? Well, if we have a set of keys that are of different lengths, we can lengthen the shorter ones by adding arbitrary attributes and still have a maximal set. 好吧,如果我们有一组长度不同的键,则可以通过添加任意属性来加长较短的键,而仍然有一个最大的键集。

So, you only need to consider subsets of 1, 2, 3, 4, and 5 keys, exactly. 因此,您只需要精确地考虑1、2、3、4和5个键的子集。 When you work it out, you will find that the maximum numbers are: 进行计算时,您会发现最大数量为:

5 10 10 5 1

You can add a "1" to the beginning and you may recognize the pattern. 您可以在开头添加“ 1”,并且可以识别该模式。 This is a row from Pascal's Triangle . 这是Pascal的Triangle中的一行。 This observation (well, and the related proof) actually makes it easy to determine the maximum value for any given n. 实际上,这种观察(以及相关证明)使确定给定n的最大值变得容易。

Incidentally, the sets of length 3 are: 顺便说一下,长度为3的集合为:

A B C
A B D
A B E
A C D
A C E
A D E
B C D
B C E
B D E
C D E

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM