SlideShare ist ein Scribd-Unternehmen logo
1 von 155
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Connor McDonald
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
2
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
3
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
4
Getting in touch is easy...
connor-mcdonald.com
https://linktr.ee/connor
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
6https://asktom.oracle.com
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
https://asktom.oracle.com/officehours
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
200 hours free access so far
8
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
before we begin
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
let's look at real life ...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
"We'd never do that .... that's stupid"
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
but everyone does ... :-(
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
the most common PLSQL program
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> declare
2 cursor c_products is
3 select aisle, item, descr
4 from hardware;
5 l_each c_products%rowtype;
6 begin
7 open c_products;
8 loop
9 fetch c_products
10 into l_each;
11 exit when c_products%notfound;
12 end loop;
13 close c_products;
14 end;
15 /
PL/SQL procedure successfully completed.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
our setup for this session
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> create table HARDWARE
2 ( aisle NUMBER(5),
3 item NUMBER(12),
4 descr CHAR(50),
5 stocked DATE
6 );
Table created.
SQL> insert /*+ APPEND */ into HARDWARE
2 select trunc(rownum/1000)+1 aisle,
3 rownum item,
4 'Description '||rownum descr,
5 to_date('01-JAN-2011','dd-mon-yyyy')+rownum/86400
6 from
7 ( select 1 from dual connect by level <= 1000),
8 ( select 1 from dual connect by level <= 1000);
1000000 rows created.
SQL> create index HARDWARE_IX on HARDWARE ( aisle, item );
Index created.
1,000,000 items,
across 1000 aisles
quick access to
items in an aisle
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
no matter what platform
18
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
no matter what direction
20
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
row by row :-(
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
"The database is slow"
Part 1
reading data
23
querying data
data is stored in blocks | pages
to read data, you read blocks...
SQL> select *
2 from EMP
3 where ...
/u01/my_data1.dat
memory
memory access = controlled access
SQL> select *
2 from EMP
3 where 

SQL> update EMP
2 set 

3 where 

SQL> select *
2 from EMP
3 where 

SQL> insert into
2 EMP
3 values (
)
SQL> select *
2 from CUSTOMER
3 /
SQL> select max(EMP)
2 from DEPT
SQL> delete
2 from DEPT
3 /
a quick primer on (database) memory
32
metaphor
35
limited resource
lots of people want it
concurrent access causes problems
it's a complex system
37
same with memory
SGA
SGA
protected by
SGA
protected by
1) get latch
SGA
protected by
2) access memory
SGA
protected by
3) release latch
latch contention
SGA
protected by
someone must wait ...
active wait
spinning
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
46
latch contention....
hurts CPU...
49
hurts concurrency
YOU
GET
NOTHING
DONE
back to reading data
SQL> select *
2 from EMP
3 where ...
/u01/my_data1.dat
memory
we have to latch !
‱ Get latch
‱ Search along list of blocks in memory
‱ Read block
‱ Extract row of interest
‱ Release latch
‱ Give row back to client
"fetch a row"
58
SQL>
...
9 fetch c_products
10 into l_each;
...
lots of rows
lots of latching
typical program
‱ Get latch
‱ Walk along list
‱ Get block
‱ Extract single row
‱ Release latch
‱ Give row back to client
‱ Get latch (again)
‱ Walk along list (again)
‱ Get block (again)
‱ Extract single row
‱ Release latch (again)
‱ Give row back to client (again)
Row #1
Row #2
‱ Get latch (again)
‱ Walk along list (again)
‱ Get block (again)
‱ Extract single row
‱ Release latch (again)
‱ Give row back to client (again)
Row #3
62
loop
fetch c_products
into l_each;
exit when c_products%notfound;
end loop;
a better strategy.... “pinning”
"fetch a row"
‱ Get latch
‱ Walk along list
‱ Get block
‱ Pin the block
‱ Release latch
‱ Give row 1 back to client
‱ Give row 2 back to client


