[Database] - Lossless connection, Chase algorithm, maintaining functional dependencies

Chase Algorithm

Formal definition:

  • construct a kkk rownnA table with n columns, each row corresponds to a patternR i ( 1 ≤ i ≤ k ) Ri (1≤i ≤ k)Ri(1ik ) , each column corresponds to an attributeA j ( 1 ≤ j ≤ n ) Aj ( 1≤j≤ n)Aj1jn ,若A j AjA j inR i RiR i , then in tableiirow i , jjFill in aj ajin column jaj , otherwise fill in the symbolbij bijbee
  • Check FFF for eachFD FDF D , and modify the elements in the table, as follows:
    • For the functional dependence X → YX → Y in FXY , if there are two rows in the table atXXEqual in X component, in YYY components
      are not equal, then modifyYYY
      • YYThere is an aj ajin the component of Yaj , the other is also modified toaj ajaj
      • if there is no aj ajaj , use one of thebij bijbij replaces another symbol (iii is allbbthe minimum number of rows in b ) until the table cannot be modified
  • If after modification, there is a row in the table that is all aaa , immediatelya 1 a 2 … an a1a2…ana 1 a 2and pp_p relative toFFF is a decomposition of lossless connections, otherwise not
    for example:

Relation schema: R ( A , B , C , D , E ) Decomposition: R 1 ( A , D ) , R 2 ( A , B ) , R 3 ( B , E ) , R 4 ( C , D , E ) , R 5 ( A , E ) Functional dependency: F = { A → C , B → C , C → D , DE → C , CE → A } Judgment R is decomposed into p = R 1 , R 2 , R 3 , R 4 , R 5 Whether it is a decomposition relation mode of lossless connection: R(A,B,C,D,E)\\ {}\\ Decomposition: R1(A,D), R2(A,B), R3(B ,E), R4(C,D,E), R5(A,E)\\ {}\\ Functional dependency: F=\{A→C, B→C, C→D, DE→C, CE→ A\}\\ {}\\ Determine whether R is decomposed into p={R1, R2, R3, R4, R5} is a decomposition of lossless connectionRelation schema: R ( A ,B,C,D,E)Decomposition: R 1 ( A ,D),R2(A,B),R3(B,E),R4(C,D,E),R5(A,E)Functional dependencies: F={ AC,BC,CD,D EC,CEA}Judging that R is decomposed into p = R 1 ,R2 , _R 3 ,R 4 ,Is R 5 a decomposition of lossless joins

Chase Algorithm Example

① Construct an initial two-dimensional table If the "attribute" belongs to the attribute in the "schema", fill in aj, otherwise fill in bij

Please add a picture description

② According to A→C, process the above table. Since the 1st, 2nd, and 5th rows on the attribute column A are all a1, change the b13, b23, and b53 on the attribute column C to the same symbol b13 (take the row number minimum).

Please add a picture description
③ According to B→C, process the above table. Since the second and third rows on attribute column B are both a2, change b13 and b33 on attribute column C to the same symbol b13 (take the minimum value of the row number) .

Please add a picture description
④ Process the above table according to C→D. Since rows 1, 2, 3, and 5 on attribute column C are all b13, the values ​​on attribute column D are all changed to the same symbol a4.

Please add a picture description
⑤ According to DE→C, process the above table. Since the 3rd, 4th, and 5th rows on the attribute column DE are the same as a4a5, so change the values ​​on the attribute column C to the same symbol a3.

Please add a picture description
⑥ According to CE→A, process the above table. Since the 3rd, 4th, and 5th rows on the attribute column CE are the same as a3a5, the values ​​on the attribute column A are all changed to the same symbol a1.

Please add a picture description

⑦ Through the above modification, the third line becomes a 1 a 2 a 3 a 4 a 5 a1a2a3a4a5a 1 a 2 a 3 a 4 a 5 , the algorithm terminates. And the decomposition has lossless connectivity.

Chase algorithm example part reference link

One convenience method: when decomposed into two patterns

insert image description here

A Simple Example of Lossless Joins and Functional Dependencies

insert image description here

Guess you like

Origin blog.csdn.net/weixin_56462041/article/details/130225013