资源描述:
《数据库系统英第三版课件2012版 Database Systems(5).ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、5AlgebraicandLogicalQueryLanguagesInthischapter,weextendtheset-basedalgebratobags,whichbetterreflectthewaytherelationalmodelisimplementedinpractice.Wealsoextendthealgebrasoitcanhandleseveralmoreoperations.5.1RelationalOperationsonBagsWhatisabag(包)?Abagme
2、ansarelationthatmay(ormaynot)haveduplicatetuples.Asetmeansarelationwithoutduplicatetuples.Whybags?SQL,themostimportantquerylanguageforrelationaldatabases,isactuallyabaglanguage.Someoperations,likeprojectionandunion,aremuchmoreefficientonbagsthansets.Supp
3、osethatRandSarebags,andthattupletappearsntimesinRandmtimesinS.BagUnionInthebagunionR∪S,tupletappearsn+mtimes.Example:{1,2,1}∪{1,1,2,3,1}={1,1,1,1,1,2,2,3}5.1.2Union,Intersection,andDifferenceofBagsBagIntersectionInthebagintersectionR∩S,tupletappearsmin(n
4、,m)times.Example:{1,2,1,1}∩{1,2,1,3}={1,1,2}5.1.2Union,Intersection,andDifferenceofBagsBagDifferenceInthebagDifferenceR–S,tupletappearsmax(0,n-m)times.Example:{1,2,1,1}–{1,2,3}={1,1}{1,2,3}–{1,2,1,1}={3}5.1.2Union,Intersection,andDifferenceofBagsAlgebrai
5、cLawsforBagsSome,butnotallalgebraiclawsthatholdforsetsalsoholdforbags.Example:R∪S=S∪R.However,thereareanumberofotherlawsthatholdwhenrelationalalgebraisappliedtosetsbutthatdonotholdwhenrelationsareinterpretedasbags.Example:S∪S=S(R∪S)–T=(R–T)∪(S–T)5.1.2Uni
6、on,Intersection,andDifferenceofBagsRAB125612πA(R)=A1515.1.3ProjectionofBagsProjectionappliestoeachtuple,butasabagoperator,wedonoteliminate(消除)duplicates.Example:RAB125612σA+B<5(R)=AB12125.1.4SelectiononBagsSelectionappliestoeachtuple,soitseffectonbagsisl
7、ikeitseffectonsets.Example:5.1.5ProductofBagsEachtupleofonerelationispairedwitheachtupleoftheother,regardlessofwhetheritisaduplicateornot.IfatuplerappearsinarelationRmtimes,andtuplesappearsntimesinrelationS,thenintheproductR×S,thetuplerswillappearm×ntime
8、s.Example:RABSBC1234567812R×S=AR.BS.BC1234127856345678123412785.1.5ProductofBags5.1.6JoinsofBagsWecompareeachtupleofonerelationwitheachtupleoftheother,decidewhetherornotthispairoftuplesjoinssuccessfully,andifsoweputtheresu