SLIDE 1 The Mother of All Query Languages: SQL in Modern Times
@MarkusWinand • @ModernSQL
http://www.almaden.ibm.com/cs/people/chamberlin/sequel-1974.pdf
SLIDE 2
1974 1992
SLIDE 3 SQL-92 — Tied to the Relational Idea
Relational Data Model
Atom image: https://commons.wikimedia.org/wiki/File:Stylised_atom_with_three_Bohr_model_orbits_and_stylised_nucleus.png
SLIDE 4 SQL-92 — Tied to the Relational Idea
Relational Data Model
A B C
SLIDE 5 SQL-92 — Tied to the Relational Idea
Relational Data Model
- “Atomic” types (domain)
- Schema independent of
processing purposes
A B C C D B E
SLIDE 6 SQL-92 — Tied to the Relational Idea
Relational Data Model
- “Atomic” types (domain)
- Schema independent of
processing purposes
Relational Operations
each particular
processing purposes
A B C C D B E A B C D E
SLIDE 7 SQL-92 — Tied to the Relational Idea
Relational Data Model
- “Atomic” types (domain)
- Schema independent of
processing purposes
Relational Operations
each particular
processing purposes
A B C C D B E
A B C D E
A B E
SLIDE 8 SQL-92 — Tied to the Relational Idea
Relational Data Model
- “Atomic” types (domain)
- Schema independent of
processing purposes
Relational Operations
each particular
processing purposes
A B C C D B E
A B C D E A B E
C D E
SLIDE 9 SQL-92 — Tied to the Relational Idea
Relational Data Model
- “Atomic” types (domain)
- Schema independent of
processing purposes
Relational Operations
each particular
processing purposes
A B C C D B E
A B C D E A B E C D E
SLIDE 10
1992 1999
SLIDE 11 https://www.wiscorp.com/DBMS_-_GreatNews-TheRelationalModelIsDead_-_paper_-_sam.pdf
SLIDE 12 SQL:1999 — Escaping the Relational Cage
To say that these SQL:1999 extensions are mere
“extended interpretations” of the relational data model
is like saying that an intercontinental ballistic missile is
merely an “extended interpretation” of a spear. With SQL/99 you can get the best of both worlds and
- f course, you can get the worst of both worlds.
It’s up to the database practitioners to do the right thing.
https://www.wiscorp.com/DBMS_-_GreatNews-TheRelationalModelIsDead_-_paper_-_sam.pdf
SLIDE 13 Relational Model?
Chris Date
Date on Database: Writings 2000-2006
SQL:1999 — Escaping the Relational Cage
?
I was as confused as anyone else
SLIDE 14 Relational Model?
Chris Date
Date on Database: Writings 2000-2006
SQL:1999 — Escaping the Relational Cage
? I was as confused as anyone else By the early 1990s, however,
I’d seen the light
Domains Can Contain Anything!
SLIDE 15 Relational Model?
Chris Date
Date on Database: Writings 2000-2006
SQL:1999 — Escaping the Relational Cage
? I was as confused as anyone else By the early 1990s, however,
I’d seen the light
Domains Can Contain Anything!
SLIDE 16 Relational Model?
- Introduced rich types
- arrays
Chris Date
Date on Database: Writings 2000-2006
SQL:1999 — Escaping the Relational Cage
A B
[ , ] [ ] []
? I was as confused as anyone else By the early 1990s, however,
I’d seen the light
Domains Can Contain Anything!
SLIDE 17 Relational Model?
- Introduced rich types
- arrays
- Nested tables (multiset)
Chris Date
Date on Database: Writings 2000-2006
SQL:1999 — Escaping the Relational Cage
A B
[ , ] [ ] []
C
C D C D C D
? I was as confused as anyone else By the early 1990s, however,
I’d seen the light
Domains Can Contain Anything!
SLIDE 18 Relational Model?
- Introduced rich types
- arrays
- Nested tables (multiset)
- composite types (objects)
Chris Date
Date on Database: Writings 2000-2006
SQL:1999 — Escaping the Relational Cage
A B C D
[ , ]
{x: , y: }
[ ]
{x: , y: }
[]
{x: , y: }
C D C D C D
? I was as confused as anyone else By the early 1990s, however,
I’d seen the light
Domains Can Contain Anything!
SLIDE 19 Relational Model?
- Introduced rich types
- arrays
- Nested tables (multiset)
- composite types (objects)
Non-Relational Operations
queries that process
their own output
Chris Date
Date on Database: Writings 2000-2006
SQL:1999 — Escaping the Relational Cage
? I was as confused as anyone else By the early 1990s, however,
I’d seen the light
Domains Can Contain Anything!
SLIDE 20
SQL:1999 — Recursion
SLIDE 21
SQL:1999 — Recursion
SLIDE 22
SQL:1999 — Recursion
SLIDE 23
SQL:1999 — Recursion
SELECT t.id, t.parent FROM t WHERE t.id = ? UNION ALL SELECT t.id, t.parent FROM t WHERE t.parent = ?
SLIDE 24
SQL:1999 — Recursion
SELECT t.id, t.parent FROM t WHERE t.id = ? UNION ALL SELECT t.id, t.parent FROM t WHERE t.parent = ?
SLIDE 25
SQL:1999 — Recursion
SELECT t.id, t.parent FROM t WHERE t.id = ? UNION ALL SELECT t.id, t.parent FROM t WHERE t.parent = ?
SLIDE 26
SQL:1999 — Recursion
WITH RECURSIVE prev (id, parent) AS ( )
SELECT t.id, t.parent FROM t WHERE t.id = ? UNION ALL SELECT t.id, t.parent FROM t JOIN prev ON t.parent = prev.id SELECT * FROM prev
SLIDE 27 SQL:1999 — Recursion
1 9 9 9 2 1 2 3 2 5 2 7 2 9 2 1 1 2 1 3 2 1 5 2 1 7
5.1 10.2
MariaDB
8.0 MySQL 8.4
PostgreSQL
3.8.3
[0]
SQLite
7.0
DB2 LUW
11gR2
Oracle
2005
SQL Server
[0]Only for top-level SELECT statements
SLIDE 28
1999 2016
SLIDE 29 SQL:2016 — JSON
http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
SLIDE 30 SQL:2016 — JSON
id a1 42 foo 43 bar [ { "id": 42, "a1": "foo" }, { "id": 43, "a1": "bar" } ]
http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
SLIDE 31 SELECT * FROM tbl , JSON_TABLE ( jsoncol , '$[*]' COLUMNS ( id INT PATH '$.id' , a1 VARCHAR(…) PATH '$.a1' ) ) r
SQL:2016 — JSON
[ { "id": 42, "a1": "foo" }, { "id": 43, "a1": "bar" } ]
id a1 42 foo 43 bar
SLIDE 32 SELECT * FROM tbl , JSON_TABLE ( jsoncol , '$[*]' COLUMNS ( id INT PATH '$.id' , a1 VARCHAR(…) PATH '$.a1' ) ) r
SQL:2016 — JSON
[ { "id": 42, "a1": "foo" }, { "id": 43, "a1": "bar" } ]
id a1 42 foo 43 bar
SQL/JSON Path
select elements from a JSON document
SQL standard
SLIDE 33 SELECT * FROM tbl , JSON_TABLE ( jsoncol , '$[*]' COLUMNS ( id INT PATH '$.id' , a1 VARCHAR(…) PATH '$.a1' ) ) r
SQL:2016 — JSON
[ { "id": 42, "a1": "foo" }, { "id": 43, "a1": "bar" } ]
id a1 42 foo 43 bar
SQL/JSON Path
select elements from a JSON document
SQL standard
SLIDE 34 SQL:2016 — JSON
1999 2001 2003 2005 2007 2009 2011 2013 2015 2017
MariaDB
8.0
MySQL PostgreSQL SQLite DB2 LUW
12cR1
Oracle SQL Server
SLIDE 35 SQL has evolved
beyond the relational idea If you use SQL for CRUD operations only, you are doing it wrong A lot has
happened since SQL-92
https://modern-sql.com
@ModernSQL by @MarkusWinand