Developers’ mDay 2019. -Bogdan Kecman, Oracle – MySQL 8.0 – why upgrade
Developers’ mDay konferencija okuplja inspirativne ljude iz oblasti web developmenta. U pitanju je događaj stručnog karaktera, namenjen web developerima sa ciljem da se upoznaju sa aktuelnim tehnologijama u projektovanju web sistema, iskustvima u korišćenju najnovijih tehnika i tehnologija, kao i u rešavanju problema sa kojima se svakodnevno suočavaju.
1. MySQL 8 – why upgrade?
Bogdan Kecman
CEO @BAD-TEAM
MySQL Principal Technical Engineer @ORACLE
bogdan.kecman@oracle.com
bogdan.kecman@bad-team.net
#mDevDay, #mDevDay2019, Beograd, Novembar 2019
2. Safe Harbor Statement
The following is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.
2
3. MySQL 8.0
●
Evolved beyond SQL-92
●
Evolved beyond relational dogma
●
Supports window functions (over)
●
Supports CommonTableExpressions (with)
●
Transactional DDL (no more FRM files)
●
Hash Joins, SKIP LOCKED, NO WAIT, Explain Analyze...
One Giant Leap for SQL
3
4. MySQL 8.0
●
Support for the latest Unicode 9.0
●
UTF8MB4 is new default (utf8mb4_0900_ai_ci is default coll.)
●
Accent and case sensitive collations (20+ lang specific)
●
Improved performance (no, really, it’s unbelievably fast now)
UTF8
4
5. MySQL 8.0
●
Geography Support (lat/lon)
●
Spatial Reference Systems (SRS) Support
●
SRID aware spatial datatypes, indexes and functions
●
Informational Schema views about spatial data
(ST_GEOMETRY_COLUMNS)
●
GeoHash(), GeoJSON()
GIS: SRS, SRID, IS Views, GeoHash and GeoJSON
5
6. MySQL 8.0
●
ST_Distance() permits an optional unit argument that specifies the
linear unit for the returned distance value. Conforming with
SQL/MM Part 3 Spatial (ISO/IEC 13249 3:2015), Sect. 5.1.41.
mysql> SET @ls = ST_GeomFromText('LineString(1 1,2 2,3 3)', 4326);
Query OK, 0 rows affected (0.02 sec)
mysql> SELECT ST_Length(@ls), ST_Length(@ls, 'metre'), ST_Length(@ls, 'foot');
+-------------------+-------------------------+------------------------+
| ST_Length(@ls) | ST_Length(@ls, 'metre') | ST_Length(@ls, 'foot') |
+-------------------+-------------------------+------------------------+
| 313701.9623204328 | 313701.9623204328 | 1029205.9131247795 |
+-------------------+-------------------------+------------------------+
1 row in set (0.03 sec)
GIS: Added unit to ST_Distance()
6
7. MySQL 8.0
> select * from INFORMATION_SCHEMA.ST_UNITS_OF_MEASURE;
+--------------------------------------+-----------+---------------------+-------------+
| UNIT_NAME | UNIT_TYPE | CONVERSION_FACTOR | DESCRIPTION |
+--------------------------------------+-----------+---------------------+-------------+
| British link (Sears 1922 truncated) | LINEAR | 0.20116756 | |
| foot | LINEAR | 0.3048 | |
| British yard (Benoit 1895 B) | LINEAR | 0.9143992042898124 | |
...
| kilometre | LINEAR | 1000 | |
| US survey foot | LINEAR | 0.30480060960121924 | |
| British yard (Sears 1922) | LINEAR | 0.9143984146160288 | |
...
GIS: New INFORMATION_SCHEMA.ST_UNITS_OF_MEASURE
7
8. MySQL 8.0
Common problem: hot row contention, multiple worker threads accessing the same rows
●
Solution 1:
start transaction;
select * from seats where seat_no between 2 and 3 and booked =
‘no’ for update SKIP LOCKED;
●
Solution 2:
start transaction;
select * from seats where seat_no between 2 and 3 and booked =
‘no’ for update NOWAIT;
SKIP LOCKED and NOWAIT
8
9. MySQL 8.0
●
New data type: CREATE TABLE t1 (col1 JSON);
●
New JSON Functions to deal with JSON data type
●
Convert JSON documents to relational tables:
select ppl.* from t1, JSON_TABLE(json_col, ‘$.ppl[*]’
COLUMNS( name varchar(40) PATH ‘$.name’, address
varchar(100) PATH ‘$.address’)) ppl;
JSON Functions, Data Type and JSON_TABLE
9
10. MySQL 8.0
●
INVISIBLE index is maintained by storage engine but ignored by
the optimizer (PK cannot be invisible)
●
DESCENDING now works
●
SKIP SCAN
Index extensions: invisible, descending..
10
11. MySQL 8.0
●
Cost model significantly improved with configurable cost constants
●
Histograms to provide optimizer with information about value
distribution
●
Hints (join_fixed_order, join_order, join_prefix, join_suffix,
index_merge, no_index_merge)
●
Set a session variable inside select (select /*+
set_var(sort_buffer_size=16M) */ name from ppl ...
Optimizer
11
12. MySQL 8.0
●
IN, EXIST → semi-join
●
NOT IN, NOT EXIST → anti-semi-join
Optimizations: query transformation
12
13. MySQL 8.0
●
Instruments and executes the query
– Estimated cost
– Actual execution statistics
●
Time to return first row
●
Time to return all rows
●
Number of rows returned
●
Number of loops
●
Uses the new tree output format also available in EXPLAIN
EXPLAIN ANALYZE
13
14. MySQL 8.0
●
A derived table is a subquery in the FROM clause
– SELECT … FROM (subquery) AS derived, t1
●
Common Table Expression is just like a derived table, but its
declaration is put before the query block instead of in FROM clause
– WITH derived AS ( subquery) SELECT … FROM derived, t1
●
It’s an alternative to derived table for readability, multiple
references, increased performance
●
Can be recursive (traverse hierarchies)
CTEs (SQL:99)
14
15. MySQL 8.0
●
Similar to an aggregation function, performs a calculation across a
set of rows that are related to the current row
●
Window functions can access values of other rows “in the vicinity”
of the current row
Example (sum up total salary for each department):
SELECT name, dept _id, salary,
SUM(salary) OVER (PARTITION BY dept_id) AS dept_total
FROM employee ORDER BY dept _id, name
WINDOW functions (SQL: 2003)
15
16. MySQL 8.0
●
Illegal in SQL92 because a derived table cannot depend on other
tables in the same FROM clause (it has to be constant over the
query's duration
●
A derived table cannot normally refer to (depend on) columns of
preceding tables in the same FROM clause
SELECT salesperson.name, max_sale.amount, max_sale.customer_name
FROM salesperson, --find max size and customer at same time
LATERAL (SELECT amount, customer_name FROM all_sales
WHERE all_sales.salesperson_id = salesperson.id
ORDER BY amount DESC LIMIT 1) AS max_sale;
LATERAL derived tables (SQL:99)
16
17. MySQL 8.0
●
MyISAM not used for on-disk temp tables
●
Deprecate BINARY keyword for _bin collations
●
Deprecate integer display width and ZEROFILL option
●
Deprecate unsigned attribute for DECIMAL and FLOAT
●
Deprecate && as synonym for AND and || as synonym for OR
●
Deprecate AUTO_INCREMENT on DOUBLE and FLOAT
●
Deprecate number of digits for floating point types
●
Deprecate SQL_CALC_FOUND_ROWS and FOUND_ROWS
MISC
17