HeatWave is a massively parallel, high performance, in-memory query accelerator for Oracle MySQL Database Service that accelerates MySQL performance by orders of magnitude for analytics and mixed workloads. But how do you collect data from an Internet of Things Environment so you can use HeatWave to process it? In one hour you will see how data collected by a Raspberry PI or other Internet of Things device can be uploaded to the MySQL Database Service and then processed by HeatWave.
2. Who am I ?
about.me/lefred
Copyright @ 2022 Oracle and/or its affiliates.
2
3. @lefred
MySQL Evangelist
using MySQL since version 3.21
devops believer
living in
born at PiDay !
h ps://lefred.be
Frédéric Descamps
Copyright @ 2022 Oracle and/or its affiliates.
3
4. @lefred
MySQL Evangelist
using MySQL since version 3.21
devops believer
living in
born at PiDay !
h ps://lefred.be
Frédéric Descamps
Copyright @ 2022 Oracle and/or its affiliates.
3
6. IoT - the Internet of Things
The Internet of Things describes the network of physical objects—“things”—that are
embedded with sensors, software, and other technologies for the purpose of connecting
and exchanging data with other devices and systems over the internet.
These devices range from ordinary household objects to sophisticated industrial tools. With
more than 7 billion connected IoT devices today, experts are expecting this number to grow
to 22 billion by 2025.
Copyright @ 2022 Oracle and/or its affiliates.
5
7. MySQL
the most popular Open Source Relational Database
Management System
Copyright @ 2022 Oracle and/or its affiliates.
6
8. MySQL HeatWave
MySQL is the most popular Open Source Database and it's developed by Oracle.
MySQL is a relational database management system (RDMBS) but also a NoSQL Document
Store.
Copyright @ 2022 Oracle and/or its affiliates.
7
9. MySQL HeatWave
MySQL is the most popular Open Source Database and it's developed by Oracle.
MySQL is a relational database management system (RDMBS) but also a NoSQL Document
Store.
MySQL is also available in Oracle Cloud Inftrastructure (OCI) as a managed service.
HeatWave is a massively, high performance, in-memory query accelerator for OCI MySQL
Database Service that accelerates MySQL performance by orders of magnitude for
analytics and mixed workload.
Copyright @ 2022 Oracle and/or its affiliates.
7
12. Hardware
A DHT22 sensor providing mesure for temperature and humidity:
Copyright @ 2022 Oracle and/or its affiliates.
10
13. Hardware
This is the assembly schema:
Copyright @ 2022 Oracle and/or its affiliates.
11
14. Software
On the Raspberry the following packages are required:
Python
pip
mysql-connector-python (from pip)
Adafruit_Python_DHT (from pip)
Copyright @ 2022 Oracle and/or its affiliates.
12
15. Software
On the Raspberry the following packages are required:
Python
pip
mysql-connector-python (from pip)
Adafruit_Python_DHT (from pip)
We will also create our own program and a systemd script to manage it (start/stop/status):
metrics_to_MySQL.py
piday_metrics@.service
Copyright @ 2022 Oracle and/or its affiliates.
12
17. OCI Architecture - simpli ed
Copyright @ 2022 Oracle and/or its affiliates.
14
18. Deploy in OCI
Once you have an Oracle Cloud account, you can just use the link on the next slide to
deploy the required architecture using a Oracle Resource Manager Stack (Terraform).
This will create all the necessary resources:
A VCN
The Public and Private Subnets
An Internet Gateway
The Security Lists
A compute instance with MySQL Router installed and con gured
A MySQL Database Service Instance
Copyright @ 2022 Oracle and/or its affiliates.
15
19. Deploy in OCI - Stack
h ps://github.com/lefred/oci-iot-mds
Copyright @ 2022 Oracle and/or its affiliates.
16
20. Deploy in OCI - Stack (2)
Copyright @ 2022 Oracle and/or its affiliates.
17
21. Deploy in OCI - Stack (3)
Copyright @ 2022 Oracle and/or its affiliates.
18
22. Deploy in OCI - Stack (4)
Copyright @ 2022 Oracle and/or its affiliates.
19
23. Deploy in OCI - Stack (5)
Copyright @ 2022 Oracle and/or its affiliates.
20
24. Deploy in OCI - Stack (6)
Copyright @ 2022 Oracle and/or its affiliates.
21
25. Deploy in OCI - Stack (7)
Copyright @ 2022 Oracle and/or its affiliates.
22
26. Deploy in OCI - Stack (8)
Copyright @ 2022 Oracle and/or its affiliates.
23
27. Deploy in OCI - Stack (9)
Copyright @ 2022 Oracle and/or its affiliates.
24
28. Deploy in OCI - Created Resources
Copyright @ 2022 Oracle and/or its affiliates.
25
29. Deploy in OCI - Created Resources (2)
Copyright @ 2022 Oracle and/or its affiliates.
26
31. MySQL 8.0
With MySQL 8.0, you can mix relational tables and JSON Documents.
Copyright @ 2022 Oracle and/or its affiliates.
28
32. MySQL 8.0
With MySQL 8.0, you can mix relational tables and JSON Documents.
SQL + NoSQL = MySQL Document Store
Copyright @ 2022 Oracle and/or its affiliates.
28
33. Built on the
MySQL JSON
Data type
and Proven
MySQL
Server
Technology
Provides a schema exible JSON Document Store
No SQL required
No need to de ne all possible a ributes, tables, etc.
Uses new X DevAPI (available on premise and in OCI only !)
Can leverage generated column to extract JSON values into materialized
columns that can be indexed for fast SQL searches.
Document can be ~1GB
It's a column in a row of a table
It cannot exceed max_allowed_packet
Allows use of modern programming styles
No more embedded strings of SQL in your code
Easy to read
Also works with relational Tables
Proven MySQL Technology
Copyright @ 2022 Oracle and/or its affiliates.
29
35. Design - explanations
For realtime (current) information, we use a collection of JSON documents where each
document represents the state of a device with the lastest values it collected.
For historical data generally used for analytics, we use relational tables that we will use later
with HeatWave if we need to improve the performance.
Copyright @ 2022 Oracle and/or its affiliates.
31
36. Design - connection to the MySQL Instance
We use port 6448 (X Protocol) on the Public IP of the Compute Instance where MySQL
Router is deployed.
Copyright @ 2022 Oracle and/or its affiliates.
32
37. Design - schema and collection creation
Copyright @ 2022 Oracle and/or its affiliates.
33
39. At some point, dealing with historical data
like archiving, deleting old records can
become a heavy operation.
HeatWave has been designed to deal with a
huge amount of data but on MySQL,
partitioning is a solution to deal with these
operations.
Design - relational tables creation
Copyright @ 2022 Oracle and/or its affiliates.
35
40. Design - relational tables creation: partitioning
SQL
SQL>
> alter
alter table
table humidity_history
humidity_history add
add day_date
day_date date
date as
as (
(date
date(
(time_stamp
time_stamp)
))
) stored
stored,
,
drop
drop primary
primary key
key,
, add
add primary
primary key
key (
(id
id,
, day_date
day_date)
);
;
SQL
SQL>
> alter
alter table
table humidity_history
humidity_history partition
partition by
by range
range columns
columns(
(day_date
day_date)
) (
(
partition
partition p0_before2022
p0_before2022 values
values less than
less than(
('2022-01-01'
'2022-01-01')
),
,
partition
partition p2022_01
p2022_01 values
values less than
less than(
('2022-02-01'
'2022-02-01')
),
,
partition
partition p2022_02
p2022_02 values
values less than
less than(
('2022-03-01'
'2022-03-01')
),
,
partition
partition p2022_03
p2022_03 values
values less than
less than(
('2022-04-01'
'2022-04-01')
),
,
partition
partition p2022_04
p2022_04 values
values less than
less than(
('2022-05-01'
'2022-05-01')
),
,
partition
partition p2022_05
p2022_05 values
values less than
less than(
('2022-06-01'
'2022-06-01')
),
,
.
..
..
.
partition
partition p2023_12
p2023_12 values
values less than
less than(
('2024-01-01'
'2024-01-01')
),
,
partition
partition p9_future
p9_future values
values less than
less than(
(maxvalue
maxvalue)
))
);
;
see h ps://dev.mysql.com/doc/refman/8.0/en/partitioning-management-range-list.html
Copyright @ 2022 Oracle and/or its affiliates.
36
42. MySQL Dedicated User for IoT
It's a best practice that every applications use their own user to access MySQL.
In our case we will create one for all our devices.
We create a user with the required priveleges to write data from our Rasbperry Pi:
SQL
SQL>
> create
create user
user piday identified
piday identified with
with 'mysql_native_password'
'mysql_native_password'
by
by 'Fred140376#'
'Fred140376#';
;
SQL
SQL>
> grant
grant select
select,
, insert
insert,
, update
update on
on piday
piday.
.*
* to
to piday
piday;
;
Copyright @ 2022 Oracle and/or its affiliates.
38
44. We need Adafruit_DHT module to read the sensor:
import
import Adafruit_DHT
Adafruit_DHT
sensor
sensor=
=Adafruit_DHT
Adafruit_DHT.
.DHT22
DHT22
gpio
gpio=
=4
4
humidity
humidity,
, temperature
temperature =
= Adafruit_DHT
Adafruit_DHT.
.read_retry
read_retry(
(sensor
sensor,
, gpio
gpio)
)
Reading from the Sensor
I am using Python on the Raspberry Pi.
Copyright @ 2022 Oracle and/or its affiliates.
40
45. Connection to MySQL
Of course all the connectors maintained by Oracle MySQL support the X Dev API
Copyright @ 2022 Oracle and/or its affiliates.
41
50. The code : /opt/PiDayMySQL/metrics_to_MySQL.py (4)
while
while(
(True
True)
):
:
if
if not
not session
session.
.is_open
is_open(
()
):
:
connect
connect(
()
)
humidity
humidity,
, temperature
temperature =
= Adafruit_DHT
Adafruit_DHT.
.read_retry
read_retry(
(sensor
sensor,
, gpio
gpio)
)
if
if humidity
humidity is
is not
not None
None and
and temperature
temperature is
is not
not None
None:
:
# Find the device and its last ip
# Find the device and its last ip
res
res =
= col_devices
col_devices.
.find
find(
("_id='{}'"
"_id='{}'".
.format
format(
(rasbpy_id
rasbpy_id)
))
).
.fields
fields(
(
'_id'
'_id',
, 'publicip'
'publicip')
).
.execute
execute(
()
)
device
device =
= res
res.
.fetch_one
fetch_one(
()
)
if
if device
device:
:
old_public_ip
old_public_ip =
= device
device[
['publicip'
'publicip']
]
else
else:
:
print
print(
("device with _id: {} not found !"
"device with _id: {} not found !".
.format
format(
(rasbpy_id
rasbpy_id)
))
)
print
print(
("sleeping 1 min..."
"sleeping 1 min...")
)
time
time.
.sleep
sleep(
(60
60)
)
continue
continue
Copyright @ 2022 Oracle and/or its affiliates.
46
63. Analyzing the collected data
Let's get some statistics on the metrics we collected so far:
SQL
SQL >
> select
select *
* from
from (
(select
select device_id
device_id,
, max
max(
(value
value)
) as
as `
`max temp
max temp`
`,
, min
min(
(value
value)
) as
as `
`min temp
min temp`
`,
,
avg
avg(
(value
value)
) as
as `
`avg temp
avg temp`
` from
from temperature_history
temperature_history group
group by
by device_id
device_id)
) a
a
natural
natural join
join (
(select
select device_id
device_id,
, max
max(
(value
value)
) as
as `
`max humidity
max humidity`
`,
, min
min(
(value
value)
) as
as `
`min humidity
min humidity`
`,
,
avg
avg(
(value
value)
) as
as `
`avg humidity
avg humidity`
` from
from humidity_history
humidity_history group
group by
by device_id
device_id)
) b
b ;
;
+
+------------------------------+----------+----------+-----------+--------------+--------------+--------------+
------------------------------+----------+----------+-----------+--------------+--------------+--------------+
|
| device_id
device_id |
| max
max temp
temp |
| min
min temp
temp |
| avg
avg temp
temp |
| max humidity
max humidity |
| min humidity
min humidity |
| avg humidity
avg humidity |
|
+
+------------------------------+----------+----------+-----------+--------------+--------------+--------------+
------------------------------+----------+----------+-----------+--------------+--------------+--------------+
|
| 00006227543
00006227543c0000000000000001
c0000000000000001 |
| 142.94
142.94 |
| 9.00
9.00 |
| 11.711163
11.711163 |
| 169.86
169.86 |
| 40.00
40.00 |
| 45.206324
45.206324 |
|
|
| 00006227543
00006227543c0000000000000002
c0000000000000002 |
| 29.99
29.99 |
| 20.00
20.00 |
| 22.513379
22.513379 |
| 65.00
65.00 |
| 55.00
55.00 |
| 60.000385
60.000385 |
|
|
| 00006227543
00006227543c0000000000000003
c0000000000000003 |
| 814.36
814.36 |
| 0.00
0.00 |
| 3.114047
3.114047 |
| 800.21
800.21 |
| 1.00
1.00 |
| 6.609432
6.609432 |
|
|
| 00006227543
00006227543c0000000000000004
c0000000000000004 |
| 288.44
288.44 |
| 10.00
10.00 |
| 12.567651
12.567651 |
| 279.32
279.32 |
| 30.00
30.00 |
| 35.062746
35.062746 |
|
+
+------------------------------+----------+----------+-----------+--------------+--------------+--------------+
------------------------------+----------+----------+-----------+--------------+--------------+--------------+
4
4 rows
rows in
in set
set (
(2.0747
2.0747 sec
sec)
)
Copyright @ 2022 Oracle and/or its affiliates.
57
64. Get the Query Execution Plan
Let's have a look at the EXPLAIN plan (format=tree):
EXPLAIN
EXPLAIN:
: -
->
> Nested
Nested loop
loop inner
inner join
join (
(cost
cost=
=1348953.36
1348953.36 rows
rows=
=0
0)
)
-
->
> Filter:
Filter: (
(a
a.
.device_id
device_id is
is not
not null
null)
) (
(cost
cost=
=155455.11
155455.11.
..58090
.58090.86
.86 rows
rows=
=516341
516341)
)
-
->
> Table
Table scan
scan on
on a
a (
(cost
cost=
=0.01
0.01.
..6456
.6456.76
.76 rows
rows=
=516341
516341)
)
-
->
> Materialize
Materialize (
(cost
cost=
=155455.31
155455.31.
..161912
.161912.06
.06 rows
rows=
=516341
516341)
)
-
->
> Group
Group aggregate:
aggregate: max
max(
(temperature_history
temperature_history.
.`
`value
value`
`)
),
, min
min(
(temperature_history
temperature_history.
.`
`value
value`
`)
),
,
avg
avg(
(temperature_history
temperature_history.
.`
`value
value`
`)
) (
(cost
cost=
=103821.20
103821.20 rows
rows=
=516341
516341)
)
-
->
> Index
Index scan
scan on
on temperature_history
temperature_history using
using device_id_idx
device_id_idx (
(cost
cost=
=52187.10
52187.10 rows
rows=
=516341
516341)
)
-
->
> Index
Index lookup
lookup on
on b
b using
using <
<auto_key0
auto_key0>
> (
(device_id
device_id=
=a
a.
.device_id
device_id)
)
-
->
> Materialize
Materialize (
(cost
cost=
=0.00
0.00.
..0
.0.00
.00 rows
rows=
=0
0)
)
-
->
> Table
Table scan
scan on
on <
<temporary
temporary>
>
-
->
> Aggregate
Aggregate using
using temporary
temporary table
table
-
->
> Table
Table scan
scan on
on humidity_history
humidity_history (
(cost
cost=
=52191.40
52191.40 rows
rows=
=516384
516384)
)
Copyright @ 2022 Oracle and/or its affiliates.
58
65. Analyzing the collected data (2)
SQL
SQL >
> select
select *
* from
from (
(
select
select date
date(
(time_stamp
time_stamp)
) as
as `
`day
day`
`,
, device_id
device_id,
, count
count(
(*
*)
) as
as `
`tot
tot`
`,
,
max
max(
(value
value)
) as
as `
`max hum
max hum`
`,
, min
min(
(value
value)
) as
as `
`min hum
min hum`
`,
, avg
avg(
(value
value)
) as
as `
`avg hum
avg hum`
`
from
from humidity_history
humidity_history group
group by
by device_id
device_id,
, day
day)
) a
a
natural
natural join
join (
(
select
select date
date(
(time_stamp
time_stamp)
) as
as `
`day
day`
`,
, device_id
device_id,
, count
count(
(*
*)
) as
as `
`tot
tot`
`,
,
max
max(
(value
value)
) as
as `
`max temp
max temp`
`,
, min
min(
(value
value)
) as
as `
`min temp
min temp`
`,
, avg
avg(
(value
value)
) as
as `
`avg temp
avg temp`
`
from
from temperature_history
temperature_history group
group by
by device_id
device_id,
, day
day)
) b
b order
order by
by day
day,
, device_id
device_id;
;
+
+------------+------------------------------+--------+---------+---------+-----------+----------+----------+-----------+
------------+------------------------------+--------+---------+---------+-----------+----------+----------+-----------+
|
| day
day |
| device_id
device_id |
| tot
tot |
| max hum
max hum |
| min hum
min hum |
| avg hum
avg hum |
| max
max temp
temp |
| min
min temp
temp |
| avg
avg temp
temp |
|
+
+------------+------------------------------+--------+---------+---------+-----------+----------+----------+-----------+
------------+------------------------------+--------+---------+---------+-----------+----------+----------+-----------+
|
| 2022
2022-
-03
03-
-09
09 |
| 00006227543
00006227543c0000000000000002
c0000000000000002 |
| 14534
14534 |
| 65.00
65.00 |
| 55.00
55.00 |
| 60.009273
60.009273 |
| 29.99
29.99 |
| 20.00
20.00 |
| 22.597118
22.597118 |
|
|
| 2022
2022-
-03
03-
-09
09 |
| 00006227543
00006227543c0000000000000003
c0000000000000003 |
| 31605
31605 |
| 800.21
800.21 |
| 1.00
1.00 |
| 8.570861
8.570861 |
| 814.36
814.36 |
| 0.00
0.00 |
| 5.079733
5.079733 |
|
|
| 2022
2022-
-03
03-
-09
09 |
| 00006227543
00006227543c0000000000000004
c0000000000000004 |
| 31284
31284 |
| 279.32
279.32 |
| 30.00
30.00 |
| 35.294440
35.294440 |
| 288.44
288.44 |
| 10.00
10.00 |
| 12.797445
12.797445 |
|
|
| 2022
2022-
-03
03-
-10
10 |
| 00006227543
00006227543c0000000000000001
c0000000000000001 |
| 114906
114906 |
| 50.00
50.00 |
| 40.00
40.00 |
| 45.001613
45.001613 |
| 14.00
14.00 |
| 9.00
9.00 |
| 11.499796
11.499796 |
|
|
| 2022
2022-
-03
03-
-10
10 |
| 00006227543
00006227543c0000000000000002
c0000000000000002 |
| 100913
100913 |
| 65.00
65.00 |
| 55.00
55.00 |
| 59.999105
59.999105 |
| 25.00
25.00 |
| 20.00
20.00 |
| 22.501319
22.501319 |
|
|
| 2022
2022-
-03
03-
-10
10 |
| 00006227543
00006227543c0000000000000003
c0000000000000003 |
| 101465
101465 |
| 11.00
11.00 |
| 1.00
1.00 |
| 5.998472
5.998472 |
| 5.00
5.00 |
| 0.00
0.00 |
| 2.501763
2.501763 |
|
|
| 2022
2022-
-03
03-
-10
10 |
| 00006227543
00006227543c0000000000000004
c0000000000000004 |
| 101044
101044 |
| 40.00
40.00 |
| 30.00
30.00 |
| 34.991012
34.991012 |
| 15.00
15.00 |
| 10.00
10.00 |
| 12.496505
12.496505 |
|
+
+------------+------------------------------+--------+---------+---------+-----------+----------+----------+-----------+
------------+------------------------------+--------+---------+---------+-----------+----------+----------+-----------+
7
7 rows
rows in
in set
set (
(1.2717
1.2717 sec
sec)
)
Copyright @ 2022 Oracle and/or its affiliates.
59
66. Get the Query Execution Plan (2)
EXPLAIN
EXPLAIN:
: -
->
> Sort: a
Sort: a.
.`
`day
day`
`,
, a
a.
.device_id
device_id
-
->
> Stream results
Stream results (
(cost
cost=
=1374880.15
1374880.15 rows
rows=
=0
0)
)
-
->
> Nested
Nested loop
loop inner
inner join
join (
(cost
cost=
=1374880.15
1374880.15 rows
rows=
=0
0)
)
-
->
> Filter:
Filter: (
((
(b
b.
.`
`day
day`
` is
is not
not null
null)
) and
and (
(b
b.
.device_id
device_id is
is not
not null
null)
))
) (
(cost
cost=
=0.11
0.11.
..59207
.59207.65
.65 rows
rows=
=526268
526268)
)
-
->
> Table
Table scan
scan on
on b
b (
(cost
cost=
=2.50
2.50.
..2
.2.50
.50 rows
rows=
=0
0)
)
-
->
> Materialize
Materialize (
(cost
cost=
=2.50
2.50.
..2
.2.50
.50 rows
rows=
=0
0)
)
-
->
> Table
Table scan
scan on
on <
<temporary
temporary>
>
-
->
> Aggregate
Aggregate using
using temporary
temporary table
table
-
->
> Table
Table scan
scan on
on temperature_history
temperature_history (
(cost
cost=
=53179.80
53179.80 rows
rows=
=526268
526268)
)
-
->
> Index
Index lookup
lookup on
on a
a using
using <
<auto_key0
auto_key0>
> (
(day
day=
=b
b.
.`
`day
day`
`,
, device_id
device_id=
=b
b.
.device_id
device_id,
, tot
tot=
=b
b.
.tot
tot)
)
-
->
> Materialize
Materialize (
(cost
cost=
=0.00
0.00.
..0
.0.00
.00 rows
rows=
=0
0)
)
-
->
> Table
Table scan
scan on
on <
<temporary
temporary>
>
-
->
> Aggregate
Aggregate using
using temporary
temporary table
table
-
->
> Table
Table scan
scan on
on humidity_history
humidity_history (
(cost
cost=
=53184.10
53184.10 rows
rows=
=526311
526311)
)
Copyright @ 2022 Oracle and/or its affiliates.
60
67. Enable HeatWave
Let's boost MySQL's performance with HeatWave !
We have two options to enable HeatWave:
. Editing the Stack (if we used OCI Resoure Manager)
. Using MySQL Database Service's console
Copyright @ 2022 Oracle and/or its affiliates.
61
68. Enable HeatWave - with Stack
Copyright @ 2022 Oracle and/or its affiliates.
62
69. Enable HeatWave - with Stack (2)
Copyright @ 2022 Oracle and/or its affiliates.
63
70. Enable HeatWave - with Stack (3)
Copyright @ 2022 Oracle and/or its affiliates.
64
71. Enable HeatWave - with MDS Console
Copyright @ 2022 Oracle and/or its affiliates.
65
72. Enable HeatWave - with MDS Console (2)
Copyright @ 2022 Oracle and/or its affiliates.
66
73. Enable HeatWave - with MDS Console (3)
Copyright @ 2022 Oracle and/or its affiliates.
67
74. Enable HeatWave - with MDS Console (4)
Copyright @ 2022 Oracle and/or its affiliates.
68
75. SQL
SQL >
> show
show global
global status
status like
like 'rapid_%er%_status'
'rapid_%er%_status';
;
+
+----------------------+--------+
----------------------+--------+
|
| Variable_name
Variable_name |
| Value
Value |
|
+
+----------------------+--------+
----------------------+--------+
|
| rapid_cluster_status
rapid_cluster_status |
| ON
ON |
|
|
| rapid_service_status
rapid_service_status |
| ONLINE
ONLINE |
|
+
+----------------------+--------+
----------------------+--------+
HeatWave Ready
Copyright @ 2022 Oracle and/or its affiliates.
69
76. Load Data to HeatWave
We now use the load command printed during the Estimate Node Count step:
SQL
SQL >
> CALL
CALL sys
sys.
.heatwave_load
heatwave_load(
(JSON_ARRAY
JSON_ARRAY(
('piday'
'piday')
),
, NULL
NULL)
);
;
Copyright @ 2022 Oracle and/or its affiliates.
70
77. Load Data to HeatWave (2)
This operation returns a report:
.
..
..
.
+
+-------------------------------------------------------------------------------+
-------------------------------------------------------------------------------+
|
| LOAD
LOAD SUMMARY
SUMMARY |
|
+
+-------------------------------------------------------------------------------+
-------------------------------------------------------------------------------+
|
| |
|
|
| SCHEMA
SCHEMA TABLES
TABLES TABLES
TABLES COLUMNS
COLUMNS LOAD
LOAD |
|
|
| NAME LOADED FAILED LOADED DURATION
NAME LOADED FAILED LOADED DURATION |
|
|
| ------ ------ ------ ------- -------- |
------ ------ ------ ------- -------- |
|
| `
`piday
piday`
` 3
3 0
0 12
12 1.84
1.84 s
s |
|
|
| |
|
+
+-------------------------------------------------------------------------------+
-------------------------------------------------------------------------------+
6
6 rows
rows in
in set
set (
(1.9237
1.9237 sec
sec)
)
Copyright @ 2022 Oracle and/or its affiliates.
71
78. ... and now ?
SQL
SQL >
> select
select *
* from
from (
(select
select device_id
device_id,
, max
max(
(value
value)
) as
as `
`max temp
max temp`
`,
, min
min(
(value
value)
) as
as `
`min temp
min temp`
`,
,
avg
avg(
(value
value)
) as
as `
`avg temp
avg temp`
` from
from temperature_history
temperature_history group
group by
by device_id
device_id)
) a
a
natural
natural join
join (
(select
select device_id
device_id,
, max
max(
(value
value)
) as
as `
`max humidity
max humidity`
`,
, min
min(
(value
value)
) as
as `
`min humidity
min humidity`
`,
,
avg
avg(
(value
value)
) as
as `
`avg humidity
avg humidity`
` from
from humidity_history
humidity_history group
group by
by device_id
device_id)
) b
b ;
;
+
+------------------------------+----------+----------+-----------+--------------+--------------+--------------+
------------------------------+----------+----------+-----------+--------------+--------------+--------------+
|
| device_id
device_id |
| max
max temp
temp |
| min
min temp
temp |
| avg
avg temp
temp |
| max humidity
max humidity |
| min humidity
min humidity |
| avg humidity
avg humidity |
|
+
+------------------------------+----------+----------+-----------+--------------+--------------+--------------+
------------------------------+----------+----------+-----------+--------------+--------------+--------------+
|
| 00006227543
00006227543c0000000000000003
c0000000000000003 |
| 814.36
814.36 |
| 0.00
0.00 |
| 3.114047
3.114047 |
| 800.21
800.21 |
| 1.00
1.00 |
| 6.609431
6.609431 |
|
|
| 00006227543
00006227543c0000000000000001
c0000000000000001 |
| 142.94
142.94 |
| 9.00
9.00 |
| 11.708011
11.708011 |
| 169.86
169.86 |
| 40.00
40.00 |
| 45.203256
45.203256 |
|
|
| 00006227543
00006227543c0000000000000002
c0000000000000002 |
| 29.99
29.99 |
| 20.00
20.00 |
| 22.513379
22.513379 |
| 65.00
65.00 |
| 55.00
55.00 |
| 60.000384
60.000384 |
|
|
| 00006227543
00006227543c0000000000000004
c0000000000000004 |
| 288.44
288.44 |
| 10.00
10.00 |
| 12.567650
12.567650 |
| 279.32
279.32 |
| 30.00
30.00 |
| 35.062746
35.062746 |
|
+
+------------------------------+----------+----------+-----------+--------------+--------------+--------------+
------------------------------+----------+----------+-----------+--------------+--------------+--------------+
4
4 rows
rows in
in set
set (
(0.1049
0.1049 sec
sec)
)
Copyright @ 2022 Oracle and/or its affiliates.
72
79. ... and now ?
SQL
SQL >
> select
select *
* from
from (
(select
select device_id
device_id,
, max
max(
(value
value)
) as
as `
`max temp
max temp`
`,
, min
min(
(value
value)
) as
as `
`min temp
min temp`
`,
,
avg
avg(
(value
value)
) as
as `
`avg temp
avg temp`
` from
from temperature_history
temperature_history group
group by
by device_id
device_id)
) a
a
natural
natural join
join (
(select
select device_id
device_id,
, max
max(
(value
value)
) as
as `
`max humidity
max humidity`
`,
, min
min(
(value
value)
) as
as `
`min humidity
min humidity`
`,
,
avg
avg(
(value
value)
) as
as `
`avg humidity
avg humidity`
` from
from humidity_history
humidity_history group
group by
by device_id
device_id)
) b
b ;
;
+
+------------------------------+----------+----------+-----------+--------------+--------------+--------------+
------------------------------+----------+----------+-----------+--------------+--------------+--------------+
|
| device_id
device_id |
| max
max temp
temp |
| min
min temp
temp |
| avg
avg temp
temp |
| max humidity
max humidity |
| min humidity
min humidity |
| avg humidity
avg humidity |
|
+
+------------------------------+----------+----------+-----------+--------------+--------------+--------------+
------------------------------+----------+----------+-----------+--------------+--------------+--------------+
|
| 00006227543
00006227543c0000000000000003
c0000000000000003 |
| 814.36
814.36 |
| 0.00
0.00 |
| 3.114047
3.114047 |
| 800.21
800.21 |
| 1.00
1.00 |
| 6.609431
6.609431 |
|
|
| 00006227543
00006227543c0000000000000001
c0000000000000001 |
| 142.94
142.94 |
| 9.00
9.00 |
| 11.708011
11.708011 |
| 169.86
169.86 |
| 40.00
40.00 |
| 45.203256
45.203256 |
|
|
| 00006227543
00006227543c0000000000000002
c0000000000000002 |
| 29.99
29.99 |
| 20.00
20.00 |
| 22.513379
22.513379 |
| 65.00
65.00 |
| 55.00
55.00 |
| 60.000384
60.000384 |
|
|
| 00006227543
00006227543c0000000000000004
c0000000000000004 |
| 288.44
288.44 |
| 10.00
10.00 |
| 12.567650
12.567650 |
| 279.32
279.32 |
| 30.00
30.00 |
| 35.062746
35.062746 |
|
+
+------------------------------+----------+----------+-----------+--------------+--------------+--------------+
------------------------------+----------+----------+-----------+--------------+--------------+--------------+
4
4 rows
rows in
in set
set (
(0.1049
0.1049 sec
sec)
)
from 2.0747 sec to 0.1049 sec !!
20x faster !
Copyright @ 2022 Oracle and/or its affiliates.
72
80. the second example:
SQL
SQL >
> select
select *
* from
from (
(
select
select date
date(
(time_stamp
time_stamp)
) as
as `
`day
day`
`,
, device_id
device_id,
, count
count(
(*
*)
) as
as `
`tot
tot`
`,
,
max
max(
(value
value)
) as
as `
`max hum
max hum`
`,
, min
min(
(value
value)
) as
as `
`min hum
min hum`
`,
, avg
avg(
(value
value)
) as
as `
`avg hum
avg hum`
`
from
from humidity_history
humidity_history group
group by
by device_id
device_id,
, day
day)
) a
a
natural
natural join
join (
(
select
select date
date(
(time_stamp
time_stamp)
) as
as `
`day
day`
`,
, device_id
device_id,
, count
count(
(*
*)
) as
as `
`tot
tot`
`,
,
max
max(
(value
value)
) as
as `
`max temp
max temp`
`,
, min
min(
(value
value)
) as
as `
`min temp
min temp`
`,
, avg
avg(
(value
value)
) as
as `
`avg temp
avg temp`
`
from
from temperature_history
temperature_history group
group by
by device_id
device_id,
, day
day)
) b
b order
order by
by day
day,
, device_id
device_id;
;
+
+------------+------------------------------+--------+---------+---------+-----------+----------+----------+-----------+
------------+------------------------------+--------+---------+---------+-----------+----------+----------+-----------+
|
| day
day |
| device_id
device_id |
| tot
tot |
| max hum
max hum |
| min hum
min hum |
| avg hum
avg hum |
| max
max temp
temp |
| min
min temp
temp |
| avg
avg temp
temp |
|
+
+------------+------------------------------+--------+---------+---------+-----------+----------+----------+-----------+
------------+------------------------------+--------+---------+---------+-----------+----------+----------+-----------+
|
| 2022
2022-
-03
03-
-09
09 |
| 00006227543
00006227543c0000000000000002
c0000000000000002 |
| 14534
14534 |
| 65.00
65.00 |
| 55.00
55.00 |
| 60.009272
60.009272 |
| 29.99
29.99 |
| 20.00
20.00 |
| 22.597117
22.597117 |
|
|
| 2022
2022-
-03
03-
-09
09 |
| 00006227543
00006227543c0000000000000003
c0000000000000003 |
| 31605
31605 |
| 800.21
800.21 |
| 1.00
1.00 |
| 8.570860
8.570860 |
| 814.36
814.36 |
| 0.00
0.00 |
| 5.079732
5.079732 |
|
|
| 2022
2022-
-03
03-
-09
09 |
| 00006227543
00006227543c0000000000000004
c0000000000000004 |
| 31284
31284 |
| 279.32
279.32 |
| 30.00
30.00 |
| 35.294440
35.294440 |
| 288.44
288.44 |
| 10.00
10.00 |
| 12.797445
12.797445 |
|
|
| 2022
2022-
-03
03-
-10
10 |
| 00006227543
00006227543c0000000000000001
c0000000000000001 |
| 115609
115609 |
| 50.00
50.00 |
| 40.00
40.00 |
| 45.001736
45.001736 |
| 14.00
14.00 |
| 9.00
9.00 |
| 11.499157
11.499157 |
|
|
| 2022
2022-
-03
03-
-10
10 |
| 00006227543
00006227543c0000000000000002
c0000000000000002 |
| 100913
100913 |
| 65.00
65.00 |
| 55.00
55.00 |
| 59.999104
59.999104 |
| 25.00
25.00 |
| 20.00
20.00 |
| 22.501318
22.501318 |
|
|
| 2022
2022-
-03
03-
-10
10 |
| 00006227543
00006227543c0000000000000003
c0000000000000003 |
| 101465
101465 |
| 11.00
11.00 |
| 1.00
1.00 |
| 5.998472
5.998472 |
| 5.00
5.00 |
| 0.00
0.00 |
| 2.501762
2.501762 |
|
|
| 2022
2022-
-03
03-
-10
10 |
| 00006227543
00006227543c0000000000000004
c0000000000000004 |
| 101044
101044 |
| 40.00
40.00 |
| 30.00
30.00 |
| 34.991011
34.991011 |
| 15.00
15.00 |
| 10.00
10.00 |
| 12.496504
12.496504 |
|
+
+------------+------------------------------+--------+---------+---------+-----------+----------+----------+-----------+
------------+------------------------------+--------+---------+---------+-----------+----------+----------+-----------+
7
7 rows
rows in
in set
set (
(0.1267
0.1267 sec
sec)
)
Copyright @ 2022 Oracle and/or its affiliates.
73
81. More Data : more di erence !
Now let's use again the second example with more data (7 days):
Without HeatWave:
90
90 rows
rows in
in set
set (
(5
5 min
min 3.3237
3.3237 sec
sec)
)
Copyright @ 2022 Oracle and/or its affiliates.
74
82. More Data : more di erence !
Now let's use again the second example with more data (7 days):
Without HeatWave:
90
90 rows
rows in
in set
set (
(5
5 min
min 3.3237
3.3237 sec
sec)
)
With HeatWave:
90
90 rows
rows in
in set
set (
(0.8620
0.8620 sec
sec)
)
from 363.3237 sec to 0.8620 sec ! 421x faster !!
Copyright @ 2022 Oracle and/or its affiliates.
74
83. More Data : more di erence !
And this is with 5GB to parse:
SQL
SQL>
> select
select format_bytes
format_bytes(
(sum
sum(
(data_length
data_length)
))
) DATA
DATA,
,
format_bytes
format_bytes(
(sum
sum(
(index_length
index_length)
))
) INDEXES
INDEXES,
,
format_bytes
format_bytes(
(sum
sum(
(data_length
data_length +
+ index_length
index_length)
))
) 'TOTAL SIZE'
'TOTAL SIZE'
from
from information_schema
information_schema.
.TABLES
TABLES order
order by
by data_length
data_length +
+ index_length
index_length;
;
+
+----------+----------+------------+
----------+----------+------------+
|
| DATA
DATA |
| INDEXES
INDEXES |
| TOTAL SIZE
TOTAL SIZE |
|
+
+----------+----------+------------+
----------+----------+------------+
|
| 4.23
4.23 GiB
GiB |
| 1.37
1.37 GiB
GiB |
| 5.60
5.60 GiB
GiB |
|
+
+----------+----------+------------+
----------+----------+------------+
Copyright @ 2022 Oracle and/or its affiliates.
75
84. Without HeatWave:
44
44 rows
rows in
in set
set (
(10
10 min
min 14.1022
14.1022 sec
sec)
)
With HeatWave:
45
45 rows
rows in
in set
set (
(1.6051
1.6051 sec
sec)
)
Let's double the data:
+
+----------+----------+------------+
----------+----------+------------+
|
| DATA
DATA |
| INDEXES
INDEXES |
| TOTAL SIZE
TOTAL SIZE |
|
+
+----------+----------+------------+
----------+----------+------------+
|
| 8.66
8.66 GiB
GiB |
| 2.93
2.93 GiB
GiB |
| 11.59
11.59 GiB
GiB |
|
+
+----------+----------+------------+
----------+----------+------------+
69M ROWS
Copyright @ 2022 Oracle and/or its affiliates.
76
85. MySQL & HeatWave for your IoT Projects
Copyright @ 2022 Oracle and/or its affiliates.
77
86. MySQL & HeatWave
When having to deal with large amount of data for Analytics, this is the traditional
architecture:
Copyright @ 2022 Oracle and/or its affiliates.
78
87. MySQL & HeatWave - no more ETL required
Single MySQL database for OLTP & Analytics applications
All existing applications work without any changes
Extreme performance
Copyright @ 2022 Oracle and/or its affiliates.
79
88. MySQL & HeatWave - one solution !
Copyright @ 2022 Oracle and/or its affiliates.
80
89. Using HeatWave ?
SQL
SQL>
> show
show global
global status
status like
like 'rapid_query_offload_count'
'rapid_query_offload_count';
;
+
+---------------------------+-------+
---------------------------+-------+
|
| Variable_name
Variable_name |
| Value
Value |
|
+
+---------------------------+-------+
---------------------------+-------+
|
| rapid_query_offload_count
rapid_query_offload_count |
| 17
17 |
|
+
+---------------------------+-------+
---------------------------+-------+
The EXPLAIN command for a query will have the following value for Extra when using
HeatWave:
Using secondary engine RAPID
Using secondary engine RAPID
Copyright @ 2022 Oracle and/or its affiliates.
81
90. More with Autopilot Machine Learning
HeatWave includes several Autopilot processes, the following ones are avaible from the
SQL prompt when HeatWave is enabled:
Autopilot Encoding: Determines the optimal representation of columns loaded into
HeatWave by analyzing HeatWave query history, which improves query performance
and minimizes the required cluster size.
Autopilot Placement: Recommends how tables should be partitioned in memory to
achieve the best query performance, and estimates the expected performance
improvement
More Info: h ps://dev.mysql.com/doc/heatwave/en/heatwave-autopilot.html
Copyright @ 2022 Oracle and/or its affiliates.
82
93. HeatWave and Oracle Analytics Cloud
fast realtime analytics
Copyright @ 2022 Oracle and/or its affiliates.
84
94. Comprehensive cloud-native analytics
platform
Data visualization, data preparation,
data quality and data Flows
ML and AI embedded throughout
Natural language processing and
generation
Self upgrading, self patching, self
securing
Oracle Analytics Cloud
Complete Analytics Platform for Business Users, Developers and IT
Copyright @ 2022 Oracle and/or its affiliates.
85
97. From Multiple Native Connectors including
MySQL !
Creating a new connection to our MySQL
database instance:
Using Oracle Analytics Cloud with MySQL HeatWave
Copyright @ 2022 Oracle and/or its affiliates.
88
98. Using Oracle Analytics Cloud with MySQL HeatWave
Copyright @ 2022 Oracle and/or its affiliates.
89
99. For Data Modeling, OAC supports...
Copyright @ 2022 Oracle and/or its affiliates.
90
100. Now we can create our dataset:
Using Oracle Analytics Cloud with MySQL HeatWave
Copyright @ 2022 Oracle and/or its affiliates.
91
101. We search and select our connection
(piday):
Using Oracle Analytics Cloud with MySQL HeatWave
Copyright @ 2022 Oracle and/or its affiliates.
92
102. Using Oracle Analytics Cloud with MySQL HeatWave
Copyright @ 2022 Oracle and/or its affiliates.
93
103. Using Oracle Analytics Cloud with MySQL HeatWave
Copyright @ 2022 Oracle and/or its affiliates.
94
104. Using Oracle Analytics Cloud with MySQL HeatWave
We join using device_id eld:
Copyright @ 2022 Oracle and/or its affiliates.
95
105. Using Oracle Analytics Cloud with MySQL HeatWave
Copyright @ 2022 Oracle and/or its affiliates.
96
106. Using Oracle Analytics Cloud with MySQL HeatWave
Don't forget to specify that we want live data !
Copyright @ 2022 Oracle and/or its affiliates.
97
107. Using Oracle Analytics Cloud with MySQL HeatWave
Retrieving data from a JSON document in a collection.
Let's return the device_id as VARCHAR and its short_name using VIRTUAL COLUMNS:
SQL
SQL>
> alter
alter table
table devices
devices add
add device_id
device_id varchar
varchar(
(32
32)
)
generated always
generated always as
as (
(doc
doc-
->>
>>'$._id'
'$._id')
)
SQL
SQL>
> alter
alter table
table devices
devices add
add short_name
short_name varchar
varchar(
(20
20)
)
generated always
generated always as
as (
(doc
doc-
->>
>>'$.short_name'
'$.short_name')
);
;
Copyright @ 2022 Oracle and/or its affiliates.
98
108. Using Oracle Analytics Cloud with MySQL HeatWave
We can now retrieved them (and index them if needed) without having to use the special
JSON notation:
SQL
SQL>
> select
select device_id
device_id,
, short_name
short_name from
from devices
devices;
;
+
+------------------------------+------------+
------------------------------+------------+
|
| device_id
device_id |
| short_name
short_name |
|
+
+------------------------------+------------+
------------------------------+------------+
|
| 00006227543
00006227543c0000000000000001
c0000000000000001 |
| lefredPi
lefredPi |
|
|
| 00006227543
00006227543c0000000000000002
c0000000000000002 |
| fake01
fake01 |
|
|
| 00006227543
00006227543c0000000000000003
c0000000000000003 |
| fake02
fake02 |
|
|
| 00006227543
00006227543c0000000000000004
c0000000000000004 |
| fake03
fake03 |
|
+
+------------------------------+------------+
------------------------------+------------+
4
4 rows
rows in
in set
set (
(0.0284
0.0284 sec
sec)
)
Copyright @ 2022 Oracle and/or its affiliates.
99
109. Using Oracle Analytics Cloud with MySQL HeatWave
Copyright @ 2022 Oracle and/or its affiliates.
100
110. Using Oracle Analytics Cloud with MySQL HeatWave
Copyright @ 2022 Oracle and/or its affiliates.
101
111. Using Oracle Analytics Cloud with MySQL HeatWave
Copyright @ 2022 Oracle and/or its affiliates.
102
112. Using Oracle Analytics Cloud with MySQL HeatWave
Copyright @ 2022 Oracle and/or its affiliates.
103
113. For Data Preparation, OAC supports...
Copyright @ 2022 Oracle and/or its affiliates.
104
114. For Data Exploration, OAC supports...
Copyright @ 2022 Oracle and/or its affiliates.
105
116. For Data Visualization, OAC supports... (2)
As a developer you could even check the performance parameters of your visualizations:
Copyright @ 2022 Oracle and/or its affiliates.
107
120. Using Oracle Analytics Cloud with MySQL HeatWave
Easy creation of real-time dashboard of all the data collected by the Raspberry Pi
Copyright @ 2022 Oracle and/or its affiliates.
111
121. Summary
our journey from IoT device to HeatWave and Analyitcs
Copyright @ 2022 Oracle and/or its affiliates.
112
122. Summary of our journey
Copyright @ 2022 Oracle and/or its affiliates.
113
123. Summary of our journey
We started from a simple Raspberry Pi
Copyright @ 2022 Oracle and/or its affiliates.
113
124. Summary of our journey
We started from a simple Raspberry Pi
We collected a lot of data
Copyright @ 2022 Oracle and/or its affiliates.
113
125. Summary of our journey
We started from a simple Raspberry Pi
We collected a lot of data
We ran queries super fast and were ready for Analitycs without any ETL service
Copyright @ 2022 Oracle and/or its affiliates.
113
126. Summary of our journey
We started from a simple Raspberry Pi
We collected a lot of data
We ran queries super fast and were ready for Analitycs without any ETL service
We used the limitless OAC capabilities to process, vizualize and forecast the data
Copyright @ 2022 Oracle and/or its affiliates.
113
127. Summary of our journey
We started from a simple Raspberry Pi
We collected a lot of data
We ran queries super fast and were ready for Analitycs without any ETL service
We used the limitless OAC capabilities to process, vizualize and forecast the data
and all this thanks to MySQL HeatWave !
Copyright @ 2022 Oracle and/or its affiliates.
113
128. Want more
Swag ?
Download a free trial
and get bonus swag on top of the Pi Day swag kit!
Copyright @ 2022 Oracle and/or its affiliates.
114
129. Once your email is whitelisted, go to bit.ly/piday-freetrial and click the Sign Up bu on
Copyright @ 2022 Oracle and/or its affiliates.
115
130. Click Verify my email bu on
Enter your Country/Territory, First Name, Last Name, and Email
Check the box if you are a human and complete the Captcha authentication
Copyright @ 2022 Oracle and/or its affiliates.
116
131. Click the Verify Email bu on
You will be presented with an o er for $500 in free credits, click the Select O er bu on
Go to the email account that was used to register for this event and look for the Oracle
Cloud email asking to verify the email address and create your Oracle account.
Copyright @ 2022 Oracle and/or its affiliates.
117
132. Enter required elds under Account
information
Read the Terms of Use and click the
Continue bu on
Copyright @ 2022 Oracle and/or its affiliates.
118
133. Enter your Address and Phone Number
Click the Continue bu on
Read the terms and conditions and
acknowledge the Agreement.
Click the Start my free trial bu on
Copyright @ 2022 Oracle and/or its affiliates.
119
134. Your Oracle Cloud Infrastructure (OCI) tenancy is now being provisioned.
Copyright @ 2022 Oracle and/or its affiliates.
120
135. Welcome to your Oracle Cloud Infrastructure (OCI) tenancy
Copyright @ 2022 Oracle and/or its affiliates.
121
142. Resources (2)
Try a Live Lab: MySQL Database Service powered by HeatWave and Oracle Analytics Cloud:
h ps://apexapps.oracle.com/pls/apex/dbpm/r/livelabs/workshop-a endee-2?
p210_workshop_id=870&p210_type=1&session=2731606019312
Copyright @ 2022 Oracle and/or its affiliates.
128