复试877学长数据库003课件14版5algebraic_第1页
复试877学长数据库003课件14版5algebraic_第2页
复试877学长数据库003课件14版5algebraic_第3页
复试877学长数据库003课件14版5algebraic_第4页
复试877学长数据库003课件14版5algebraic_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Chapter 5 Algebraic and Logical Query Languages 第5章 代数和逻辑查询语言5.1 Relational Operations on BagsWhat is a bag?A bag means a relation that may ( or may not ) have duplicate tuples.A set means a relation without duplicate tuples.Why bags?SQL, the most important query language for relational databases, i

2、s actually a bag language.Some operations, like projection, are much more efficient on bags than sets.5.1 Relational Operations on BagsSelection applies to each tuple, so its effect on bags is like its effect on sets.Projection also applies to each tuple, but as a bag operator, we do not eliminate d

3、uplicates.Products and joins are done on each pair of tuples, so duplicates in bags have no effect on how we operate.Example: Bag SelectionR(A,B )125612A+B5 (R) =AB1212Example: Bag ProjectionR(A,B ) 125612 A (R) =A151Example: Bag ProductR(A,B )S(B,C )1234567812R S =AR.BS.BC123412785634567812341278Ex

4、ample: Bag Theta-JoinR(A,B )S(B,C )1234567812R R.BS.B S =AR.BS.BC12341278567812341278Bag UnionAn element appears in the union of two bags the sum of the number of times it appears in each bag.Example: 1,2,1 1,1,2,3,1 = 1,1,1,1,1,2,2,3Bag IntersectionAn element appears in the intersection of two bags

5、 the minimum of the number of times it appears in either.Example: 1,2,1,1 1,2,1,3 = 1,1,2.Bag DifferenceAn element appears in the difference A B of bags as many times as it appears in A, minus the number of times it appears in B.But never less than 0 times.Example: 1,2,1,1 1,2,3 = 1,1.Duplicate Elim

6、inationA BR1 22 31 2 (R)A B1 22 3Aggregation OperatorsSUMAVGMINMAXCOUNTA B1 22 31 2 SUM(B)=2+3+2=7Grouping OperatorsIf there is grouping, then the aggregation is within groups.L(R)Constructing method:Partition the tuples of R into groups. Each group consists of all tuples having one particular assig

7、nment of values to the grouping attributes in the list L. If there are no grouping attributes, the entire relation R is one group.For each group, produce one tuple consisting of:The grouping attributes values for that group andThe aggregations, over all tuples of that group, for the aggregated attri

8、butes on list L.starName, MIN(year)minYear, COUNT(titile) ctTitle(StarsIn)Renaming Operator and Sorting OperatorRenaming: Sorting: L(R)AB(R) A+BC(R)A(R) A, B (R)OuterjoinSuppose we join R S.A tuple of R that has no tuple of S with which it joins is said to be dangling.Similarly for a tuple of S.Outerjoin preserves dangling tuples by padding them with a special NULL symbol in the result.Left outerjoin R S.Right outerjoin R S.Full outerjoin R S.LRLeft OuterjoinOuterjoinRight OuterjoinOuterjoinFull OuterjoinOuterjoinExample: OuterjoinR = ( AB

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论