版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年云南城市建设职业学院单招职业适应性考试题库及参考答案详解
- 2026年上海应用技术大学单招职业倾向性测试题库带答案详解(满分必刷)
- 2026年上海第二工业大学单招职业适应性考试题库附参考答案详解(能力提升)
- 2026年亳州职业技术学院单招职业技能测试题库及答案详解一套
- 2026年上海杉达学院单招职业适应性测试题库带答案详解(巩固)
- 2026年云南省曲靖市单招职业倾向性考试题库含答案详解(能力提升)
- 2026年仙桃职业学院单招职业倾向性测试题库及参考答案详解(新)
- 2026年伊犁职业技术学院单招职业倾向性测试题库及答案详解(网校专用)
- 2026年三亚城市职业学院单招综合素质考试题库参考答案详解
- 2026年云南理工职业学院单招职业适应性测试题库附参考答案详解(巩固)
- (人教2024版)数学三年级上册第6单元《分数的初步认识》大单元教学设计(新教材)
- 血乳酸在急危重症应用的急诊专家共识2025
- 嘉兴微型顶管施工方案
- 技术研发团队介绍
- 碳循环与碳减排课件
- 浙江省40m装配式预应力混凝土先简支后连续T梁上部结构通 用图(L=40m A=0° 连续T梁)2024
- 春节的传说故事(合集15篇)
- 顾客健康档案表
- 京津冀金融协同发展:测度、困境与优化路径
- 光伏电站电气设备检测维护-光伏逆变器的检测与维护(光伏电站运维)
- 《热轧生产智能管控技术要求》
评论
0/150
提交评论