Relational Algebra(数据库关系代数)

article/2025/8/3 23:26:10

目录

What is an “Algebra”

What is Relational Algebra?

Core Relational Algebra

Selection

Projection

Extended Projection

Product(笛卡尔积)

Theta-Join

Natural Join

Renaming

Building Complex Expressions

Sequences of Assignments

Expressions in a Single Assignment

Expression Trees

Example: Tree for a Query

Example: Self-Join

Operations on Bags


What is an “Algebra”

Mathematical system consisting of:

  • Operands --- variables or values from which new values can be constructed.(操作数,用于构建新值的变量或者值)

  • Operators --- symbols denoting procedures that construct new values from given values.(运算符,标志着从给定值创建新值的过程)

What is Relational Algebra?

  • An algebra whose operands are relations or variables that represent relations.(关系代数是操作数是关系或者是表示关系的变量)

  • Operators are designed to do the most common things that we need to do with relations in a database.

  • The result is an algebra that can be used as a query language for relations.(关系代数语言将会是数据库语言的基础)

Core Relational Algebra

  • Union, intersection, and difference.(并、交、差)

Usual set operations, but both operands must have the same relation schema.(两个操作数之间必须要有一样的关系模式)

  • Selection: picking certain rows.(也就是SQL中的WHERE)

  • Projection: picking certain columns.

  • Products and joins: compositions of relations.(笛卡尔积和连接:笛卡尔积是全组合、连接是条件组合)

  • Renaming of relations and attributes.

Selection

R_{1}:=\sigma _{C}(R_{2})
  • C is a condition (as in “if” statements) that refers to attributes of R2.

  • R1 is all those tuples of R2 that satisfy C.

这两个关系之间没有任何关系

Projection

R_{1}:=\pi _{L}(R_{2})
  • L is a list of attributes from the schema of R2.(L是R2关系模式中的一串属性)

  • R1 is constructed by looking at each tuple of R2, extracting the attributes on list L, in the order specified, and creating from those components a tuple for R1.(查看R2的属性列表,然后提取出L属性列表中的属性,然后按照特定顺序创建R1的元组)

  • Eliminate duplicate tuples, if any.(消除重复项)

Extended Projection

  • Using the same \pi _{L} operator, we allow the list L to contain arbitrary expressions(任意表达式) involving attributes:

  • Arithmetic on attributes, e.g., A+B->C.

  • Duplicate occurrences of the same attribute.

Product(笛卡尔积)

R_{3}:=R_{1}\times R_{2}

  • Pair each tuple t1 of R1 with each tuple t2 of R2.

  • Concatenation t1t2 is a tuple of R3.

  • Schema of R3 is the attributes of R1 and then R2, in order.

But beware attribute A of the same name in R1 and R2: use R1.A and R2.A.(如果R1、R2中有相同的属性使用R1.A和R2.A来进行区分)

Theta-Join

R_{3}:=R_{1}\bowtie _{C}R_{2}
  • Take the product R1 Χ R2.

  • Then apply \bowtie _{C} to the result.

  • As for σ, C can be any boolean-valued condition.(对于C来说,可以是任何布尔值的表达式)

Historic versions of this operator allowed only A \theta B, where \theta is = , <, etc.; hence the name “theta-join.”

Natural Join

  • A useful join variant (natural join) connects two relations by:
  • Equating(等值比较) attributes of the same name, and Projecting out one copy of each pair of equated attributes.(将等值属性的一组副本投影掉)
  • Denoted R3 := R1 R2.

Renaming

  • The ρ operator gives a new schema to a relation.
  • R_{1}:=\rho _{R1(A_{1}A_{2}...A_{n})}(R2) makes R1 be a relation with attributes A1,…,An and the same tuples as R2.
  • Simplified notation: R1(A_{1}A_{2}...A_{n}):=R2

Building Complex Expressions

Combine operators with parentheses and precedence rules.(通过括号或者优先运算规则对操作符进行组合)

Three notations, just as in arithmetic:

  • Sequences of assignment statements.

  • Expressions with several operators.

  • Expression trees.

Sequences of Assignments

  • Create temporary relation names.
  • Renaming can be implied by giving relations a list of attributes.
  • Example:
R3 := R1 C R2
can be written:
R4 := R1 Χ R2
R3 := σ C (R4)

Expressions in a Single Assignment

  • Example:

the theta-join R3 := R1 C R2

can be written:

R3 := σC (R1 Χ R2)

  • Precedence of relational operators:

  1. [σ, π, ρ] (highest).

  2. [Χ, ].

  3. .

  4. [, ]