‱ Give row n to client
‱ Get latch
‱ Walk along list
‱ Remove my pin on the block
‱ Release latch
“and .. I’ll will need
several rows from
this block”
Connor is
using this
block
how do you say
“I may want many rows” ?
the client is in charge
SQL> set arraysize 50 stmt.setFetchSize(50)
proc prefetch=50 reader.FetchSize = 50
plsql = bulk collect | bulk bind
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
quick revision
68
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
implicit cursor via select
69
SQL> declare
2 l_descr hardware.descr%type;
3 begin
4 select descr
5 into l_descr
6 from hardware
7 where aisle = 1 -- single
8 and item = 1; -- row
9 end;
bulk
SQL> declare
2 type t_descr_list is
3 table of hardware.descr%type;
4 l_descr_list t_descr_list;
5 begin
6 select descr
7 bulk collect
8 into l_descr_list
9 from hardware
10 where aisle = 1 -- multiple
11 and item between 1 and 100; -- rows
12 end;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
explicit cursor
70
SQL> declare
2 cursor c_tool_list is
3 select descr
4 from hardware
5 where aisle = 1
6 and item between 1 and 500;
7
8 l_descr hardware.descr%type;
9 begin
10 open c_tool_list;
11 loop
12 fetch c_tool_list into l_descr;
13 exit when c_tool_list%notfound;
14 end loop;
15 close c_tool_list;
16 end;
bulk
SQL> declare
2 cursor c_tool_list is
3 select descr
4 from hardware
5 where aisle = 1
6 and item between 1 and 500;
7
8 type t_descr_list is
9 table of c_tool_list%rowtype;
10 l_descr_list t_descr_list;
11
12 begin
13 open c_tool_list;
14 fetch c_tool_list
15 bulk collect into l_descr_list;
16 close c_tool_list;
17 end;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
implicit cursor
71
SQL> begin
2 for i in (
3 select descr
4 from hardware
5 where aisle = 1
6 and item between 1 and 500 )
7 loop
8 [processing]
9 end loop;
10 end;
bulk
SQL> begin
2 for i in (
3 select descr
4 from hardware
5 where aisle = 1
6 and item between 1 and 500 )
7 loop
8 [processing]
9 end loop;
10 end;
SQL> select value
2 from v$parameter
3 where name = 'plsql_optimize_level';
VALUE
-----
2
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
"But why bother?"
bulk1.sql
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
wow !
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
it's more than just elapsed time
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> exec dbms_monitor.session_trace_enable;
[repeat the demo]
SQL> exec dbms_monitor.session_trace_disable;
SQL ID: frmas27snufjy Plan Hash: 652399433
SELECT DESCR
FROM HARDWARE
call count cpu elapsed disk query current rows
------- ------- -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1000001 4.56 3.70 0 1000011 0 1000000
------- ------- -------- ---------- ---------- ---------- ---------- ----------
total 1000003 4.56 3.70 0 1000011 0 1000000
SQL ID: frmas27snufjy Plan Hash: 652399433
SELECT DESCR
FROM HARDWARE
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.34 0 10100 0 1000000
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 3 0.00 0.34 0 10100 0 1000000
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
but ...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
all that data goes somewhere
78
13 open c_tool_list;
14 fetch c_tool_list
15 bulk collect into l_descr_list; -- 1,000,000 rows into an array
16 close c_tool_list;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> select * from v$mystats
2 where name like '%pga%'
3 /
NAME VALUE
------------------------------ ----------
session pga memory 201534672
session pga memory max 201534672
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
200m of memory !
per session
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
law of diminishing returns
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
this was about pinning
82
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
typical block is 8KB
83
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
NAME VALUE
------------------------------ ----------
session pga memory 2127112
session pga memory max 2155912
SQL> declare
2 cursor c_tool_list is
3 select descr
4 from hardware;
5
6 type t_descr_list is table of c_tool_list%rowtype;
7 l_descr_list t_descr_list;
8
9 begin
10 open c_tool_list;
11 loop
12 fetch c_tool_list
13 bulk collect
14 into l_descr_list limit 500;
15 exit when c_tool_list%notfound;
16 end loop;
17 close c_tool_list;
18 end;
19 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.10
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
important !
85
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> declare
2 cursor c_tool_list is
3 select descr
4 from hardware;
5
6 type t_descr_list is table of c_tool_list%rowtype;
7 l_descr_list t_descr_list;
8
9 begin
10 open c_tool_list;
11 loop
12 fetch c_tool_list
13 bulk collect
14 into l_descr_list limit 500;
1) array is replaced
15 exit when c_tool_list%notfound;
16 end loop;
17 close c_tool_list;
18 end;
19 /
2) < 500 = "not found"
[processing here!]
for i in 1 .. l_descr_list.count
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
even easier ...
87
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
implicit cursor
88
SQL> begin
2 for i in (
3 select descr
4 from hardware
5 where aisle = 1
6 and item between 1 and 500 )
7 loop
8 [processing]
9 end loop;
10 end;
bulk
SQL> begin
2 for i in (
3 select descr
4 from hardware
5 where aisle = 1
6 and item between 1 and 500 )
7 loop
8 [processing]
9 end loop;
10 end;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
guidelines
89
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
1) single row
no change
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
91
SQL> declare
2 l_descr hardware.descr%type;
3 begin
4 select descr
5 into l_descr
6 from hardware
7 where aisle = 1 -- single
8 and item = 1; -- row
9 end;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
2) finite and "reasonable"
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
93
SQL> declare
2 type t_descr_list is
3 table of hardware.descr%type;
4 l_descr_list t_descr_list;
5 begin
6 select descr
7 bulk collect
8 into l_descr_list
9 from hardware
10 where aisle = 1
11 and item between 1 and 100;
12 end;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
note: subtle differences
94
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> declare
2 l_descr hardware.descr%type;
3 begin
4 select descr
5 into l_descr
6 from hardware
7 where aisle = 0
8 and item = 0;
9 end;
10 /
declare
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 4
SQL> declare
2 l_descr hardware.descr%type;
3 begin
4 select descr
5 into l_descr
6 from hardware
7 where aisle = 0
8 and item = 0;
9 dbms_output.put_line('YES!');
10 exception
11 when no_data_found then
12 dbms_output.put_line('NO!');
13 end;
14 /
NO!
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> declare
2 type t_descr_list is table of hardware.descr%type;
3 l_descr_list t_descr_list;
4 begin
5 select descr
6 bulk collect
7 into l_descr_list
8 from hardware
9 where aisle = 0
10 and item = 0;
11 dbms_output.put_line('YES!');
12 exception
13 when no_data_found then
14 dbms_output.put_line('NO!');
15 end;
16 /
YES!
no exception
if l_descr_list.count = 0 then raise no_data_found; end if;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
3) unknown number of rows
97
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
98
SQL> begin
2 for i in (
3 select descr
4 from hardware
5 where aisle = 1
6 and item between 1 and 500 )
7 loop
8 [processing]
9 end loop;
10 end;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
special case #1
99
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
100
SQL> begin
2 for i in (
3 select descr
4 from hardware
5 where aisle = 1
6 and item between 1 and 500 )
7 loop
8
...
...
exit [early] when [some condition];
...
..
19 end loop;
20 end;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
special case #2
101
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
dont forget this bit
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
reduce network roundtrips
103
larger array sizes
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
sidebar: SQL as well
104
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
a little known feature
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL Net de-duplicate
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> set autotrace traceonly stat
SQL> set arraysize 100
SQL> select aisle, item, descr
2 from hardware
3 where ...;
89405 rows selected.
Statistics
---------------------------------------------
4 recursive calls
0 db block gets
2452 consistent gets
0 physical reads
0 redo size
1198478 bytes sent via SQL*Net to client
107
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> select aisle, item, descr
2 from hardware
3 where ...
4 order by 1,2;
89405 rows selected.
Statistics
--------------------------------------------
14 recursive calls
0 db block gets
1507 consistent gets
0 physical reads
0 redo size
618820 bytes sent via SQL*Net to client
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
focus on blocks
109
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
focus on roundtrips
110
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Part 2
writing data
111
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
the same rules apply
112
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
conventional DML in PLSQL
113
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
114
SQL> declare
2 l_row hardware%rowtype;
3 begin
4 for i in 1 .. 100 loop
5 l_row.aisle := 1;
6 l_row.item := i;
7 insert into hardware values
8 ( l_row.aisle, l_row.item, l_row.descr) ;
9 end loop;
10 end;
11 /
PL/SQL procedure successfully completed.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
or even nicer (PLSQL only)
115
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
116
SQL> declare
2 l_row hardware%rowtype;
3 begin
4 for i in 1 .. 100 loop
5 l_row.aisle := 1;
6 l_row.item := i;
7 insert into hardware values l_row;
8 end loop;
9 end;
10 /
PL/SQL procedure successfully completed.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
DML bulk = "bulk bind / FORALL"
117
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
118
SQL> declare
2 type t_row_list is table of hardware%rowtype;
3 l_row t_row_list := t_row_list();
4 begin
5 for i in 1 .. 100 loop
6 l_row.extend;
7 l_row(i).aisle := 1;
8 l_row(i).item := i;
9 end loop;
10
11 forall i in 1 .. 100
12 insert into hardware values l_row(i);
13 end;
14 /
PL/SQL procedure successfully completed.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
"Is it worth the extra code?"
bulk2.sql
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
it's better than that
bulk3.sql
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
but ...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
... the same rules apply
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
all the data is somewhere
PGA memory
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
law of diminishing returns
bulk4.sql
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
no auto option :-(
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
100-1000 typically fine
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
one special case
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> insert /*+ APPEND_VALUES */
2 into HARDWARE ( item ) values (1);
1 row created.
SQL> select item from HARDWARE;
select item from HARDWARE
*
ERROR at line 1:
ORA-12838: cannot read/modify an object after modifying it in parallel
SQL> commit;
Commit complete.
SQL> select item from HARDWARE;
ITEM
----------
1
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
direct load
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
high speed, massive data loads
bulk7.sql
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
challenges with multi-row DML
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> alter table hardware
2 add constraint
3 hardware_chk check ( item > 0 );
SQL> begin
2 insert into hardware ( item ) values (1);
3 insert into hardware ( item ) values (-1);
4 insert into hardware ( item ) values (2);
5 insert into hardware ( item ) values (3);
6 insert into hardware ( item ) values (4);
7 insert into hardware ( item ) values (-2);
8 end;
9 /
ERROR at line 1:
ORA-02290: check constraint (MCDONAC.HARDWARE_CHK) violated
ORA-06512: at line 3
SQL> select * from hardware;
no rows selected
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> declare
2 type t_list is table of hardware.item%type;
3 l_rows t_list := t_list(1,-1,2,3,4,-2);
4 begin
5 forall i in 1 .. l_rows.count
6 insert into hardware ( item ) values (l_rows(i));
7 end;
8 /
declare
*
ERROR at line 1:
ORA-02290: check constraint (MCDONAC.HARDWARE_CHK) violated
ORA-06512: at line 5
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
issue #1: which row cause the problem
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
issue #2: none of the rows were stored
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SAVE EXCEPTIONS clause
bulk5.sql
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
also consider error logging
bulk6.sql
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
issue #3: sparseness
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> declare
2 type t_num_list is table of hardware.item%type index by pls_integer;
3
4 val t_num_list;
5 begin
6
7 val(10) := 10;
8 val(11) := 20;
9 val(12) := 20;
10
11 forall i in 1 .. val.count
12 insert into hardware ( item ) values (val(i));
13
14 end;
15 /
declare
*
ERROR at line 1:
ORA-22160: element at index [1] does not exist
ORA-06512: at line 11
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> declare
2 type t_num_list is table of hardware.item%type index by pls_integer;
3
4 val t_num_list;
5 begin
6
7 val(10) := 10;
8 val(11) := 20;
9 val(12) := 20;
10
11 forall i in val.first .. val.last
12 insert into hardware ( item ) values (val(i));
13
14 end;
15 /
PL/SQL procedure successfully completed.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
but ... contiguous is assumed
141
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> declare
2 type t_num_list is table of hardware.item%type index by pls_integer;
3
4 val t_num_list;
5 begin
6
7 val(10) := 10;
8 -- val(11) := 20;
9 val(12) := 20;
10
11 forall i in val.first .. val.last
12 insert into hardware ( item ) values (val(i));
13
14 end;
15 /
declare
*
ERROR at line 1:
ORA-22160: element at index [11] does not exist
ORA-06512: at line 11
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
INDICES OF clause
143
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> declare
2 type t_num_list is table of hardware.item%type index by pls_integer;
3
4 val t_num_list;
5 begin
6
7 val(10) := 10;
8 -- val(11) := 20;
9 val(12) := 20;
10
11 forall i in indices of val
12 insert into hardware ( item ) values (val(i));
13
14 end;
15 /
PL/SQL procedure successfully completed.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
homework :-)
145
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
VALUES OF clause
146
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
"How to get array benefits with SQL?"
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL does this automatically...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
full table scans
index range scans
prefetch
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
use SQL in preference to PLSQL where possible
150
for another day
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
wrap up
151
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
“relational”
not
“rowlational”
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
process data in sets not rows
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
use bulk collect / bulk bind where appropriate
Enjoy the rest of the conference!
https://linktr.ee/connor

