Slide 1

Slide 1 text

Gay Marriage! From a database engineering perspective @lizTheDeveloper Adapted from an essay by Sam Hughes @ qntm.org/gay Friday, March 15, 13

Slide 2

Slide 2 text

Friday, March 15, 13

Slide 3

Slide 3 text

What is Marriage? Friday, March 15, 13

Slide 4

Slide 4 text

Love? Friday, March 15, 13

Slide 5

Slide 5 text

Childbearing? Friday, March 15, 13

Slide 6

Slide 6 text

Sociological construct designed to make agricultural societies run smoother? Friday, March 15, 13

Slide 7

Slide 7 text

A Relationship Friday, March 15, 13

Slide 8

Slide 8 text

A Relationship... • Recognized by the state Friday, March 15, 13

Slide 9

Slide 9 text

A Relationship... • Recognized by the state • That affords certain legal rights Friday, March 15, 13

Slide 10

Slide 10 text

A Relationship... • Recognized by the state • That affords certain legal rights • Defines common property Friday, March 15, 13

Slide 11

Slide 11 text

A Relationship... • Recognized by the state • That affords certain legal rights • Defines common property • Automagically determines parentage of children created while in the relationship. Friday, March 15, 13

Slide 12

Slide 12 text

That’s all we track. Friday, March 15, 13

Slide 13

Slide 13 text

That’s all we track. From a database engineering perspective. Friday, March 15, 13

Slide 14

Slide 14 text

Everything else.... Friday, March 15, 13

Slide 15

Slide 15 text

Everything else.... is beyond the scope of this talk. Friday, March 15, 13

Slide 16

Slide 16 text

How to store a relationship? Friday, March 15, 13

Slide 17

Slide 17 text

Quick Vocabulary • Entities • Relationship • Metadata • Key Friday, March 15, 13

Slide 18

Slide 18 text

Foreign Keys • Every entity has an ID • Other entities reference that ID Friday, March 15, 13

Slide 19

Slide 19 text

“Good Enough for Government Work” `males` - `id` - `forename` - `surname` - `birthdate` - `wife_id` (foreign key references column `females`.`id`, may be NULL if male is unmarried) `females` - `id` - `forename` - `surname` - `birthdate` - `husband_id` (foreign key references column `males`.`id`, may be NULL if female is unmarried) Friday, March 15, 13

Slide 20

Slide 20 text

Problem? • Bad Referential Integrity • Relationships can be one-way • Duplicates data • No metadata about relationship • Lots of other things Friday, March 15, 13

Slide 21

Slide 21 text

Sexist Database Design `males` - `id` - `forename` - `surname` - `birthdate` - `wife_id` (unique foreign key references column `females`.`id`, may be NULL if male is unmarried) `females` - `id` - `forename` - `surname` - `birthdate` Friday, March 15, 13

Slide 22

Slide 22 text

Friday, March 15, 13

Slide 23

Slide 23 text

Serious problems • Mind-bogglingly sexist • But slightly better, from an engineering perspective (shockingly.) • Still have a lack of metadata Friday, March 15, 13

Slide 24

Slide 24 text

Sexism with Metadata `males` - `id` - `forename` - `surname` - `birthdate` - `wife_id` (foreign key references column `females`.`id`, may be NULL if male is unmarried) - `marriage_date` (may be NULL if male is unmarried) - `divorce_date` (may be NULL if male is unmarried or married but not yet divorced) `females` - `id` - `forename` - `surname` - `birthdate` Friday, March 15, 13

Slide 25

Slide 25 text

Friday, March 15, 13

Slide 26

Slide 26 text

Problem? • Still sexist! • Also, men can only be married/divorced once. • “Flat” data presents these problems. Friday, March 15, 13

Slide 27

Slide 27 text

So... what do we do? Friday, March 15, 13

Slide 28

Slide 28 text

Relationship Tables `males` - `id` - `forename` - `surname` - `birthdate` `females` - `id` - `forename` - `surname` - `birthdate` `marriages` - `id` - `husband_id` (foreign key references column `males`.`id`) - `wife_id` (foreign key references column `females`.`id`) - `marriage_date` - `divorce_date` (NULL if marriage not ended) Friday, March 15, 13

