Skip to content

Commit

Permalink
Update Tue Jun 8 18:22:03 PDT 2021
Browse files Browse the repository at this point in the history
  • Loading branch information
zedchance committed Jun 9, 2021
1 parent 39bff72 commit da3163e
Show file tree
Hide file tree
Showing 570 changed files with 57,579 additions and 1,781 deletions.
6 changes: 5 additions & 1 deletion content/CS134/CS134-lecture-20210607.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: "CS134-lecture-20210607"
# date: 2021-06-07T13:42:23-07:00
draft: false
bookToc: true
tags: ["ER model", "relational database"]
tags: ["ER model", "relational model"]
---

## ER model exercise cont.
Expand Down Expand Up @@ -38,6 +38,10 @@ Add this assignment into the weekly hw upload.

## Relational data model and relational database constraints

{{< hint info >}}
File: [*Ch 3 slides*](/notes/134-3.pdf)
{{< /hint >}}

![image_2021-06-07-14-57-30](/notes/image_2021-06-07-14-57-30.png)
![image_2021-06-07-15-00-17](/notes/image_2021-06-07-15-00-17.png)

Expand Down
153 changes: 153 additions & 0 deletions content/CS134/CS134-lecture-20210608.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
---
title: "CS134-lecture-20210608"
# date: 2021-06-08T16:12:49-07:00
draft: false
bookToc: true
tags: ["relational model", "keys"]
---

## RE assignment 1

`account_number` is a unique value.

## Relational model cont.

### State cont.

![image_2021-06-08-16-14-58](/notes/image_2021-06-08-16-14-58.png)

```
R(color, bit)
dom(color) = {blue, green, red}
dom(bit) = {0, 1}
```

color | bit
--- | ---
blue | 0
blue | 1
green | 0
green | 1
red | 0
red | 1

This is all the possible combinations, but lets say we have a state like

color | bit
--- | ---
blue | 1
green | 0

Which visualizes that the state is a subset of all possible combinations.

### Specifying an attribute's value

![image_2021-06-08-16-23-38](/notes/image_2021-06-08-16-23-38.png)

### Constraints

![image_2021-06-08-16-22-51](/notes/image_2021-06-08-16-22-51.png)

As a programmer we don't have much of selection when it comes to model-based constraints.

![image_2021-06-08-16-22-58](/notes/image_2021-06-08-16-22-58.png)

DDL = date definition language

{{< hint info >}}
Note: We are not currently covering data dependencies.
{{< /hint >}}

![image_2021-06-08-16-37-49](/notes/image_2021-06-08-16-37-49.png)
![image_2021-06-08-16-38-40](/notes/image_2021-06-08-16-38-40.png)

### Key constraints

![image_2021-06-08-16-39-11](/notes/image_2021-06-08-16-39-11.png)

Versus a key, superkeys do not have to be minimal.

![image_2021-06-08-16-49-17](/notes/image_2021-06-08-16-49-17.png)

- `{ssn, name}` is a superkey
- `{building, room_no}` is a key, and a superkey

True or false

- Any superkey is a key
- false
- Any key is a superkey
- true

### Primary key

![image_2021-06-08-16-59-41](/notes/image_2021-06-08-16-59-41.png)

We have two candidate keys `license_number` and `engine_serial_number`.
We will need to pick 1 to be the primary key.

![image_2021-06-08-17-00-18](/notes/image_2021-06-08-17-00-18.png)

{{< hint info >}}
Note on notation in relational model: we only underline the primary key.
{{< /hint >}}

### Constraints on null values

![image_2021-06-08-17-03-55](/notes/image_2021-06-08-17-03-55.png)

### Entity integrity constraint

![image_2021-06-08-17-07-14](/notes/image_2021-06-08-17-07-14.png)

### Multiple relations – referential integrity constraints

![image_2021-06-08-17-08-46](/notes/image_2021-06-08-17-08-46.png)

### Foreign keys

