more than a query language sql in the 21st century
play

More Than a Query Language: SQL in the 21st Century Markus Winand, - PowerPoint PPT Presentation

More Than a Query Language: SQL in the 21st Century Markus Winand, winand.at SQL Renaissance Ambassador 1974 1992 SQL-92 Tied to the Relational Idea SQL-92 Tied to the Relational Idea Relational Data Model Atomic types


  1. SQL:1999 — LATERAL Lateral derived tables lift both limitations and can be correlated: “Derived table” means SELECT … it’s in the , ldt.* FROM/JOIN clause FROM t2 CROSS JOIN LATERAL (SELECT column_1, column_2 FROM t1 WHERE t1.x = t2.y ) AS ldt Still … “correlated”

  2. SQL:1999 — LATERAL Lateral derived tables lift both limitations and can be correlated: “Derived table” means SELECT … it’s in the , ldt.* FROM/JOIN clause FROM t2 CROSS JOIN LATERAL (SELECT column_1, column_2 FROM t1 Regular join WHERE t1.x = t2.y semantics ) AS ldt Still … “correlated”

  3. SQL:1999 — LATERAL

  4. SQL:1999 — LATERAL ‣ Top-N per group inside a lateral derived table FETCH FIRST (or LIMIT , TOP ) applies per row from left tables.

  5. SQL:1999 — LATERAL ‣ Top-N per group FROM t JOIN LATERAL (SELECT … inside a lateral derived table FROM … FETCH FIRST (or LIMIT , TOP ) WHERE t.c=… applies per row from left tables. ORDER BY … LIMIT 10 ) derived_table

  6. SQL:1999 — LATERAL Add proper index for Top-N query ‣ Top-N per group FROM t JOIN LATERAL (SELECT … inside a lateral derived table FROM … FETCH FIRST (or LIMIT , TOP ) WHERE t.c=… applies per row from left tables. ORDER BY … LIMIT 10 ) derived_table https://use-the-index-luke.com/sql/partial-results/top-n-queries

  7. SQL:1999 — LATERAL Add proper index for Top-N query ‣ Top-N per group FROM t JOIN LATERAL (SELECT … inside a lateral derived table FROM … FETCH FIRST (or LIMIT , TOP ) WHERE t.c=… applies per row from left tables. ORDER BY … LIMIT 10 ‣ Also useful to find most recent ) derived_table news from several subscribed topics (“multi-source top-N”). https://use-the-index-luke.com/sql/partial-results/top-n-queries

  8. SQL:1999 — LATERAL Add proper index for Top-N query ‣ Top-N per group FROM t JOIN LATERAL (SELECT … inside a lateral derived table FROM … FETCH FIRST (or LIMIT , TOP ) WHERE t.c=… applies per row from left tables. ORDER BY … LIMIT 10 ‣ Also useful to find most recent ) derived_table news from several subscribed topics (“multi-source top-N”). https://use-the-index-luke.com/sql/partial-results/top-n-queries ‣ Table function arguments FROM t ( TABLE often implies LATERAL ) JOIN TABLE (your_func(t.c))

  9. SQL:1999 — LATERAL 1999 2001 2003 2005 2007 2009 2011 2013 2015 2017 2019 MariaDB 5.1 MySQL 8.0.14 PostgreSQL 9.3 SQLite 1.0 DB2 LUW 9.1 Oracle 11gR1 12cR1 [0] SQL Server 2005 [1] [0] Undocumented. Requires setting trace event 22829. [1] LATERAL is not supported as of SQL Server 2016 but [CROSS|OUTER] � APPLY can be used for the same e � ect.

  10. 1999 2003

  11. http://www.acm.org:80/sigmod/record/issues/0206/standard.pdf (via Wayback machine)

  12. SQL:2003 — Schemaless & Analytical Schemaless ‣ Introduced XML ‣ Non-uniform documents in a single column

  13. SQL:2003 — Schemaless & Analytical Schemaless ‣ Introduced XML ‣ Non-uniform documents in a single column Later: ‣ JSON added with SQL:2016 ‣ Proprietary JSON support: ‣ 2012: PostgreSQL ‣ 2014: Oracle ‣ 2015: MySQL ‣ 2016: SQL Server

  14. SQL:2003 — Schemaless & Analytical Schemaless Analytical ‣ Introduced XML ‣ Introduced ‣ Non-uniform window functions ‣ Accessing other rows documents in a single column of the current result Later: ‣ JSON added with SQL:2016 ‣ Proprietary JSON support: ‣ 2012: PostgreSQL ‣ 2014: Oracle ‣ 2015: MySQL ‣ 2016: SQL Server

  15. SQL:2003 — Schemaless & Analytical Schemaless Analytical ‣ Introduced XML ‣ Introduced ‣ Non-uniform window functions ‣ Accessing other rows documents in a single column of the current result Later: Later: ‣ JSON added with SQL:2016 ‣ Extended in SQL:2011 ‣ Proprietary JSON support: ‣ Popular among “New SQLs” ‣ 2012: PostgreSQL ‣ 2013: BigQuery, Hive ‣ 2014: Oracle ‣ 2014: Impala ‣ 2015: MySQL ‣ 2015: Spark SQL ‣ 2016: SQL Server ‣ 2016: NuoDB, MemSQL, Cockroach DB, VoltDB

  16. SQL:2003 — Analytical id value SELECT id, value 1 +10 2 +20 3 -10 4 +50 5 -30 6 -20 FROM t

  17. SQL:2003 — Analytical id value bal SELECT id, value 1 +10 2 +20 3 -10 4 +50 5 -30 6 -20 FROM t

  18. SQL:2003 — Analytical id value bal SELECT id, value 1 +10 +10 2 +20 3 -10 4 +50 5 -30 6 -20 FROM t

  19. SQL:2003 — Analytical id value bal SELECT id, value 1 +10 +10 2 +20 +30 3 -10 +20 4 +50 +70 5 -30 +40 6 -20 +20 FROM t

  20. SQL:2003 — Analytical id value bal SELECT id, value , SUM(value) 1 +10 +10 OVER ( 2 +20 +30 3 -10 +20 4 +50 +70 5 -30 +40 6 -20 +20 ) bal FROM t

  21. SQL:2003 — Analytical id value bal SELECT id, value , SUM(value) 1 +10 +10 OVER ( 2 +20 +30 ORDER BY id 3 -10 +20 4 +50 +70 5 -30 +40 6 -20 +20 ) bal FROM t

  22. SQL:2003 — Analytical id value bal SELECT id, value , SUM(value) 1 +10 +10 OVER ( 2 +20 +30 ORDER BY id 3 -10 +20 4 +50 +70 5 -30 +40 6 -20 +20 ) bal FROM t

  23. SQL:2003 — Analytical id value bal SELECT id, value , SUM(value) 1 +10 +10 OVER ( 2 +20 +30 ORDER BY id 3 -10 +20 ROWS BETWEEN 4 +50 +70 UNBOUNDED PRECEDING 5 -30 +40 6 -20 +20 ) bal FROM t

  24. SQL:2003 — Analytical id value bal SELECT id, value , SUM(value) 1 +10 +10 OVER ( 2 +20 +30 ORDER BY id 3 -10 +20 ROWS BETWEEN 4 +50 +70 UNBOUNDED PRECEDING 5 -30 +40 6 -20 +20 ) bal FROM t

  25. SQL:2003 — Analytical id value bal SELECT id, value , SUM(value) 1 +10 +10 OVER ( 2 +20 +30 ORDER BY id 3 -10 +20 ROWS BETWEEN 4 +50 +70 UNBOUNDED PRECEDING 5 -30 +40 AND CURRENT ROW 6 -20 +20 ) bal FROM t

  26. SQL:2003 — Analytical id value bal SELECT id, value , SUM(value) 1 +10 +10 OVER ( 2 +20 +30 ORDER BY id 3 -10 +20 ROWS BETWEEN 4 +50 +70 UNBOUNDED PRECEDING 5 -30 +40 AND CURRENT ROW 6 -20 +20 ) bal FROM t

  27. SQL:2003 — Analytical id value bal SELECT id, value , SUM(value) 1 +10 +10 OVER ( 2 +20 +30 ORDER BY id 3 -10 +20 ROWS BETWEEN 4 +50 +70 UNBOUNDED PRECEDING 5 -30 +40 AND CURRENT ROW 6 -20 +20 ) bal FROM t

  28. SQL:2003 — Analytical id value bal SELECT id, value , SUM(value) 1 +10 +10 OVER ( 2 +20 +30 ORDER BY id 3 -10 +20 ROWS BETWEEN 4 +50 +70 UNBOUNDED PRECEDING 5 -30 +40 AND CURRENT ROW 6 -20 +20 ) bal FROM t

  29. SQL:2003 — Analytical id value bal SELECT id, value , SUM(value) 1 +10 +10 OVER ( 2 +20 +30 ORDER BY id 3 -10 +20 ROWS BETWEEN 4 +50 +70 UNBOUNDED PRECEDING 5 -30 +40 AND CURRENT ROW 6 -20 +20 ) bal FROM t

  30. SQL:2003 — Analytical id value bal SELECT id, value , SUM(value) 1 +10 +10 OVER ( 2 +20 +30 ORDER BY id 3 -10 +20 ROWS BETWEEN 4 +50 +70 UNBOUNDED PRECEDING 5 -30 +40 AND CURRENT ROW 6 -20 +20 ) bal FROM t

  31. SQL:2003 — Analytical id value bal SELECT id, value , SUM(value) 1 +10 +10 OVER ( 2 +20 +30 ORDER BY id 3 -10 +20 ROWS BETWEEN 4 +50 +70 UNBOUNDED PRECEDING 5 -30 +40 AND CURRENT ROW 6 -20 +20 ) bal FROM t

  32. SQL:2003 — Analytical id value bal SELECT id, value , SUM(value) 1 +10 +10 OVER ( 2 +20 +30 ORDER BY id 3 -10 +20 ROWS BETWEEN 4 +50 +70 UNBOUNDED PRECEDING 5 -30 +40 AND CURRENT ROW 6 -20 +20 ) bal FROM t

  33. SQL:2003 — Analytical 1999 2001 2003 2005 2007 2009 2011 2013 2015 2017 2019 MariaDB 5.1 10.2 MySQL 8.0 PostgreSQL 8.4 SQLite 1.0 3.25.0 DB2 LUW 7.0 Oracle 8i SQL Server 2005 2012 [0] [0] Without framing

  34. SQL:2003 — Analytical Impala Spark BigQuery Hive NuoDB 1999 2001 2003 2005 2007 2009 2011 2013 2015 2017 2019 MariaDB 5.1 10.2 MySQL 8.0 PostgreSQL 8.4 SQLite 1.0 3.25.0 DB2 LUW 7.0 Oracle 8i SQL Server 2005 2012 [0] [0] Without framing

  35. 2003 2016

  36. SQL:2016 — JSON http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip

  37. SQL:2016 — JSON [ { "id": 42, "a1": "foo" }, { "id": 43, "a1": "bar" } ] http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip

  38. SQL:2016 — JSON [ { "id": 42, id a1 "a1": "foo" }, 42 foo { 43 bar "id": 43, "a1": "bar" } ] http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip

  39. SQL:2016 — JSON_TABLE [ SELECT * { "id": 42, FROM JSON_TABLE "a1": "foo" }, ( ? { "id": 43, , '$[*]' "a1": "bar" COLUMNS } ] ( id INT PATH '$.id' , a1 VARCHAR(…) PATH '$.a1' id a1 ) 42 foo ) r 43 bar

  40. SQL:2016 — JSON_TABLE [ SELECT * { "id": 42, FROM JSON_TABLE "a1": "foo" }, ( ? { Bind "id": 43, , '$[*]' Parameter "a1": "bar" COLUMNS } ] ( id INT PATH '$.id' , a1 VARCHAR(…) PATH '$.a1' id a1 ) 42 foo ) r 43 bar

  41. SQL:2016 — JSON_TABLE SQL/JSON Path [ SELECT * { ‣ Query language to "id": 42, select elements from FROM JSON_TABLE "a1": "foo" a JSON document }, ( ? { ‣ Defined in the Bind "id": 43, , '$[*]' SQL standard Parameter "a1": "bar" COLUMNS } ] ( id INT PATH '$.id' , a1 VARCHAR(…) PATH '$.a1' id a1 ) 42 foo ) r 43 bar

  42. SQL:2016 — JSON_TABLE SQL/JSON Path [ SELECT * { ‣ Query language to "id": 42, select elements from FROM JSON_TABLE "a1": "foo" a JSON document }, ( ? { ‣ Defined in the Bind "id": 43, , '$[*]' SQL standard Parameter "a1": "bar" COLUMNS } ] ( id INT PATH '$.id' , a1 VARCHAR(…) PATH '$.a1' id a1 ) 42 foo ) r 43 bar

  43. SQL:2016 — JSON_TABLE SQL/JSON Path [ SELECT * { ‣ Query language to "id": 42, select elements from FROM JSON_TABLE "a1": "foo" a JSON document }, ( ? { ‣ Defined in the Bind "id": 43, , '$[*]' SQL standard Parameter "a1": "bar" COLUMNS } ] ( id INT PATH '$.id' , a1 VARCHAR(…) PATH '$.a1' id a1 ) 42 foo ) r 43 bar

  44. SQL:2016 — JSON_TABLE — Use Case [ SELECT * { "id": 42, FROM JSON_TABLE "a1": "foo" }, ( ? { "id": 43, , '$[*]' "a1": "bar" COLUMNS } ] ( id INT PATH '$.id' , a1 VARCHAR(…) PATH '$.a1' id a1 ) 42 foo ) r 43 bar

  45. SQL:2016 — JSON_TABLE — Use Case [ INSERT INTO target_table { SELECT * "id": 42, "a1": "foo" FROM JSON_TABLE }, { ( ? "id": 43, , '$[*]' "a1": "bar" } COLUMNS ] ( id INT PATH '$.id' id a1 , a1 VARCHAR(…) PATH '$.a1' 42 foo ) ) r 43 bar

  46. SQL:2016 — JSON_TABLE 1999 2001 2003 2005 2007 2009 2011 2013 2015 2017 2019 MariaDB 5.1 MySQL 8.0 PostgreSQL SQLite 1.0 DB2 LUW 11.1.4.4 [0] Oracle 12cR1 SQL Server 2016 [1] [0] Ridicoulus limitations: only 'strict $' as row expression [1] OPENJSON provides similar functionality

  47. SQL:2016 — JSON_TABLE MDEV-17399 Tagged with 1999 2001 2003 2005 2007 2009 2011 2013 2015 2017 2019 fix/Version: 10.6 MariaDB 5.1 Ready for MySQL 8.0 Committer PostgreSQL SQLite 1.0 DB2 LUW 11.1.4.4 [0] Oracle 12cR1 SQL Server 2016 [1] [0] Ridicoulus limitations: only 'strict $' as row expression [1] OPENJSON provides similar functionality

  48. 2011 2016

  49. SQL:2011 — Time Travelling http://cs.ulb.ac.be/public/_media/teaching/infoh415/tempfeaturessql2011.pdf

  50. SQL:2011 — Time Travelling Application Versioning ‣ Dedicated syntax added ‣ When did something happen in the real world? http://cs.ulb.ac.be/public/_media/teaching/infoh415/tempfeaturessql2011.pdf

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend