Upload
others
View
35
Download
0
Embed Size (px)
Citation preview
The Mother of All Query Languages: SQL in Modern Times
@MarkusWinand • @ModernSQL
http://www.almaden.ibm.com/cs/people/chamberlin/sequel-1974.pdf
1974 1992
SQL-92 — Tied to the Relational Idea
Relational Data Model‣ “Atomic” types (domain)
Atom image: https://commons.wikimedia.org/wiki/File:Stylised_atom_with_three_Bohr_model_orbits_and_stylised_nucleus.png
SQL-92 — Tied to the Relational Idea
Relational Data Model‣ “Atomic” types (domain)
A B C
SQL-92 — Tied to the Relational Idea
Relational Data Model‣ “Atomic” types (domain)‣Schema independent of
processing purposes ‣ “Normalization”
A B C C D B E
SQL-92 — Tied to the Relational Idea
Relational Data Model‣ “Atomic” types (domain)‣Schema independent of
processing purposes ‣ “Normalization”
Relational Operations ‣Transform data for
each particularprocessing purposes ‣JOIN, UNION, nesting, …
A B C C D B E A B C D E
SQL-92 — Tied to the Relational Idea
Relational Data Model‣ “Atomic” types (domain)‣Schema independent of
processing purposes ‣ “Normalization”
Relational Operations ‣Transform data for
each particularprocessing purposes ‣JOIN, UNION, nesting, …
A B C C D B E A B C D E
A B E
SQL-92 — Tied to the Relational Idea
Relational Data Model‣ “Atomic” types (domain)‣Schema independent of
processing purposes ‣ “Normalization”
Relational Operations ‣Transform data for
each particularprocessing purposes ‣JOIN, UNION, nesting, …
A B C C D B E A B C D E
A B E
C D E
SQL-92 — Tied to the Relational Idea
Relational Data Model‣ “Atomic” types (domain)‣Schema independent of
processing purposes ‣ “Normalization”
Relational Operations ‣Transform data for
each particularprocessing purposes ‣JOIN, UNION, nesting, …
A B C C D B E A B C D E
A B E
C D E
1992 1999
https://www.wiscorp.com/DBMS_-_GreatNews-TheRelationalModelIsDead_-_paper_-_sam.pdf
SQL:1999 — Escaping the Relational Cage
To say that these SQL:1999 extensions are mere “extended interpretations” of the relational data modelis 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
of 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
Relational Model?
Chris DateDate on Database: Writings 2000-2006
SQL:1999 — Escaping the Relational Cage
?I was as confused as anyone else
Relational Model?
Chris DateDate 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 lightDomains Can Contain Anything!
Relational Model?‣ Introduced rich types
Chris DateDate 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 lightDomains Can Contain Anything!
Relational Model?‣ Introduced rich types‣arrays
Chris DateDate 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 lightDomains Can Contain Anything!
Relational Model?‣ Introduced rich types‣arrays‣Nested tables (multiset)
Chris DateDate on Database: Writings 2000-2006
SQL:1999 — Escaping the Relational Cage
A B
[ , ][ ][]
CC D
C D
C D
?I was as confused as anyone else By the early 1990s, however,
I’d seen the lightDomains Can Contain Anything!
Relational Model?‣ Introduced rich types‣arrays‣Nested tables (multiset)‣composite types (objects)
Chris DateDate 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 lightDomains Can Contain Anything!
Relational Model?‣ Introduced rich types‣arrays‣Nested tables (multiset)‣composite types (objects)
Non-Relational Operations ‣ Introduced recursive
queries that processtheir own output ‣Transitive closure
Chris DateDate 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 lightDomains Can Contain Anything!
SQL:1999 — Recursion
SQL:1999 — Recursion
SQL:1999 — Recursion
SQL:1999 — Recursion
SELECTt.id,t.parentFROMtWHEREt.id=?UNIONALLSELECTt.id,t.parentFROMtWHEREt.parent=?
SQL:1999 — Recursion
SELECTt.id,t.parentFROMtWHEREt.id=?UNIONALLSELECTt.id,t.parentFROMtWHEREt.parent=?
SQL:1999 — Recursion
SELECTt.id,t.parentFROMtWHEREt.id=?UNIONALLSELECTt.id,t.parentFROMtWHEREt.parent=?
SQL:1999 — Recursion
WITHRECURSIVEprev(id,parent)AS(
)
SELECTt.id,t.parentFROMtWHEREt.id=?UNIONALLSELECTt.id,t.parentFROMtJOINprevONt.parent=prev.id
SELECT*FROMprev
SQL:1999 — Recursion
1999
2001
2003
2005
2007
2009
2011
2013
2015
2017
5.1 10.2 MariaDB8.0 MySQL
8.4 PostgreSQL3.8.3[0] SQLite
7.0 DB2 LUW11gR2 Oracle
2005 SQL Server[0]Only for top-level SELECT statements
1999 2016
SQL:2016 — JSON
http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
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
SELECT*FROMtbl,JSON_TABLE(jsoncol,'$[*]'COLUMNS(idINTPATH'$.id',a1VARCHAR(…)PATH'$.a1'))r
SQL:2016 — JSON
[{"id":42,"a1":"foo"},{"id":43,"a1":"bar"}]
id a142 foo43 bar
SELECT*FROMtbl,JSON_TABLE(jsoncol,'$[*]'COLUMNS(idINTPATH'$.id',a1VARCHAR(…)PATH'$.a1'))r
SQL:2016 — JSON
[{"id":42,"a1":"foo"},{"id":43,"a1":"bar"}]
id a142 foo43 bar
SQL/JSON Path ‣ Query language to
select elements from a JSON document ‣Defined in the
SQL standard
SELECT*FROMtbl,JSON_TABLE(jsoncol,'$[*]'COLUMNS(idINTPATH'$.id',a1VARCHAR(…)PATH'$.a1'))r
SQL:2016 — JSON
[{"id":42,"a1":"foo"},{"id":43,"a1":"bar"}]
id a142 foo43 bar
SQL/JSON Path ‣ Query language to
select elements from a JSON document ‣Defined in the
SQL standard
SQL:2016 — JSON1999
2001
2003
2005
2007
2009
2011
2013
2015
2017
MariaDB8.0 MySQL
PostgreSQLSQLiteDB2 LUW
12cR1 OracleSQL Server
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