![image_2021-06-08-17-11-11](/notes/image_2021-06-08-17-11-11.png)

Foreign keys can be

- 1 attributes
- or, {{<k>}} n {{</k>}} attributes

The foreign key must

- have the same domain as the primary keys on the *other* schema.
- obey `t1[foreign] = t2[primary]`

![image_2021-06-08-17-15-00](/notes/image_2021-06-08-17-15-00.png)
![image_2021-06-08-17-15-20](/notes/image_2021-06-08-17-15-20.png)

`DNO` {{<k>}} \to {{</k>}} `DNUMBER` is a foreign key with 1 attribute

![image_2021-06-08-17-18-52](/notes/image_2021-06-08-17-18-52.png)

Remember, to be a foreign key, we need to verify that `DNO` and `DNUMBER` have the same domain.
They do not have to have the same name.

If we change the requirement so that employees don't have to work for a department, the keys must reference to existing attributes:

![image_2021-06-08-17-21-41](/notes/image_2021-06-08-17-21-41.png)

But if we have an employee that doesn't have a department, we must put a null value:

![image_2021-06-08-17-22-00](/notes/image_2021-06-08-17-22-00.png)

Another example of a foreign key:

![image_2021-06-08-17-24-42](/notes/image_2021-06-08-17-24-42.png)

Notice that foreign keys create duplication among tuples.

![image_2021-06-08-17-28-17](/notes/image_2021-06-08-17-28-17.png)
![image_2021-06-08-18-00-50](/notes/image_2021-06-08-18-00-50.png)

### Application based constraints

![image_2021-06-08-18-09-29](/notes/image_2021-06-08-18-09-29.png)

Triggers and assertions are part of SQL.

4 changes: 2 additions & 2 deletions content/CS152/CS152-lecture-20210604.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ We can compose these 3 operators to scramble bits (and is invertible):
uint32_t scramble(uint32_t x)
{
x = x ^ 0x1AFE9B3A; // xor by random constant
x = x <<< 12;
x = x << 12;
x = x + 0x2783AFBC; // add random constant
return x;
}
Expand All @@ -158,7 +158,7 @@ We could easily write the invertible function to undo these operations:
uint32_t unscramble(uint32_t x)
{
x = x - 0x2783AFBC; // sub random constant
x = x >>> 12;
x = x >> 12;
x = x ^ 0x1AFE9B3A; // xor by random constant
return x;
}
Expand Down
13 changes: 9 additions & 4 deletions content/CS152/CS152-lecture-20210607.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ To tell if the cipher is truly random looking, we can use distinguishing games:

- The distinguisher (could be adversary) is given a black box, with {{<k>}} A {{</k>}} or {{<k>}} B {{</k>}} in it (equally likely).
- The distinguisher follows an algorithm and guesses {{<k>}} A {{</k>}} or {{<k>}} B {{</k>}}.
- {{<k>}} \text{advantage} = P(\text{ guess is right }) - P(\text{ guess is wrong} ) \\{{</k>}}
{{<k>}}\text{advantage} = P(\text{guess } A \mid \text{box is } A) - P(\text{ guess } A \mid \text{box is } B) {{</k>}}

{{<k display>}}
\begin{aligned}
\text{advantage} &= P(\text{ guess is right }) - P(\text{ guess is wrong} ) \\
&= P(\text{guess } A \mid \text{box is } A) - P(\text{ guess } A \mid \text{box is } B)
\end{aligned}
{{</k>}}

If our strategy was to **always** guess {{<k>}} A {{</k>}}, then
{{<k>}} \text{advantage} = 1 - 1 = 0 {{</k>}}.
Expand Down Expand Up @@ -160,8 +165,8 @@ for i from 0 to q:
y = f(j)
if x == y:
guess "function"
else:
guess "permutation"
else:
guess "permutation"
```

{{<k display>}}
Expand Down

0 comments on commit da3163e

Please sign in to comment.