Slide 29

Slide 29 text

Storing a relationship makes sense. Friday, March 15, 13

Slide 30

Slide 30 text

But we still have problems • Still sexist • Separating genders doesn’t make sense. Friday, March 15, 13

Slide 31

Slide 31 text

If two entities are equal (like men and women) then there is no reason to stratify them. Friday, March 15, 13

Slide 32

Slide 32 text

We are all humans. `humans` - `id` - `forename` - `surname` - `birthdate` - `sex` ("male" or "female") `marriages` - `id` - `partner_1_id` (foreign key references column `humans`.`id`) - `partner_2_id` (foreign key references column `humans`.`id`) - `marriage_date` - `divorce_date` (NULL if marriage not ended) Friday, March 15, 13

Slide 33

Slide 33 text

Problems? • Unary marriages are now possible - you can marry yourself. • The “sex” column is more limiting than it seems. Friday, March 15, 13

Slide 34

Slide 34 text

“There’s gonna be a lot more guys with makeup this millennium” - Eddie Izzard `humans` - `id` - `forename` - `surname` - `birthdate` - `sex_id` (foreign key references column `sexes`) `marriages` - `id` - `partner_1_id` (foreign key references column `humans`.`id`) - `partner_2_id` (foreign key references column `humans`.`id`) - `marriage_date` - `divorce_date` (NULL if marriage not ended) `sexes` - `id` - `string` Friday, March 15, 13

Slide 35

Slide 35 text

What is Sex/Gender? Friday, March 15, 13

Slide 36

Slide 36 text

`humans` - `id` - `forename` - `surname` - `birthdate` - `sex_id` (foreign key references column `sexes`) - `gender_id` (foreign key references column `genders`) `marriages` - `id` - `partner_1_id` (foreign key references column `humans`.`id`) - `partner_2_id` (foreign key references column `humans`.`id`) - `marriage_date` - `divorce_date` (NULL if marriage not ended) `sexes` - `id` - `string` `genders` - `id` - `string` Gender is a Spectrum Friday, March 15, 13

Slide 37

Slide 37 text

Existential Crisis mode! Friday, March 15, 13

Slide 38

Slide 38 text

Let’s just forget about it. `humans` - `id` - `forename` - `surname` - `birthdate` `marriages` - `id` - `partner_1_id` (foreign key references column `humans`.`id`) - `partner_2_id` (foreign key references column `humans`.`id`) - `marriage_date` - `divorce_date` (NULL if marriage not ended) Friday, March 15, 13

Slide 39

Slide 39 text

We’re done, right? Please oh please let us be done. Friday, March 15, 13

Slide 40

Slide 40 text

Friday, March 15, 13

Slide 41

Slide 41 text

Relationships are discrete entities, but so are marriage partners. Friday, March 15, 13

Slide 42

Slide 42 text

Let’s take it slowly. `humans` - `id` - `forename` - `surname` - `birthdate` `marriages` - `id` - `marriage_date` - `divorce_date` (NULL if marriage not ended) `marriage_partners` - `id` - `human_id` (foreign key references column `humans`.`id`) - `marriage_id` (foreign key references column `marriages`.`id`) Friday, March 15, 13

Slide 43

Slide 43 text

Problems? • What if a human joins the marriage after it begins? From a database engineering perspective. Friday, March 15, 13

Slide 44

Slide 44 text

It’s all about metadata `humans` - `id` - `forename` - `surname` - `birthdate` `marriages` - `id` `marriage_partners` - `id` - `human_id` (foreign key references column `humans`.`id`) - `marriage_id` (foreign key references column `marriages`.`id`) - `marriage_date` - `divorce_date` (NULL if still in marriage) Friday, March 15, 13

Slide 45

Slide 45 text

Friday, March 15, 13

Slide 46

Slide 46 text

Marriage == Graph Theory Friday, March 15, 13

Slide 47

Slide 47 text

Intransitive Marriage Friday, March 15, 13

Slide 48

Slide 48 text

Non-communicative Marriage Friday, March 15, 13

Slide 49

Slide 49 text

Architecture Astronauts never get married Friday, March 15, 13