Expression Trees

  • Leaves are operands --- either variables standing for relations or particular constant relations.(叶子结点是操作数,可以是标识关系的变量也可以是常量)

  • Interior nodes are operators, applied to their child or children.(内部结点是操作符,作用于子结点)

Example: Tree for a Query

Using the relations Bars(name, addr) and Sells(bar, beer, price), find the names of all the bars that are either on Maple St. or sell Bud for less than $3.

Example: Self-Join

Using Sells(bar, beer, price) , find the bars that sell two different beers at the same price.
Strategy :
  • by renaming, define a copy of Sells, called S(bar, beer1, price).
  • The natural join of Sells and S consists of quadruples (bar, beer, beer1, price)
  • such that the bar sells both beers at this price.

先通过重命名得到一个Sells的副本,然后将原表与副本进行自连接,自连接的条件是price相同,然后进行选择,最后投影出name

Operations on Bags

  • Selection 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 duplicates.

  • Products and joins are done on each pair of tuples, so duplicates in bags have no effect on how we operate.


http://www.hkcw.cn/article/VKdGlsHqCr.shtml

相关文章

操作系统:进程管理(王道+计算机操作系统)

第二章 进程与线程 2.1进程的概念、组成与特征 2.1.1 进程与程序的区别 ​ 1.程序&#xff1a;静态的&#xff0c;就是放在磁盘里的可执行文件&#xff0c;如&#xff1a;QQ.exe。 ​ 2.进程&#xff1a;动态的&#xff0c;是程序的一次执行过程&#xff0c;如&#xff1a;…

浅谈简历制作的四点注意事项

如大家所了解的&#xff0c;一份工作&#xff0c;往往是从制作一份简历开始。 对于新人来说&#xff0c;简历制作的注意事项&#xff0c;你又了解多少呢&#xff1f;下面一起来看看吧&#xff01; 简历字数&#xff1a;一封合格的简历字数大概在 350 词 – 650 词之间&#xf…

软考-数据库系统工程师-程序设计语言知识要点

小房学堂&#xff0c;程序设计语言知识要点 汇编、编译、解释系统的基础知识 计算机只能理解由0-1组成的指令&#xff0c;就像一个只会本国语言的人&#xff0c;他听不懂其他国家的语言 而程序员编程使用的是低级语言&#xff08;汇编语言&#xff09;或者高级语言如C、C、Jav…

6级翻译学习

找到一个中文句子先看中文句子的主谓宾&#xff0c;主系表 不会写的词不要写&#xff0c;不会影响得分&#xff0c;只要其他地方写对

【Rhino】【Python】adjust repeated column marks

#codingutf-8 import rhinoscriptsyntax as rs import re import System.Guiddef process_column_marks():# 获取目标图层中的所有文本对象layer_name "03 STR. DRAFT MEMBER::COLUMN MARK"text_objects rs.ObjectsByLayer(layer_name, True)if not text_objects o…

Goreplay最新版本的安装和简单使用

一&#xff1a;概述 Gor 是一个开源工具&#xff0c;用于捕获实时 HTTP 流量并将其重放到测试环境中&#xff0c;以便使用真实数据持续测试您的系统。它可用于提高对代码部署、配置更改和基础设施更改的信心。简单易用。 项目地址&#xff1a;buger/goreplay: GoReplay is an …

YOLOv5 环境配置指南

系统要求 Windows/Linux/MacOSNVIDIA GPU (推荐) 或 CPUPython 3.8CUDA 11.8 (如果使用 GPU) 安装步骤 1. 安装 Conda 如果还没有安装 Conda&#xff0c;请先从官网下载并安装 Miniconda。 2. 创建虚拟环境 # 创建名为 yolov5 的新环境&#xff0c;使用 Python 3.8 conda…

【算法应用】虚拟力算法VFA用于WSN覆盖,无人机网络覆盖问题

目录 1.虚拟力算法VFA2.WSN覆盖&无人机覆盖应用3.参考文献4.代码获取5.读者交流 1.虚拟力算法VFA 虚拟势场&#xff08;Virtual Potential Field&#xff09;最早因解决机器人路径规划及避障问题而被提出。它假设待优化个体会根据某种关系与周围的环境或其他个体产生力的作…

简历制作要精而不简

不得不说&#xff0c;不管是春招&#xff0c;还是秋招&#xff0c;我们在求职时&#xff0c;第一步便是制作一份简历。不得不承认&#xff0c;好的简历&#xff0c;就像一块敲门砖&#xff0c;能让面试官眼前一亮&#xff0c;让应聘成功的概率增添一分。 对于一个初次求职者来…

数据库管理与高可用-MySQL全量,增量备份与恢复

目录 #1.1MySQL数据库备份概述 1.1.1数据备份的重要性 1.1.2数据库备份类型 1.1.3常见的备份方法 #2.1数据库完全备份操作 2.1.1物理冷备份与恢复 2.1.2mysqldump备份与恢复 2.1.3MySQL增量备份与恢复 #3.1制定企业备份策略的思路 #4.1扩展&#xff1a;MySQL的GTID 4.1.1My…

论文解读 - 统一的多模态理解和生成模型综述(上)

一、 简要介绍 近年来&#xff0c;多模态理解模型和图像生成模型都取得了显著的进步。尽管各自取得了成功&#xff0c;这两个领域却独立发展&#xff0c;形成了独特的架构范式&#xff1a;基于自回归的架构主导了多模态理解&#xff0c;而基于扩散的模型则成为图像生成的基石…

核心机制:TCP 断开连接(四次挥手)

断开连接的四次挥手,可能是客户端主动发起的,也可能是服务端主动发起的 而三次握手,一定是客户端先发起的(倒果为因)(先发起的一方定义为客户端) 1.客户端告诉服务器,我要和你断开连接,请你把我删了 2.服务器回应"收到" 3.服务器告诉客户端,我也要和你断开连接,请…

WEBSTORM前端 —— 第3章:移动 Web —— 第3节:移动适配

目录 一、移动Web基础 1.谷歌模拟器 2.屏幕分辨率 3.视口 4.二倍图 二、适配方案 三、rem 适配方案 四、less 1.less – 简介 2.less – 注释 3.less – 运算 4.less – 嵌套 5.less – 变量 6.less – 导入 7.less – 导出 8.less – 禁止导出 五…

【笔记】MSYS2 安装 Python 构建依赖记录Cython + Ninja + Meson + meson-python

#工作记录 &#x1f4cc; 安装目标 为构建 Python C 扩展&#xff08;如 numpy&#xff09;安装必要依赖&#xff1a; CythonNinjaMeson meson-python ✅ 成功安装命令 pacman -S mingw-w64-x86_64-cython pacman -S mingw-w64-x86_64-ninja pacman -S mingw-w64-x86_64-me…

【染色归一化】staintools工具详讲

staintools工具原代码是没有GPU加速的,代码链接 运行速度较慢,因此,github上有研究者写了pytorch加速版本的staintools 本篇主要讲GPU加速版本的staintools工具的使用教程。 1.背景 目前的公开数据库中的WSI是由不同研究机构制作上传的,这导致WSI有很大的颜色差别,例如:…

历年中山大学计算机保研上机真题

历年中山大学计算机保研上机真题 2025中山大学计算机保研上机真题 2024中山大学计算机保研上机真题 2023中山大学计算机保研上机真题 在线测评链接&#xff1a;https://pgcode.cn/school 不连续1的子串 题目描述 给定一个数字 n n n&#xff0c;输出长度为 n n n 的 01…

历年山东大学计算机保研上机真题

历年山东大学计算机保研上机真题 2025山东大学计算机保研上机真题 2024山东大学计算机保研上机真题 2023山东大学计算机保研上机真题 在线测评链接&#xff1a;https://pgcode.cn/school 从1到100找质数 题目描述 从 1 1 1 到 100 100 100 中找出所有的质数。 输入格式 …

殷咏梅教授:OptiTROP-Breast05亮相2025 ASCO,中国原创TROP2 ADC为mTNBC一线治疗带来新希望

引言 抗体药物偶联物&#xff08;ADC&#xff09;以其精准杀伤特性&#xff0c;已成为乳腺癌治疗领域的探索热点。近年来&#xff0c;在全球ADC研发赛道中&#xff0c;中国的ADC力量正逐步崛起&#xff0c;乳腺癌领域首个中国原研、国际品质的TROP2 ADC芦康沙妥珠单抗脱颖而出&…

02.上帝之心算法用GPU计算提速50倍

本文介绍了上帝之心的算法及其Python实现&#xff0c;使用Python语言的性能分析工具测算性能瓶颈&#xff0c;将算法最耗时的部分重构至CUDA C语言在纯GPU上运行&#xff0c;利用GPU核心更多并行更快的优势显著提高算法运算速度&#xff0c;实现了结果不变的情况下将耗时缩短五…

latex 三线表-算法对比表

效果 导入包 \usepackage{booktabs} \usepackage{multirow}表格 \begin{table}[t]\caption{\textbf{Comparison of test results of various algorithms}\label{tab}}\centering\begin{tabular}{ccccc}\toprule\multirow{2}{*}{Algorithms} & \multirow{2}{*}{mAP} &…