cour s e age nda le c t ur e 5 re l a t i ona l al ge br a
play

Cour s e Age nda Le c t ur e 5: Re l a t i ona l Al - PDF document

Cour s e Age nda Le c t ur e 5: Re l a t i ona l Al ge br a Today, XM L a nd r e l a t i ona l a l ge br a a nd XM L Ne xt t wo we e ks : t he i nt e r na l s of DBM S. Cove r


  1. Cour s e Age nda Le c t ur e 5: Re l a t i ona l Al ge br a • Today, XM L a nd r e l a t i ona l a l ge br a a nd XM L • Ne xt t wo we e ks : t he i nt e r na l s of DBM S. – Cove r e d i n gor y de t a i l i n t he book, but s t a y t une d f or r e a di ng a s s i gnm e nt s . M onday, Apr i l 26t h, 2004 • M ay 20t h ( not 17t h! ) : Phi l Be r ns t e i n on m e t a - da t a m a na ge m e nt . • M ay 24t h: da t a i nt e gr a t i on. • M ay 27t h: f i na l e xa m . 1 2 Age nda Re l a t i ona l Al ge br a • Re l a t i ona l a l ge br a • For m a l i s m f or c r e a t i ng ne w r e l a t i ons f r om e xi s t i ng one s • XM L: • I t s pl a c e i n t he bi g pi c t ur e : – W ha t i s i t a nd why do we c a r e ? – Da t a m ode l – Que r y l a nguage : XPa t h De c l a r t i ve – Re al que r y l a nguage : XQue r y. quer y Al ge br a I m pl em ent a t i on l anguage – Ge ne r al r um i na t i ons a bout XM L. Re l a t i onal al ge br a SQL, Re l a t i onal bag a l gebr a 3 4 r e l a t i onal c a l cul us 1. Uni on a nd 2. Di f f e r e nc e Re l a t i ona l Al ge br a • Fi ve ope r a t or s : – Uni on: ¨ • R1 ¨ R2 – Di f f e r enc e: - – Se l e c t i on:s • Exa m pl e : – Pr oj e c t i on: P – Ac t i ve Em pl oye e s ¨ Re t i r e dEm pl oye e s – Ca r t e s i an Pr oduc t : · • De r i ve d or a uxi l i a r y ope r a t or s : – I nt e r s e c t i on, c om pl em ent • R1 – R2 – J oi ns ( na t ur al , e qui - j oi n, t he t a j oi n, s em i - j oi n) • Exa m pl e : – Re nam i ng:r – Al l Em pl oye e s - -Re t i r e dEm pl oye e s 5 6 1

  2. W ha t a bout I nt e r s e c t i on ? 3. Se l e c t i on • I t i s a de r i ve d ope r a t or • Re t ur ns a l l t upl e s whi c h s a t i s f y a • R1 ˙ R2 = R1 – ( R1 –R2) c ondi t i on • Al s o e xpr e s s e d a s a j oi n ( wi l l s e e l a t e r ) • Not a t i on: s c ( R) • Exa m pl e • Exa m pl e s – Uni oni ze dEm pl oye e s ˙ Re t i r e dEm pl oye e s – s Sa 40000 ( Em pl oye e ) l a r y > – s na h” ( Em pl oye e ) m e = “ Sm i t • The c ondi t i on c c a n be =, <, £, >,‡, <> 7 8 Se l e c t i on Exam pl e 4. Pr oj e c t i on • El i m i na t e s col um ns , t he n r e m ove s dupl i c a t e s Em pl oye e SSN Na m e De pa r t m e nt I D Sa l a r y • Not a t i on: P An ( R) A1, … , 999999999 J ohn 1 30, 000 • Exam pl e : pr oj e c t s oc i a l - s e c ur i t y num be r a nd 777777777 Tony 1 32, 000 na m e s : 888888888 Al i c e 2 45, 000 – P SSN, me ( Em pl oye e ) Na – Out put s c hem a: Ans wer ( SSN, Nam e ) Fi nd al l e m pl oye e s wi t h s a l a r y m or e t ha n $40, 000. s 40000 ( Em pl oye e ) Sa l a r y > SSN Na m e De pa r t m e nt I D Sa l a r y 888888888 Al i c e 2 45, 000 9 10 Proj ec t i on Exam pl e 5. Ca r t e s i a n Pr oduc t Em pl oyee SSN Na m e De pa r t m e nt I D Sa l a r y • Ea c h t upl e i n R1 wi t h e a c h t upl e i n R2 999999999 J ohn 1 30, 000 777777777 Tony 1 32, 000 • Not a t i on: R1 · R2 888888888 Al i ce 2 45, 000 • Exa m pl e : P SSN, P P P Nam e ( Em pl oye e ) – Em pl oye e · De pe nde nt s SSN Na m e • Ve r y r a r e i n pr a c t i c e ; m a i nl y us e d t o 999999999 J ohn e xpr e s s j oi ns 777777777 Tony 888888888 Al i ce 11 12 2

  3. Cart e s i an Pr oduc t Exam pl e Em pl oye e Re na m i ng Na m e SSN J ohn 999999999 Tony 777777777 • Cha nge s t he s c he m a , not t he i ns t a nc e De pe nde nt s • Not a t i on: r B1, Bn ( R) … , Em pl oyee SSN Dnam e • Exa m pl e : 999999999 Em i l y 777777777 J oe – r Las SocNo ( Em pl oye e ) t Nam e , Soc – Out put s c he m a : Em pl oye e x De pe ndent s Na m e SSN Em pl oye eSSN Dna m e Ans we r ( Las t Nam e , Soc Soc No) J ohn 999999999 999999999 Em i l y J ohn 999999999 777777777 J oe Tony 777777777 999999999 Em i l y Tony 777777777 777777777 J oe 13 14 Na t ur a l J oi n Re nam i ng Exam pl e ⋈ R2 • Not a t i on: R1 Em pl oye e ⋈ R2 Name SSN • M e a ni ng: R1 = P A ( s C ( R1 · R2) ) J ohn 999999999 Tony 777777777 • W he r e : – The s e l e c t i on s C c he cks e qual i t y of a l l com m on a t t r i but e s r Las SocSocNo ( Em pl oye e ) t Name, – The pr oj e c t i on e l i m i na t e s t he dupl i c at e com m on La s t Name Soc Soc No a t t r i but e s J ohn 999999999 Tony 777777777 15 16 Nat ur al Joi n Exam pl e Em pl oye e Na t ur a l J oi n Name SSN J ohn 999999999 Tony 777777777 • R= S= A B B C X Y Z U De pendent s X Z V W SSN Dnam e Y Z Z V 999999999 Em i l y Z V 777777777 J oe Em pl oye e De pe ndent s = ⋈ S= A B C • R P Na me ( s SSN=SSN2 ( Empl oye e x r SSN2, me ( De pendent s ) ) X Z U me , SSN, Dna Dna Name SSN Dnam e X Z V J ohn 999999999 Em i l y Y Z U Tony 777777777 J oe Y Z V Z V W 17 18 3

  4. Na t ur a l J oi n The t a J oi n • Gi ve n t he s c he m a s R( A, B, C, D) , S( A, C, E) , • A j oi n t ha t i nvol ve s a pr e di c a t e ⋈ S ⋈ q R2 wha t i s t he s c he m a of R ? • R1 = s q ( R1 · R2) • He r e q c a n be a ny c ondi t i on ⋈ S • Gi ve n R( A, B, C) , S( D, E) , wha t i s R ? ⋈ S • Gi ve n R( A, B) , S( A, B) , wha t i s R ? 19 20 Eq- j oi n Se m i j oi n ⋉ S ⋈ S) • A t he t a j oi n whe r e q i s a n e qua l i t y • R = P A1, An ( R … , ⋈ A=B R2 • R1 = s A=B ( R1 · R2) • W he r e A 1 , … , A n a r e t he a t t r i but e s i n R • Exa m pl e : • Exa m pl e : ⋈ SSN=SSN De ⋉ De – Em pl oye e pe nde nt s – Em pl oye e pe nde nt s • M os t us e f ul j oi n i n pr a c t i c e 21 22 Com pl e x RA Expr e s s i ons Se m i j oi ns i n Di s t r i but e d P na Da t a ba s e s m e • Se m i j oi ns a r e us e d i n di s t r i but e d da t a ba s e s buye r - s s n=s s n De pe ndent s pi d=pi d Em pl oye e SSN Dname Age . . . . . . SSN Nam e s e l l e r - s s n=s s n ne t wor k . . . . . . P s P pi s n d ⋈ s Em pl oye e n ( s ( De pe nde nt s ) ) s nam e=f s nam e=gi s n=s s age>71 r ed zm o T = P SSN s ( De pe ndent s ) ⋉ T a ge >71 R = Empl oye e Pe r s on Pur cha s e Pe r s on Pr oduc t ⋈ De 23 24 Ans wer = R pe nde nt s 4

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend