资源描述:
《数据库系统英第三版课件衷宜2011版 algebraic(5).ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Chapter5AlgebraicandLogicalQueryLanguages第5章代数和逻辑查询语言5.1RelationalOperationsonBagsWhatisabag?Abagmeansarelationthatmay(ormaynot)haveduplicatetuples.Asetmeansarelationwithoutduplicatetuples.Whybags?SQL,themostimportantquerylanguageforrelationaldatabases,isactuallyabaglanguage.Someoperati
2、ons,likeprojection,aremuchmoreefficientonbagsthansets.5.1RelationalOperationsonBagsSelectionappliestoeachtuple,soitseffectonbagsislikeitseffectonsets.Projectionalsoappliestoeachtuple,butasabagoperator,wedonoteliminateduplicates.Productsandjoinsaredoneoneachpairoftuples,soduplicatesinbag
3、shavenoeffectonhowweoperate.Example:BagSelectionR(A,B)125612σA+B<5(R)=AB1212Example:BagProjectionR(A,B)125612πA(R)=A151Example:BagProductR(A,B)S(B,C)1234567812R*S=AR.BS.BC123412785634567812341278Example:BagTheta-JoinR(A,B)S(B,C)1234567812RR.B4、lementappearsintheunionoftwobagsthesumofthenumberoftimesitappearsineachbag.Example:{1,2,1}{1,1,2,3,1}={1,1,1,1,1,2,2,3}BagIntersectionAnelementappearsintheintersectionoftwobagstheminimumofthenumberoftimesitappearsineither.Example:{1,2,1,1}{1,2,1,3}={1,1,2}.BagDifferenceAnelementappear
5、sinthedifferenceA–BofbagsasmanytimesasitappearsinA,minusthenumberoftimesitappearsinB.Butneverlessthan0times.Example:{1,2,1,1}–{1,2,3}={1,1}.5.4OtherExtensionstotheRelationalModelModifications:Insert,delete,updateAggregations:Count,average,minimum,andmaximum,tocolumnsofarelationViews:Nul
6、lvalues:valueunknown:IknowthereissomevaluethatbelongsherebutIdon’tknowwhatitis.valueinapplicable:Thereisnovaluethatmakessensehere.valuewithheld:Wearenotentitledtoknowthevaluethatbelongshere.OuterjoinSupposewejoinRS.AtupleofRthathasnotupleofSwithwhichitjoinsissaidtobedangling.Similarlyf
7、oratupleofS.OuterjoinpreservesdanglingtuplesbypaddingthemwithaspecialNULLsymbolintheresult.LeftouterjoinRightouterjoinFullouterjoinLeftOuterjoinOuterjoinRightOuterjoinOuterjoinFullOuterjoinOuterjoinExample:OuterjoinR=(AB)S=(BC)12234567(1,2)joinswith(2,3),buttheothertwotuplesare