《數(shù)據(jù)庫系統(tǒng)》教學(xué)課件
《數(shù)據(jù)庫系統(tǒng)》教學(xué)課件,數(shù)據(jù)庫系統(tǒng),數(shù)據(jù)庫,系統(tǒng),教學(xué),課件
Relational CalculusJianlin FengSchool of SoftwareSUN YAT-SEN UNIVERSITYcourtesy of Joe Hellerstein for some slidesRelational CalculusnQuery has the form:T|p(T)qT is a tuple variable.qp(T)is a formula containing T.nAnswer =tuples T for which p(T)=true.FormulaenAtomic formulae:T Relation T.a op T.bT.a op constant op is one of nA formula can be:q an atomic formulaq q q Free and Bound VariablesnQuantifiers:and nUse of or binds X.qA variable that is not bound is free.nRecall our definition of a query:qT|p(T)Important restriction:T must be the only free variable in p(T).all other variables must be bound using a quantifier.Simple QueriesnFind all sailors with rating above 7 nFind names and ages of sailors with rating above 7.qNote:S is a variable of 2 fields(i.e.S is a projection of Sailors)S|S Sailors S.rating 7S|S1 Sailors(S1.rating 7 S.sname=S1.sname S.age=S1.age)Find sailors rated 7 whove reserved boat#103 S|SSailors S.rating 7 R(RReserves R.sid=S.sid R.bid=103)JoinsJoins(continued)This may look cumbersome,but its not so different from SQL!S|SSailors S.rating 7 R(RReserves R.sid=S.sid B(BBoats B.bid=R.bid B.color=red)Find sailors rated 7 whove reserved a red boatUniversal QuantificationFind sailors whove reserved all boats S|SSailors BBoats(RReserves (S.sid=R.sid B.bid=R.bid)A trickier example S|SSailors B Boats(B.color=red R(RReserves S.sid=R.sid B.bid=R.bid)Find sailors whove reserved all Red boats S|SSailors B Boats(B.color red R(RReserves S.sid=R.sid B.bid=R.bid)Alternativelya b is the same as a baTFT FbTTTFA Remark:Unsafe Queriesn syntactically correct calculus queries that have an infinite number of answers!Unsafe queries.qe.g.,qSolution?Dont do that!Expressive PowernExpressive Power(Theorem due to Codd):qEvery query that can be expressed in relational algebra can be expressed as a safe query in relational calculus;the converse is also true.nRelational Completeness:Query language(e.g.,SQL)can express every query that is expressible in relational algebra/calculus.(actually,SQL is more powerful,as we will see)SummarynFormal query languages simple and powerful.qRelational algebra is operationalnused as internal representation for query evaluation plans.qRelational calculus is“declarative”nquery=“what you want”,not“how to compute it”qSame expressive power-relational completeness.nSeveral ways of expressing a given queryqa query optimizer should choose the most efficient version.Your turn nSchema:Movie(title,year,studioName)ActsIn(movieTitle,starName)Star(name,gender,birthdate,salary)nQueries to write in Relational Calculus:1.Find all movies by Paramount studio2.movies whose stars are all women3.movies starring Kevin Bacon4.Find stars who have been in a film w/Kevin Bacon5.Stars within six degrees of Kevin Bacon*6.Stars connected to K.Bacon via any number of films*Try two degrees for starters *Good luck with this one!Answers 1.Find all movies by Paramount studioM|MMovie M.studioName=ParamountAnswers 2.Movies whose stars are all womenM|MMovie AActsIn(A.movieTitle=M.title)SStar(S.name=A.starName S.gender=F)Answers 3.Movies starring Kevin BaconM|MMovie AActsIn(A.movieTitle=M.title A.starName=Bacon)Answers 4.Stars who have been in a film w/Kevin BaconS|SStar AActsIn(A.starName=S.name A2ActsIn(A2.movieTitle=A.movieTitle A2.starName=Bacon)moviestarA2:S:nameBaconmoviestarA:Answers 5.Stars within six degrees of Kevin BaconS|SStar AActsIn(A.starName=S.name A2ActsIn(A2.movieTitle=A.movieTitle A3ActsIn(A3.starName=A2.starName A4ActsIn(A4.movieTitle=A3.movieTitle A4.starName=Bacon)twoTwo degrees:S:nameBaconmoviestarA2:moviestarA:moviestarA4:moviestarA3:Answers 6.Stars connected to K.Bacon via any number of filmsSorry that was a trick questionNot expressible in relational calculus!What about in relational algebra?We will be able to answer this question shortly
收藏
編號:48634128
類型:共享資源
大小:6.17MB
格式:ZIP
上傳時間:2022-01-12
30
積分
- 關(guān) 鍵 詞:
-
數(shù)據(jù)庫系統(tǒng)
數(shù)據(jù)庫
系統(tǒng)
教學(xué)
課件
- 資源描述:
-
《數(shù)據(jù)庫系統(tǒng)》教學(xué)課件,數(shù)據(jù)庫系統(tǒng),數(shù)據(jù)庫,系統(tǒng),教學(xué),課件
展開閱讀全文
- 溫馨提示:
1: 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
裝配圖網(wǎng)所有資源均是用戶自行上傳分享,僅供網(wǎng)友學(xué)習(xí)交流,未經(jīng)上傳用戶書面授權(quán),請勿作他用。