+ All Categories
Home > Documents > The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select...

The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select...

Date post: 12-Mar-2020
Category:
Upload: others
View: 18 times
Download: 0 times
Share this document with a friend
35
The Mother of All Query Languages: SQL in Modern Times @MarkusWinand • @ModernSQL http://www.almaden.ibm.com/cs/people/chamberlin/sequel-1974.pdf
Transcript
Page 1: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

The Mother of All Query Languages: SQL in Modern Times

@MarkusWinand • @ModernSQL

http://www.almaden.ibm.com/cs/people/chamberlin/sequel-1974.pdf

Page 2: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

1974 1992

Page 3: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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

Page 4: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

SQL-92 — Tied to the Relational Idea

Relational Data Model‣ “Atomic” types (domain)

A B C

Page 5: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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

Page 6: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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

Page 7: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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

Page 8: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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

Page 9: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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

Page 10: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

1992 1999

Page 11: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

https://www.wiscorp.com/DBMS_-_GreatNews-TheRelationalModelIsDead_-_paper_-_sam.pdf

Page 12: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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

Page 13: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

Relational Model?

Chris DateDate on Database: Writings 2000-2006

SQL:1999 — Escaping the Relational Cage

?I was as confused as anyone else

Page 14: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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!

Page 15: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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!

Page 16: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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!

Page 17: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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!

Page 18: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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!

Page 19: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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!

Page 20: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

SQL:1999 — Recursion

Page 21: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

SQL:1999 — Recursion

Page 22: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

SQL:1999 — Recursion

Page 23: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

SQL:1999 — Recursion

SELECTt.id,t.parentFROMtWHEREt.id=?UNIONALLSELECTt.id,t.parentFROMtWHEREt.parent=?

Page 24: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

SQL:1999 — Recursion

SELECTt.id,t.parentFROMtWHEREt.id=?UNIONALLSELECTt.id,t.parentFROMtWHEREt.parent=?

Page 25: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

SQL:1999 — Recursion

SELECTt.id,t.parentFROMtWHEREt.id=?UNIONALLSELECTt.id,t.parentFROMtWHEREt.parent=?

Page 26: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

SQL:1999 — Recursion

WITHRECURSIVEprev(id,parent)AS(

)

SELECTt.id,t.parentFROMtWHEREt.id=?UNIONALLSELECTt.id,t.parentFROMtJOINprevONt.parent=prev.id

SELECT*FROMprev

Page 27: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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

Page 28: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

1999 2016

Page 29: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

SQL:2016 — JSON

http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip

Page 30: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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

Page 31: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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

Page 32: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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

Page 33: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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

Page 34: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

SQL:2016 — JSON1999

2001

2003

2005

2007

2009

2011

2013

2015

2017

MariaDB8.0 MySQL

PostgreSQLSQLiteDB2 LUW

12cR1 OracleSQL Server

Page 35: The Mother of All Query Languages: SQL in Modern …...SQL/JSON Path ‣Query language to select elements from a JSON document ‣Defined in the SQL standard SQL:2016 — JSON 1999

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


Recommended