Weitere Àhnliche Inhalte

Was ist angesagt?

OpenWorld 2018 - Pagination
OpenWorld 2018 - PaginationOpenWorld 2018 - Pagination
OpenWorld 2018 - PaginationConnor McDonald
 
Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019Connor McDonald
 
Latin America Tour 2019 - slow data and sql processing
Latin America Tour 2019  - slow data and sql processingLatin America Tour 2019  - slow data and sql processing
Latin America Tour 2019 - slow data and sql processingConnor McDonald
 
Flashback features in Oracle - UKOUG 2017
Flashback features in Oracle - UKOUG 2017Flashback features in Oracle - UKOUG 2017
Flashback features in Oracle - UKOUG 2017Connor McDonald
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featuesConnor McDonald
 
Hyderabad Mar 2019 - Autonomous Database
Hyderabad Mar 2019 - Autonomous DatabaseHyderabad Mar 2019 - Autonomous Database
Hyderabad Mar 2019 - Autonomous DatabaseConnor McDonald
 
pstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle databasepstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle databaseRiyaj Shamsudeen
 
Oracle trace data collection errors: the story about oceans, islands, and rivers
Oracle trace data collection errors: the story about oceans, islands, and riversOracle trace data collection errors: the story about oceans, islands, and rivers
Oracle trace data collection errors: the story about oceans, islands, and riversCary Millsap
 
Most important "trick" of performance instrumentation
Most important "trick" of performance instrumentationMost important "trick" of performance instrumentation
Most important "trick" of performance instrumentationCary Millsap
 
A close encounter_with_real_world_and_odd_perf_issues
A close encounter_with_real_world_and_odd_perf_issuesA close encounter_with_real_world_and_odd_perf_issues
A close encounter_with_real_world_and_odd_perf_issuesRiyaj Shamsudeen
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cConnor McDonald
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAsConnor McDonald
 
12 Things About 12c Release 2 for Developers
12 Things About 12c Release 2 for Developers12 Things About 12c Release 2 for Developers
12 Things About 12c Release 2 for DevelopersConnor McDonald
 
Finding Evil In DNS Traffic
Finding  Evil In DNS TrafficFinding  Evil In DNS Traffic
Finding Evil In DNS Trafficreal_slacker007
 
Unix Monitoring Tools
Unix Monitoring ToolsUnix Monitoring Tools
Unix Monitoring ToolsSEA Tecnologia
 
Rac 12c optimization
Rac 12c optimizationRac 12c optimization
Rac 12c optimizationRiyaj Shamsudeen
 
UKOUG, Oracle Transaction Locks
UKOUG, Oracle Transaction LocksUKOUG, Oracle Transaction Locks
UKOUG, Oracle Transaction LocksKyle Hailey
 
Đ­ĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒ ĐœĐ”ŃĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒŃ‹Đ” ŃƒŃĐ·ĐČĐžĐŒĐŸŃŃ‚Đž SAP
Đ­ĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒ ĐœĐ”ŃĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒŃ‹Đ” ŃƒŃĐ·ĐČĐžĐŒĐŸŃŃ‚Đž SAPĐ­ĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒ ĐœĐ”ŃĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒŃ‹Đ” ŃƒŃĐ·ĐČĐžĐŒĐŸŃŃ‚Đž SAP
Đ­ĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒ ĐœĐ”ŃĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒŃ‹Đ” ŃƒŃĐ·ĐČĐžĐŒĐŸŃŃ‚Đž SAPPositive Hack Days
 
Down the rabbit hole, profiling in Django
Down the rabbit hole, profiling in DjangoDown the rabbit hole, profiling in Django
Down the rabbit hole, profiling in DjangoRemco Wendt
 

Was ist angesagt? (20)

OpenWorld 2018 - Pagination
OpenWorld 2018 - PaginationOpenWorld 2018 - Pagination
OpenWorld 2018 - Pagination
 
Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019
 
Latin America Tour 2019 - slow data and sql processing
Latin America Tour 2019  - slow data and sql processingLatin America Tour 2019  - slow data and sql processing
Latin America Tour 2019 - slow data and sql processing
 
Flashback features in Oracle - UKOUG 2017
Flashback features in Oracle - UKOUG 2017Flashback features in Oracle - UKOUG 2017
Flashback features in Oracle - UKOUG 2017
 
Cool SQL Features
Cool SQL FeaturesCool SQL Features
Cool SQL Features
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featues
 
Hyderabad Mar 2019 - Autonomous Database
Hyderabad Mar 2019 - Autonomous DatabaseHyderabad Mar 2019 - Autonomous Database
Hyderabad Mar 2019 - Autonomous Database
 
pstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle databasepstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle database
 
Oracle trace data collection errors: the story about oceans, islands, and rivers
Oracle trace data collection errors: the story about oceans, islands, and riversOracle trace data collection errors: the story about oceans, islands, and rivers
Oracle trace data collection errors: the story about oceans, islands, and rivers
 
Most important "trick" of performance instrumentation
Most important "trick" of performance instrumentationMost important "trick" of performance instrumentation
Most important "trick" of performance instrumentation
 
A close encounter_with_real_world_and_odd_perf_issues
A close encounter_with_real_world_and_odd_perf_issuesA close encounter_with_real_world_and_odd_perf_issues
A close encounter_with_real_world_and_odd_perf_issues
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19c
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAs
 
12 Things About 12c Release 2 for Developers
12 Things About 12c Release 2 for Developers12 Things About 12c Release 2 for Developers
12 Things About 12c Release 2 for Developers
 
Finding Evil In DNS Traffic
Finding  Evil In DNS TrafficFinding  Evil In DNS Traffic
Finding Evil In DNS Traffic
 
Unix Monitoring Tools
Unix Monitoring ToolsUnix Monitoring Tools
Unix Monitoring Tools
 
Rac 12c optimization
Rac 12c optimizationRac 12c optimization
Rac 12c optimization
 
UKOUG, Oracle Transaction Locks
UKOUG, Oracle Transaction LocksUKOUG, Oracle Transaction Locks
UKOUG, Oracle Transaction Locks
 
Đ­ĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒ ĐœĐ”ŃĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒŃ‹Đ” ŃƒŃĐ·ĐČĐžĐŒĐŸŃŃ‚Đž SAP
Đ­ĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒ ĐœĐ”ŃĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒŃ‹Đ” ŃƒŃĐ·ĐČĐžĐŒĐŸŃŃ‚Đž SAPĐ­ĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒ ĐœĐ”ŃĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒŃ‹Đ” ŃƒŃĐ·ĐČĐžĐŒĐŸŃŃ‚Đž SAP
Đ­ĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒ ĐœĐ”ŃĐșŃĐżĐ»ŃƒĐ°Ń‚ĐžŃ€ŃƒĐ”ĐŒŃ‹Đ” ŃƒŃĐ·ĐČĐžĐŒĐŸŃŃ‚Đž SAP
 
Down the rabbit hole, profiling in Django
Down the rabbit hole, profiling in DjangoDown the rabbit hole, profiling in Django
Down the rabbit hole, profiling in Django
 

Ähnlich wie APEX Connect 2019 - array/bulk processing in PLSQL

Sangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL JediSangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL JediConnor McDonald
 
Tokyo APAC Groundbreakers tour - The Complete Java Developer
Tokyo APAC Groundbreakers tour - The Complete Java DeveloperTokyo APAC Groundbreakers tour - The Complete Java Developer
Tokyo APAC Groundbreakers tour - The Complete Java DeveloperConnor McDonald
 
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdfDatabase & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdfInSync2011
 
APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentConnor McDonald
 
Feb14 successful development
Feb14 successful developmentFeb14 successful development
Feb14 successful developmentConnor McDonald
 
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c OptimizerWellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c OptimizerConnor McDonald
 
Melbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without riskMelbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without riskConnor McDonald
 
Sangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12cSangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12cConnor McDonald
 
OpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 minsOpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 minsConnor McDonald
 
Tom Kyte at Hotsos 2015
Tom Kyte at Hotsos 2015Tom Kyte at Hotsos 2015
Tom Kyte at Hotsos 2015Connor McDonald
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyPriyanka Aash
 
ORM2Pwn: Exploiting injections in Hibernate ORM
ORM2Pwn: Exploiting injections in Hibernate ORMORM2Pwn: Exploiting injections in Hibernate ORM
ORM2Pwn: Exploiting injections in Hibernate ORMMikhail Egorov
 
Find Anything In Your APEX App - Fuzzy Search with Oracle Text
Find Anything In Your APEX App - Fuzzy Search with Oracle TextFind Anything In Your APEX App - Fuzzy Search with Oracle Text
Find Anything In Your APEX App - Fuzzy Search with Oracle TextCarsten Czarski
 
AOS Lab 4: If you liked it, then you should have put a “lock” on it
AOS Lab 4: If you liked it, then you should have put a “lock” on itAOS Lab 4: If you liked it, then you should have put a “lock” on it
AOS Lab 4: If you liked it, then you should have put a “lock” on itZubair Nabi
 
Troubleshooting Tips and Tricks for Database 19c ILOUG Feb 2020
Troubleshooting Tips and Tricks for Database 19c   ILOUG Feb 2020Troubleshooting Tips and Tricks for Database 19c   ILOUG Feb 2020
Troubleshooting Tips and Tricks for Database 19c ILOUG Feb 2020Sandesh Rao
 
HPC Examples
HPC ExamplesHPC Examples
HPC ExamplesWendi Sapp
 
hacking-embedded-devices.pptx
hacking-embedded-devices.pptxhacking-embedded-devices.pptx
hacking-embedded-devices.pptxssuserfcf43f
 
A MySQL Odyssey - A Blackhole Crossover
A MySQL Odyssey - A Blackhole CrossoverA MySQL Odyssey - A Blackhole Crossover
A MySQL Odyssey - A Blackhole CrossoverKeith Hollman
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Pluginsamiable_indian
 

Ähnlich wie APEX Connect 2019 - array/bulk processing in PLSQL (20)

Sangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL JediSangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL Jedi
 
Tokyo APAC Groundbreakers tour - The Complete Java Developer
Tokyo APAC Groundbreakers tour - The Complete Java DeveloperTokyo APAC Groundbreakers tour - The Complete Java Developer
Tokyo APAC Groundbreakers tour - The Complete Java Developer
 
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdfDatabase & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
 
APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application development
 
Feb14 successful development
Feb14 successful developmentFeb14 successful development
Feb14 successful development
 
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c OptimizerWellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
 
Melbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without riskMelbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without risk
 
Sangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12cSangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12c
 
OpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 minsOpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 mins
 
Tom Kyte at Hotsos 2015
Tom Kyte at Hotsos 2015Tom Kyte at Hotsos 2015
Tom Kyte at Hotsos 2015
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
 
ORM2Pwn: Exploiting injections in Hibernate ORM
ORM2Pwn: Exploiting injections in Hibernate ORMORM2Pwn: Exploiting injections in Hibernate ORM
ORM2Pwn: Exploiting injections in Hibernate ORM
 
Find Anything In Your APEX App - Fuzzy Search with Oracle Text
Find Anything In Your APEX App - Fuzzy Search with Oracle TextFind Anything In Your APEX App - Fuzzy Search with Oracle Text
Find Anything In Your APEX App - Fuzzy Search with Oracle Text
 
AOS Lab 4: If you liked it, then you should have put a “lock” on it
AOS Lab 4: If you liked it, then you should have put a “lock” on itAOS Lab 4: If you liked it, then you should have put a “lock” on it
AOS Lab 4: If you liked it, then you should have put a “lock” on it
 
Troubleshooting Tips and Tricks for Database 19c ILOUG Feb 2020
Troubleshooting Tips and Tricks for Database 19c   ILOUG Feb 2020Troubleshooting Tips and Tricks for Database 19c   ILOUG Feb 2020
Troubleshooting Tips and Tricks for Database 19c ILOUG Feb 2020
 
HPC Examples
HPC ExamplesHPC Examples
HPC Examples
 
Hotsos 2012
Hotsos 2012Hotsos 2012
Hotsos 2012
 
hacking-embedded-devices.pptx
hacking-embedded-devices.pptxhacking-embedded-devices.pptx
hacking-embedded-devices.pptx
 
A MySQL Odyssey - A Blackhole Crossover
A MySQL Odyssey - A Blackhole CrossoverA MySQL Odyssey - A Blackhole Crossover
A MySQL Odyssey - A Blackhole Crossover
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Plugins
 

Mehr von Connor McDonald

Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQLConnor McDonald
 
UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsConnor McDonald
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousConnor McDonald
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresConnor McDonald
 
APEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousAPEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousConnor McDonald
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne Connor McDonald
 
OOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsOOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsConnor McDonald
 
OOW19 - Read consistency
OOW19 - Read consistencyOOW19 - Read consistency
OOW19 - Read consistencyConnor McDonald
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsConnor McDonald
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessionsConnor McDonald
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresConnor McDonald
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql featuresConnor McDonald
 
ANSI vs Oracle language
ANSI vs Oracle languageANSI vs Oracle language
ANSI vs Oracle languageConnor McDonald
 
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerOG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerConnor McDonald
 
OG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsOG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsConnor McDonald
 
OG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developersOG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developersConnor McDonald
 
Kscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processingKscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processingConnor McDonald
 
KScope19 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL FeaturesConnor McDonald
 

Mehr von Connor McDonald (19)

Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
 
UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tips
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL features
 
APEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousAPEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomous
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne
 
OOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsOOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAs
 
OOW19 - Read consistency
OOW19 - Read consistencyOOW19 - Read consistency
OOW19 - Read consistency
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applications
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessions
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
 
ANSI vs Oracle language
ANSI vs Oracle languageANSI vs Oracle language
ANSI vs Oracle language
 
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerOG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizer
 
OG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsOG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tips
 
OG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developersOG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developers
 
Kscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processingKscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processing
 
KScope19 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL Features
 

KĂŒrzlich hochgeladen

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĂșjo
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 

KĂŒrzlich hochgeladen (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

APEX Connect 2019 - array/bulk processing in PLSQL

  • 1. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Connor McDonald
  • 2. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 2
  • 3. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 3
  • 4. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 4
  • 5. Getting in touch is easy... connor-mcdonald.com https://linktr.ee/connor
  • 6. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 6https://asktom.oracle.com
  • 7. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. https://asktom.oracle.com/officehours
  • 8. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 200 hours free access so far 8
  • 9. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. before we begin
  • 10. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. let's look at real life ...
  • 11. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. "We'd never do that .... that's stupid"
  • 12. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. but everyone does ... :-(
  • 13. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. the most common PLSQL program
  • 14. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> declare 2 cursor c_products is 3 select aisle, item, descr 4 from hardware; 5 l_each c_products%rowtype; 6 begin 7 open c_products; 8 loop 9 fetch c_products 10 into l_each; 11 exit when c_products%notfound; 12 end loop; 13 close c_products; 14 end; 15 / PL/SQL procedure successfully completed.
  • 15. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. our setup for this session
  • 16. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> create table HARDWARE 2 ( aisle NUMBER(5), 3 item NUMBER(12), 4 descr CHAR(50), 5 stocked DATE 6 ); Table created. SQL> insert /*+ APPEND */ into HARDWARE 2 select trunc(rownum/1000)+1 aisle, 3 rownum item, 4 'Description '||rownum descr, 5 to_date('01-JAN-2011','dd-mon-yyyy')+rownum/86400 6 from 7 ( select 1 from dual connect by level <= 1000), 8 ( select 1 from dual connect by level <= 1000); 1000000 rows created. SQL> create index HARDWARE_IX on HARDWARE ( aisle, item ); Index created. 1,000,000 items, across 1000 aisles quick access to items in an aisle
  • 17. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. no matter what platform
  • 18. 18
  • 19. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. no matter what direction
  • 20. 20
  • 21. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. row by row :-(
  • 22. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. "The database is slow"
  • 25. data is stored in blocks | pages
  • 26. to read data, you read blocks...
  • 27. SQL> select * 2 from EMP 3 where ... /u01/my_data1.dat memory
  • 28. memory access = controlled access
  • 29. SQL> select * 2 from EMP 3 where 
 SQL> update EMP 2 set 
 3 where 
 SQL> select * 2 from EMP 3 where 
 SQL> insert into 2 EMP 3 values (
) SQL> select * 2 from CUSTOMER 3 / SQL> select max(EMP) 2 from DEPT SQL> delete 2 from DEPT 3 /
  • 30. a quick primer on (database) memory
  • 31.
  • 33.
  • 34.
  • 35. 35 limited resource lots of people want it concurrent access causes problems it's a complex system
  • 36.
  • 38. SGA
  • 46. spinning can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? 46
  • 47.
  • 51. YOU
  • 52. GET
  • 54. DONE
  • 56. SQL> select * 2 from EMP 3 where ... /u01/my_data1.dat memory
  • 57. we have to latch !
  • 58. ‱ Get latch ‱ Search along list of blocks in memory ‱ Read block ‱ Extract row of interest ‱ Release latch ‱ Give row back to client "fetch a row" 58 SQL> ... 9 fetch c_products 10 into l_each; ...
  • 62. ‱ Get latch ‱ Walk along list ‱ Get block ‱ Extract single row ‱ Release latch ‱ Give row back to client ‱ Get latch (again) ‱ Walk along list (again) ‱ Get block (again) ‱ Extract single row ‱ Release latch (again) ‱ Give row back to client (again) Row #1 Row #2 ‱ Get latch (again) ‱ Walk along list (again) ‱ Get block (again) ‱ Extract single row ‱ Release latch (again) ‱ Give row back to client (again) Row #3 62 loop fetch c_products into l_each; exit when c_products%notfound; end loop;
  • 63. a better strategy.... “pinning”
  • 64. "fetch a row" ‱ Get latch ‱ Walk along list ‱ Get block ‱ Pin the block ‱ Release latch ‱ Give row 1 back to client ‱ Give row 2 back to client 
 ‱ Give row n to client ‱ Get latch ‱ Walk along list ‱ Remove my pin on the block ‱ Release latch “and .. I’ll will need several rows from this block” Connor is using this block
  • 65. how do you say “I may want many rows” ?
  • 66. the client is in charge SQL> set arraysize 50 stmt.setFetchSize(50) proc prefetch=50 reader.FetchSize = 50
  • 67. plsql = bulk collect | bulk bind
  • 68. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. quick revision 68
  • 69. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. implicit cursor via select 69 SQL> declare 2 l_descr hardware.descr%type; 3 begin 4 select descr 5 into l_descr 6 from hardware 7 where aisle = 1 -- single 8 and item = 1; -- row 9 end; bulk SQL> declare 2 type t_descr_list is 3 table of hardware.descr%type; 4 l_descr_list t_descr_list; 5 begin 6 select descr 7 bulk collect 8 into l_descr_list 9 from hardware 10 where aisle = 1 -- multiple 11 and item between 1 and 100; -- rows 12 end;
  • 70. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. explicit cursor 70 SQL> declare 2 cursor c_tool_list is 3 select descr 4 from hardware 5 where aisle = 1 6 and item between 1 and 500; 7 8 l_descr hardware.descr%type; 9 begin 10 open c_tool_list; 11 loop 12 fetch c_tool_list into l_descr; 13 exit when c_tool_list%notfound; 14 end loop; 15 close c_tool_list; 16 end; bulk SQL> declare 2 cursor c_tool_list is 3 select descr 4 from hardware 5 where aisle = 1 6 and item between 1 and 500; 7 8 type t_descr_list is 9 table of c_tool_list%rowtype; 10 l_descr_list t_descr_list; 11 12 begin 13 open c_tool_list; 14 fetch c_tool_list 15 bulk collect into l_descr_list; 16 close c_tool_list; 17 end;
  • 71. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. implicit cursor 71 SQL> begin 2 for i in ( 3 select descr 4 from hardware 5 where aisle = 1 6 and item between 1 and 500 ) 7 loop 8 [processing] 9 end loop; 10 end; bulk SQL> begin 2 for i in ( 3 select descr 4 from hardware 5 where aisle = 1 6 and item between 1 and 500 ) 7 loop 8 [processing] 9 end loop; 10 end; SQL> select value 2 from v$parameter 3 where name = 'plsql_optimize_level'; VALUE ----- 2
  • 72. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. "But why bother?" bulk1.sql
  • 73. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. wow !
  • 74. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. it's more than just elapsed time
  • 75. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> exec dbms_monitor.session_trace_enable; [repeat the demo] SQL> exec dbms_monitor.session_trace_disable; SQL ID: frmas27snufjy Plan Hash: 652399433 SELECT DESCR FROM HARDWARE call count cpu elapsed disk query current rows ------- ------- -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 1000001 4.56 3.70 0 1000011 0 1000000 ------- ------- -------- ---------- ---------- ---------- ---------- ---------- total 1000003 4.56 3.70 0 1000011 0 1000000 SQL ID: frmas27snufjy Plan Hash: 652399433 SELECT DESCR FROM HARDWARE call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 1 0.00 0.34 0 10100 0 1000000 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 3 0.00 0.34 0 10100 0 1000000
  • 76. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. but ...
  • 77.
  • 78. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. all that data goes somewhere 78 13 open c_tool_list; 14 fetch c_tool_list 15 bulk collect into l_descr_list; -- 1,000,000 rows into an array 16 close c_tool_list;
  • 79. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> select * from v$mystats 2 where name like '%pga%' 3 / NAME VALUE ------------------------------ ---------- session pga memory 201534672 session pga memory max 201534672
  • 80. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 200m of memory ! per session
  • 81. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. law of diminishing returns
  • 82. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. this was about pinning 82
  • 83. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. typical block is 8KB 83
  • 84. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. NAME VALUE ------------------------------ ---------- session pga memory 2127112 session pga memory max 2155912 SQL> declare 2 cursor c_tool_list is 3 select descr 4 from hardware; 5 6 type t_descr_list is table of c_tool_list%rowtype; 7 l_descr_list t_descr_list; 8 9 begin 10 open c_tool_list; 11 loop 12 fetch c_tool_list 13 bulk collect 14 into l_descr_list limit 500; 15 exit when c_tool_list%notfound; 16 end loop; 17 close c_tool_list; 18 end; 19 / PL/SQL procedure successfully completed. Elapsed: 00:00:00.10
  • 85. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. important ! 85
  • 86. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> declare 2 cursor c_tool_list is 3 select descr 4 from hardware; 5 6 type t_descr_list is table of c_tool_list%rowtype; 7 l_descr_list t_descr_list; 8 9 begin 10 open c_tool_list; 11 loop 12 fetch c_tool_list 13 bulk collect 14 into l_descr_list limit 500; 1) array is replaced 15 exit when c_tool_list%notfound; 16 end loop; 17 close c_tool_list; 18 end; 19 / 2) < 500 = "not found" [processing here!] for i in 1 .. l_descr_list.count
  • 87. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. even easier ... 87
  • 88. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. implicit cursor 88 SQL> begin 2 for i in ( 3 select descr 4 from hardware 5 where aisle = 1 6 and item between 1 and 500 ) 7 loop 8 [processing] 9 end loop; 10 end; bulk SQL> begin 2 for i in ( 3 select descr 4 from hardware 5 where aisle = 1 6 and item between 1 and 500 ) 7 loop 8 [processing] 9 end loop; 10 end;
  • 89. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. guidelines 89
  • 90. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 1) single row no change
  • 91. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 91 SQL> declare 2 l_descr hardware.descr%type; 3 begin 4 select descr 5 into l_descr 6 from hardware 7 where aisle = 1 -- single 8 and item = 1; -- row 9 end;
  • 92. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 2) finite and "reasonable"
  • 93. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 93 SQL> declare 2 type t_descr_list is 3 table of hardware.descr%type; 4 l_descr_list t_descr_list; 5 begin 6 select descr 7 bulk collect 8 into l_descr_list 9 from hardware 10 where aisle = 1 11 and item between 1 and 100; 12 end;
  • 94. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. note: subtle differences 94
  • 95. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> declare 2 l_descr hardware.descr%type; 3 begin 4 select descr 5 into l_descr 6 from hardware 7 where aisle = 0 8 and item = 0; 9 end; 10 / declare * ERROR at line 1: ORA-01403: no data found ORA-06512: at line 4 SQL> declare 2 l_descr hardware.descr%type; 3 begin 4 select descr 5 into l_descr 6 from hardware 7 where aisle = 0 8 and item = 0; 9 dbms_output.put_line('YES!'); 10 exception 11 when no_data_found then 12 dbms_output.put_line('NO!'); 13 end; 14 / NO!
  • 96. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> declare 2 type t_descr_list is table of hardware.descr%type; 3 l_descr_list t_descr_list; 4 begin 5 select descr 6 bulk collect 7 into l_descr_list 8 from hardware 9 where aisle = 0 10 and item = 0; 11 dbms_output.put_line('YES!'); 12 exception 13 when no_data_found then 14 dbms_output.put_line('NO!'); 15 end; 16 / YES! no exception if l_descr_list.count = 0 then raise no_data_found; end if;
  • 97. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 3) unknown number of rows 97
  • 98. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 98 SQL> begin 2 for i in ( 3 select descr 4 from hardware 5 where aisle = 1 6 and item between 1 and 500 ) 7 loop 8 [processing] 9 end loop; 10 end;
  • 99. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. special case #1 99
  • 100. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 100 SQL> begin 2 for i in ( 3 select descr 4 from hardware 5 where aisle = 1 6 and item between 1 and 500 ) 7 loop 8 ... ... exit [early] when [some condition]; ... .. 19 end loop; 20 end;
  • 101. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. special case #2 101
  • 102. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. dont forget this bit
  • 103. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. reduce network roundtrips 103 larger array sizes
  • 104. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. sidebar: SQL as well 104
  • 105. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. a little known feature
  • 106. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL Net de-duplicate
  • 107. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> set autotrace traceonly stat SQL> set arraysize 100 SQL> select aisle, item, descr 2 from hardware 3 where ...; 89405 rows selected. Statistics --------------------------------------------- 4 recursive calls 0 db block gets 2452 consistent gets 0 physical reads 0 redo size 1198478 bytes sent via SQL*Net to client 107
  • 108. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> select aisle, item, descr 2 from hardware 3 where ... 4 order by 1,2; 89405 rows selected. Statistics -------------------------------------------- 14 recursive calls 0 db block gets 1507 consistent gets 0 physical reads 0 redo size 618820 bytes sent via SQL*Net to client
  • 109. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. focus on blocks 109
  • 110. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. focus on roundtrips 110
  • 111. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Part 2 writing data 111
  • 112. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. the same rules apply 112
  • 113. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. conventional DML in PLSQL 113
  • 114. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 114 SQL> declare 2 l_row hardware%rowtype; 3 begin 4 for i in 1 .. 100 loop 5 l_row.aisle := 1; 6 l_row.item := i; 7 insert into hardware values 8 ( l_row.aisle, l_row.item, l_row.descr) ; 9 end loop; 10 end; 11 / PL/SQL procedure successfully completed.
  • 115. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. or even nicer (PLSQL only) 115
  • 116. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 116 SQL> declare 2 l_row hardware%rowtype; 3 begin 4 for i in 1 .. 100 loop 5 l_row.aisle := 1; 6 l_row.item := i; 7 insert into hardware values l_row; 8 end loop; 9 end; 10 / PL/SQL procedure successfully completed.
  • 117. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. DML bulk = "bulk bind / FORALL" 117
  • 118. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 118 SQL> declare 2 type t_row_list is table of hardware%rowtype; 3 l_row t_row_list := t_row_list(); 4 begin 5 for i in 1 .. 100 loop 6 l_row.extend; 7 l_row(i).aisle := 1; 8 l_row(i).item := i; 9 end loop; 10 11 forall i in 1 .. 100 12 insert into hardware values l_row(i); 13 end; 14 / PL/SQL procedure successfully completed.
  • 119. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. "Is it worth the extra code?" bulk2.sql
  • 120. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. it's better than that bulk3.sql
  • 121. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. but ...
  • 122. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. ... the same rules apply
  • 123. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. all the data is somewhere PGA memory
  • 124. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. law of diminishing returns bulk4.sql
  • 125. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. no auto option :-(
  • 126. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 100-1000 typically fine
  • 127. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. one special case
  • 128. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> insert /*+ APPEND_VALUES */ 2 into HARDWARE ( item ) values (1); 1 row created. SQL> select item from HARDWARE; select item from HARDWARE * ERROR at line 1: ORA-12838: cannot read/modify an object after modifying it in parallel SQL> commit; Commit complete. SQL> select item from HARDWARE; ITEM ---------- 1
  • 129. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. direct load
  • 130. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. high speed, massive data loads bulk7.sql
  • 131. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. challenges with multi-row DML
  • 132. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> alter table hardware 2 add constraint 3 hardware_chk check ( item > 0 ); SQL> begin 2 insert into hardware ( item ) values (1); 3 insert into hardware ( item ) values (-1); 4 insert into hardware ( item ) values (2); 5 insert into hardware ( item ) values (3); 6 insert into hardware ( item ) values (4); 7 insert into hardware ( item ) values (-2); 8 end; 9 / ERROR at line 1: ORA-02290: check constraint (MCDONAC.HARDWARE_CHK) violated ORA-06512: at line 3 SQL> select * from hardware; no rows selected
  • 133. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> declare 2 type t_list is table of hardware.item%type; 3 l_rows t_list := t_list(1,-1,2,3,4,-2); 4 begin 5 forall i in 1 .. l_rows.count 6 insert into hardware ( item ) values (l_rows(i)); 7 end; 8 / declare * ERROR at line 1: ORA-02290: check constraint (MCDONAC.HARDWARE_CHK) violated ORA-06512: at line 5
  • 134. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. issue #1: which row cause the problem
  • 135. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. issue #2: none of the rows were stored
  • 136. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SAVE EXCEPTIONS clause bulk5.sql
  • 137. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. also consider error logging bulk6.sql
  • 138. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. issue #3: sparseness
  • 139. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> declare 2 type t_num_list is table of hardware.item%type index by pls_integer; 3 4 val t_num_list; 5 begin 6 7 val(10) := 10; 8 val(11) := 20; 9 val(12) := 20; 10 11 forall i in 1 .. val.count 12 insert into hardware ( item ) values (val(i)); 13 14 end; 15 / declare * ERROR at line 1: ORA-22160: element at index [1] does not exist ORA-06512: at line 11
  • 140. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> declare 2 type t_num_list is table of hardware.item%type index by pls_integer; 3 4 val t_num_list; 5 begin 6 7 val(10) := 10; 8 val(11) := 20; 9 val(12) := 20; 10 11 forall i in val.first .. val.last 12 insert into hardware ( item ) values (val(i)); 13 14 end; 15 / PL/SQL procedure successfully completed.
  • 141. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. but ... contiguous is assumed 141
  • 142. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> declare 2 type t_num_list is table of hardware.item%type index by pls_integer; 3 4 val t_num_list; 5 begin 6 7 val(10) := 10; 8 -- val(11) := 20; 9 val(12) := 20; 10 11 forall i in val.first .. val.last 12 insert into hardware ( item ) values (val(i)); 13 14 end; 15 / declare * ERROR at line 1: ORA-22160: element at index [11] does not exist ORA-06512: at line 11
  • 143. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. INDICES OF clause 143
  • 144. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> declare 2 type t_num_list is table of hardware.item%type index by pls_integer; 3 4 val t_num_list; 5 begin 6 7 val(10) := 10; 8 -- val(11) := 20; 9 val(12) := 20; 10 11 forall i in indices of val 12 insert into hardware ( item ) values (val(i)); 13 14 end; 15 / PL/SQL procedure successfully completed.
  • 145. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. homework :-) 145
  • 146. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. VALUES OF clause 146
  • 147. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. "How to get array benefits with SQL?"
  • 148. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL does this automatically...
  • 149. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. full table scans index range scans prefetch
  • 150. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. use SQL in preference to PLSQL where possible 150 for another day
  • 151. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. wrap up 151
  • 152. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. “relational” not “rowlational”
  • 153. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. process data in sets not rows
  • 154. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. use bulk collect / bulk bind where appropriate
  • 155. Enjoy the rest of the conference! https://linktr.ee/connor