modern sql
play

Modern SQL: Evolution of a dinosaur @MarkusWinand @ModernSQL - PowerPoint PPT Presentation

Modern SQL: Evolution of a dinosaur @MarkusWinand @ModernSQL http://www.almaden.ibm.com/cs/people/chamberlin/sequel-1974.pdf Modern SQL: Evolution of a dinosaur @MarkusWinand @ModernSQL


  1. 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

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

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

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

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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

  12. 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

  13. 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

  14. 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

  15. 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

  16. 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

  17. 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

  18. 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

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

  20. 2003 2016

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

  22. 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

  23. 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

  24. 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

  25. 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

  26. 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

  27. 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

  28. 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

  29. 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

  30. 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

  31. SQL:2016 — JSON_TABLE — Use Case Session tip: How Well Do Relational Database [ INSERT INTO target_table Engines Support JSON? { SELECT * "id": 42, Today 15:30! "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

  32. SQL:2016 — JSON_TABLE 1999 2001 2003 2005 2007 2009 2011 2013 2015 2017 MariaDB MySQL 8.0 PostgreSQL SQLite DB2 LUW Oracle 12cR1 SQL Server 2016 [0] [0] OPENJSON provides similar functionality

  33. MATCH_RECOGNIZE (Row Pattern Recognition)

  34. SQL:2016 — Pattern Matching Example: Logfile 30 minutes Time

  35. SQL:2016 — Pattern Matching Example: Logfile Session 3 30 minutes Session 2 Session 1 Session 4 Time

  36. SQL:2016 — Pattern Matching 30 minutes Time

  37. SQL:2016 — Pattern Matching 30 minutes Time SELECT count(*) sessions, avg(duration) avg_duration FROM (SELECT MAX(ts) - MIN(ts) duration FROM (SELECT ts, SUM(grp_start) OVER(ORDER BY ts) session_no FROM (SELECT ts, CASE WHEN ts >= LAG( ts, 1, DATE'1900-01-01' ) OVER( ORDER BY ts ) + INTERVAL '30' minute THEN 1 END grp_start FROM log ) tagged ) numbered GROUP BY session_no ) grouped

  38. SQL:2016 — Pattern Matching 30 minutes Time SELECT count(*) sessions, avg(duration) avg_duration FROM (SELECT MAX(ts) - MIN(ts) duration FROM (SELECT ts, SUM(grp_start) OVER(ORDER BY ts) session_no FROM (SELECT ts, CASE WHEN ts >= LAG( ts, 1, DATE'1900-01-01' ) OVER( ORDER BY ts ) + INTERVAL '30' minute THEN 1 END grp_start Start-of-group FROM log tags ) tagged ) numbered GROUP BY session_no ) grouped

  39. SQL:2016 — Pattern Matching 30 minutes Time SELECT count(*) sessions, avg(duration) avg_duration FROM (SELECT MAX(ts) - MIN(ts) duration FROM (SELECT ts, SUM(grp_start) OVER(ORDER BY ts) session_no FROM (SELECT ts, CASE WHEN ts >= LAG( ts, 1, DATE'1900-01-01' ) OVER( ORDER BY ts ) + INTERVAL '30' minute THEN 1 END grp_start Start-of-group FROM log tags ) tagged ) numbered GROUP BY session_no ) grouped

  40. SQL:2016 — Pattern Matching 30 minutes Time number sessions SELECT count(*) sessions, avg(duration) avg_duration FROM (SELECT MAX(ts) - MIN(ts) duration FROM (SELECT ts, SUM(grp_start) OVER(ORDER BY ts) session_no FROM (SELECT ts, CASE WHEN ts >= LAG( ts, 1, DATE'1900-01-01' ) OVER( ORDER BY ts ) + INTERVAL '30' minute THEN 1 END grp_start FROM log ) tagged ) numbered GROUP BY session_no ) grouped

  41. SQL:2016 — Pattern Matching 4 3 2 2222 2 33 3 44 4 30 minutes 1 Time number sessions SELECT count(*) sessions, avg(duration) avg_duration FROM (SELECT MAX(ts) - MIN(ts) duration FROM (SELECT ts, SUM(grp_start) OVER(ORDER BY ts) session_no FROM (SELECT ts, CASE WHEN ts >= LAG( ts, 1, DATE'1900-01-01' ) OVER( ORDER BY ts ) + INTERVAL '30' minute THEN 1 END grp_start FROM log ) tagged ) numbered GROUP BY session_no ) grouped

  42. SQL:2016 — Pattern Matching .\S*

  43. SQL:2016 — Pattern Matching Regular Expression .\S*

  44. SQL:2016 — Pattern Matching .\S* { any character non-white space Rail track diagram by regexper.com

  45. SQL:2016 — Pattern Matching .\S* { { any character non-white space Rail track diagram by regexper.com

  46. SQL:2016 — Pattern Matching .\S* { { { any character any character non-white space non-white space Rail track diagram by regexper.com

  47. SQL:2016 — Pattern Matching 30 minutes Time SELECT COUNT(*) sessions , AVG(duration) avg_duration FROM log MATCH_RECOGNIZE( ORDER BY ts MEASURES LAST(ts) - FIRST(ts) AS duration ONE ROW PER MATCH PATTERN ( any cont* ) DEFINE cont AS ts < PREV(ts) + INTERVAL '30' MINUTE ) t Oracle doesn’t support avg on intervals — query doesn’t work as shown

  48. SQL:2016 — Pattern Matching 30 minutes Time SELECT COUNT(*) sessions , AVG(duration) avg_duration FROM log MATCH_RECOGNIZE( ORDER BY ts MEASURES LAST(ts) - FIRST(ts) AS duration ONE ROW PER MATCH PATTERN ( any cont* ) DEFINE cont AS ts < PREV(ts) define 
 + INTERVAL '30' MINUTE continued ) t Oracle doesn’t support avg on intervals — query doesn’t work as shown

  49. SQL:2016 — Pattern Matching 30 minutes Time SELECT COUNT(*) sessions , AVG(duration) avg_duration FROM log MATCH_RECOGNIZE( ORDER BY ts MEASURES LAST(ts) - FIRST(ts) AS duration any number 
 ONE ROW PER MATCH of “cont” 
 PATTERN ( any cont* ) rows DEFINE cont AS ts < PREV(ts) + INTERVAL '30' MINUTE ) t Oracle doesn’t support avg on intervals — query doesn’t work as shown

  50. SQL:2016 — Pattern Matching 30 minutes Time SELECT COUNT(*) sessions , AVG(duration) avg_duration FROM log MATCH_RECOGNIZE( ORDER BY ts Very much 
 MEASURES like GROUP BY LAST(ts) - FIRST(ts) AS duration ONE ROW PER MATCH PATTERN ( any cont* ) DEFINE cont AS ts < PREV(ts) + INTERVAL '30' MINUTE ) t Oracle doesn’t support avg on intervals — query doesn’t work as shown

Recommend


More recommend