SlideShare a Scribd company logo
1 of 229
Download to read offline
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
bienvenido
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Lo siento, no hablo español :-(
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
But I will do my best to help
Pero haré todo lo posible para ayudar
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Connor McDonald
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
6
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
7
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
8
Me
connor-mcdonald.com
https://linktr.ee/connor
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
10https://asktom.oracle.com
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
https://asktom.oracle.com/officehours
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
11
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
12
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
no matter how many layers ...
13
no importa cuántas capas
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
somewhere you are doing ...
14
XXXalgun lado tú lo estás haciendo
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
... data access with SQL
15
acceso a datos con SQL
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL is like any language
13
SQL es como ninguna idioma
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
compile it
14
compilarlo
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
compile it
14
on the fly
sobre la marcha
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
run it
15
ejecutarlo
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
get | store results
16
obtener | almacenar resultados
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
for successful applications...
17
para aplicaciones exitosas
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
compile it ... fast
18
rápido
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
run it ... fast
19
rápido
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
get | store results ... fast
20
rápido
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
that is all!
21
¡Eso es!
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
what everyone talks about
22
de lo que todos hablan
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
compile
execute
store/fetch results
23
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
this session
24
esta sesión
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
compile
execute
store/fetch results
25
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
before we begin ...
antes de que comencemos
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | connor_mc_dconnor mcdonald.com
controversy
31
controversia
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
here is the problem...
32
aqui esta el problema
33
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
a small digression
una pequeña digresión
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
a little bit of history on servers ...
un poco de historia en los servidores
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
(not too) long ago
no hace mucho
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
FSB = "front side bus"
38
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
any access to ... anything
cualquier acceso a ... cualquier cosa
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
CPU capped
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
hypertransport
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
memory access direct from CPU
44
acceso a memoria directo desde la CPU
~2007
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
"why do I care?"
"¿Porqué me importa?"
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
you can't blame the server (anymore)
48
ya no puedes culpar al servidor
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
if you can't get that performance ...
si no puedes obtener ese rendimiento
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
... it is our fault
está nuestro culpa
52
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
good code
buen código
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
so what's holding us back ?
¿qué nos está frenando?
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
It all comes down to...
Todo se reduce a
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
too much work or ...
demasiado trabajo
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
... not being able to do work
58
no poder hacer el trabajo
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
PART #1
56
compiling SQL
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
... how to avoid work when processing SQL
cómo evitar el trabajo excesivo al procesar SQL
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
terminology
61
cursors
cursors
declare
cursor C(p number) is
select * from DEPT
where DEPTNO = p;
begin
for rec in C loop
…
end loop;
end;
select *
from EMPLOYEE
where EMPNO > 1234;
delete from MY_TABLE;
drop table MY_TABLE;
begin
MY_PROCEDURE(1,2,3);
end;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
all of them !
todos ellos !
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
3 phases
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
open
process
close
give me some memory
do some stuff using that memory,
maybe access other memory
here's your memory back
66
Dame un poco de memoria
usa la memoria
devolver la memoria
memory access = controlled access
acceso a memoria = acceso controlado
a quick primer on (database) memory
una cartilla rápida en memoria
66
metaphor
67
71
limited resource
lots of people want it
concurrent access causes problems
it's a complex system
recurso limitado
mucha gente lo quiere
el acceso concurrente causa problemas
es un systema complejo
73
same with memory
lo mismo con la memoria
SGA
SGA
protected by
SGA
protected by
1) get latch
SGA
protected by
1) get latch
SGA
protected by
2) access memory
SGA
protected by
2) access memory
SGA
protected by
3) release latch
SGA
protected by
3) release latch
latch contention
SGA
protected by
someone must wait ...
alguien debe esperar
active wait
activo espere
spinning
89
hilado
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 ?
90
latch contention....
hurts CPU...
94
duele la CPU
hurts concurrency
duele la concurrencia
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
YOU
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
GET
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
NOTHING
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
DONEno logras nada
"When are we talking about SQL?"
"¿Cuándo estamos hablando de SQL?
to run a SQL statement
para ejecutar una declaración SQ
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
107
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
SQL> select *
2 frmo emp;
frmo emp
*
ERROR at line 2:
ORA-00923: FROM keyword not found where expected
108
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
SQL> select empnoo
2 from emp;
select empnoo
*
ERROR at line 1:
ORA-00904: invalid column name
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
PLAN
-------------------------------------
SELECT STATEMENT
TABLE ACCESS BY INDEX ROWID EMP
INDEX RANGE SCAN EMP_PK
EMP_PK EMP
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
112
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
lots of preliminary steps
muchos pasos preliminares
parsing
103
"compile"
lots of memory access
116
mucha memoria de acceso
lots of latching !
117
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
impossible to avoid ?
imposible de evitar?
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
library cache
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
previously executed statements
120
declaraciones ejecutadas previamente
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
parse statement select * from emp where empno = 123
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
parse statement
already in library cache ?
select * from emp where empno = 123
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
parse statement
already in library cache ?
select * from emp where empno = 123
syntactically, semantics OK
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
parse statement
already in library cache ?
reuse optimizer info
select * from emp where empno = 123
syntactically, semantics OK
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
parse statement
already in library cache ?
reuse optimizer info
reuse row source info
select * from emp where empno = 123
syntactically, semantics OK
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
select surname, firstname from emp where empno = 123
select * from dept where deptno = 4567
select * from customer where locality = 17
select prno from property where reference = 'X123G'
select * from dept where deptno = 23
select surname, firstname from emp where empno = 123
select * from customer where locality = 256
select * from organisation where officer = 'OFF876'
select surname, firstname from emp where empno = 7632
select * from dept where deptno = 4567
select offender from crimes where crno = 247462
Two full parses avoided
library
cache
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
select surname, firstname from emp where empno = 123
select * from dept where dname = 'SALES'
probability of reuse low ?
probabilidad de reutilización baja?
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
some queries are “nearly the same”
128
select surname, firstname from emp where empno = 123
select surname, firstname from emp where empno = 456
algunas consultas son "casi iguales"
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
binding
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
binding
parse this...
select surname, firstname from emp where empno = ?
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
binding
parse this...
now run it with ? = 123
now run it with ? = 456
select surname, firstname from emp where empno = ?
select surname, firstname from emp where empno = ?
select * from dept where deptno = ?
select * from customer where locality = ?
select prno from property where reference = ?
select * from dept where deptno = ?
select surname, firstname from emp where empno = ?
select * from customer where locality = ?
select * from organisation where officer = ?
select surname, firstname from emp where empno = ?
select * from dept where deptno = ?
select offender from crimes where crno = ?
Five full parses avoided
library
cache
demo
demo
ParseDemo
ParseDemoBind
"performance still looks ok"
"el rendimiento todavía se ve bien"
let us use real queries
hagámoslo real
let's make it real
ParseDemo2 nn
ParseDemo2Bind nn
much more serious
mucho Más grave
building SQL by concatenation
construir SQL por concatenación
you'll get hacked
select ename
from emp
where empno = 6543
select ename
from emp
where empno = 6543
select ename
from emp
where empno = 6543
and 1=0
union all
select table_name
from all_tables
where table_name like '%SECURITY%'
select ename
from emp
where empno = 6543
select ename
from emp
where empno = 6543
and 1=0
union all
select table_name
from all_tables
where table_name like '%SECURITY%'
select ename
from emp
where empno = 6543
and 1=0
union all
select username
from app_security
where ...
144
you'll get hacked ...
... really easily!
muy fácil!
#1 hacking app .....
#1 hacking app ..... Google
it takes 5 minutes to hack you
se necesita 5 minutos
for fast, secure SQL ...
para rápido seguro SQL
... always bind user input
siempre vincula la entrada del usuario
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
while we are talking about binding
mientras hablamos de encuadernación
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
parse statement
already in library cache ?
reuse optimizer info
reuse row source info
select * from emp where empno = 123
syntactically, semantics OK
Yes!
Yes!
???
???
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
still some parsing to do
156
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
Hard
Parse
Soft
Parse
foundnot found
in lib cache
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
scott@mydb> select *
2 from EMP
3 where EMPNO = :b1
mike@mydb> select *
2 from EMP
3 where EMPNO = :b1
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
scott@mydb> select *
2 from EMP
3 where EMPNO = :b1
anna@mydb> select *
2 from EMP
3 where EMPNO = :b1
SQL> desc anna.emp
Name Null? Type
----------------- -------- ------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
(even soft) parsing =
memory access =
latching
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
can we do better ?
podemos hacerlo mejor?
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
recall
recuerda
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
open
process
close
give me some memory
do some stuff using that memory,
maybe access other memory
here's your memory back
163
Dame un poco de memoria
usa la memoria
devolver la memoria
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
your SQL is always shareable
library cache
select *
from emp
tu SQL siempre se puede compartir
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
your cursor points to it
library cache
select *
from emp
cursor
165
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
close cursor = lose pointer
library cache
select *
from emp
cursor cercano = perder puntero
cursor
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
next time we parse
soft parse
la próxima vez
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
impossible to avoid ?
168
imposible de evitar?
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
what if we don't close the cursor
Y si nos no lo hagas cierra el cursor
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
library cache
select *
from emp
cursor 1
select *
from dept
cursor 2
select *
from emp
where ...
cursor 3
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
library cache
select *
from emp
cursor 1
select *
from dept
cursor 2
select *
from emp
where ...
cursor 3
pstmt_all_emp =
con.prepareStatement("select * from emp");
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
emplist(String[] args) {
if "first time" {
else
"reset the pointer, re-execute"
}
library cache
select *
from emp
cursor 1
select *
from dept
cursor 2
select *
from emp
where ...
cursor 3
pstmt_all_emp =
con.prepareStatement("select * from emp");
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
don’t close the cursor
no cierres el cursor
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
hang on to the memory
mantener la memoria
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
remember what cursors we’ve used
recuerda qué cursores hemos usado
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
reuse whenever possible
reutilizar siempre que sea posible
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
don’t exhaust memory
no agotar la memoria
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
don’t allow invalid cursor reuse
no permitir la reutilización inválida del cursor
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
sounds complicated ...
Suena complicado
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
a free solution exists
gratis la solución
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
plsql
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
create procedure MY_PROC is
begin
select empno, ename, ...
into …
from emp
where empno = my_plsql_variable
...
end;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
static SQL in stored PLSQL
automatically uses bind variables
hold’s cursors open
(even if you close)
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
better cursor caching
mejor almacenamiento en caché del cursor
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
procedure MY_PROC is
begin
select *
into …
from dept
where …
end;
select * from dept …
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
procedure MY_PROC is
cursor c_emp is
select * from emp;
begin
open c_emp;
fetch c_emp
into …;
close c_emp;
end;
select * from emp
procedure MY_PROC is
begin
select *
into …
from dept
where …
end;
select * from dept …
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
plsql in the database
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
171
PART #2
get | store results
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
172
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
start with reading data
173
Empezar con leyendo datos
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
querying data
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
data is stored in blocks | pages
los datos se almacenan en bloques | paginas
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
to read data, you read blocks...
para leer datos, lees bloques
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> select *
2 from EMP
3 where ...
/u01/my_data1.dat
memory
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
but (database) memory access is complex
195
pero el acceso a la memoria es complejo
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
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 /
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
we have to latch !
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
• 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"
198
Obtener el pestillo
Buscar en la lista de bloques en la memoria
Leer bloquear
Extraer fila de interés
Liberar el pestillo
Devolver la fila al cliente
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
lots of rows
muchas filas
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
lots of latching
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
typical program
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
rs = stmt.executeQuery("...");
while(rs.next()) {
v1 = rs.getInt(1);
v2 = rs.getString(2);
...
}
202
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
rs = stmt.executeQuery("...");
while(rs.next()) {
v1 = rs.getInt(1);
v2 = rs.getString(2);
...
}
• 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
203
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
a better strategy.... “pinning”
una mejor estrategia
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
"fetch a row"
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
"fetch a row"
“and .. I may need
many rows from this
block”
Puedo necesitar muchos
filas de esto bloquear"
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
"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 3 back to client
…
•Give row n to client
•Get latch
•Walk along list
•Remove my pin on the block
•Release latch
“and .. I may need
many rows from this
block”
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
how do you say ?
“I may want many rows”
Cómo se dice ?
"Puedo querer muchas filas"
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
responsibility of the client
responsabilidad del cliente
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
190
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
190
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
190
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
190
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
190
FetchDemo nn
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
focus on blocks
191
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
focus on roundtrips
192
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
nothing in life is free !
192
nada en la vida es gratis
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
all that data goes somewhere
220
todos esos datos van algun lado
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> declare
. . .
9 begin
10 open c;
11 loop
12 fetch c
13 into r;
14 exit when c%notfound;
. . .
19 /
Elapsed: 00:01:11.72
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> declare
. . .
9 begin
10 open c;
11
12 fetch c
13 bulk collect
14 into r;
15
. . .
19 /
Elapsed: 00:00:08.93
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 501534672
session pga memory max 501534672
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
500m of memory !
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
pin rows on a block (8k)
225
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> declare
. . .
9 begin
10 open c;
11 loop
12 fetch c
13 bulk collect
14 into r limit 100;
15 exit when c%notfound;
. . .
19 /
Elapsed: 00:00:08.17
NAME VALUE
------------------------------ ----------
session pga memory 625912
session pga memory max 625912
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
SQL> declare
. . .
9 begin
10 for i in c loop
12 ...
16 end loop;
17 end;
18 /
Elapsed: 00:00:08.21
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
PART #2(a)
storing data
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
the same rules apply
205
se aplican las mismas reglas
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
think blocks not rows
206
when appropriate
pensar bloques no filas
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
demo
208
InsertDemo3
InsertDemo4 nn
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
summary
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
avoid parsing costs
for high frequency SQL
evitar costos de análisis
para SQL de alta frecuencia
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
use binding and don't get hacked !
¡usa el enlace y no te hackeen!
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
PLSQL in the database is golden
PLSQL en la base de datos es dorado
Thank you!
connor-mcdonald.com
https://linktr.ee/connor
Gracias!

More Related Content

What's hot

What's hot (15)

APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101
 
Latin America tour 2019 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - Flashback
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19c
 
OpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersOpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer Disasters
 
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 - 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
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAs
 
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
 
Perth APAC Groundbreakers tour - SQL Techniques
Perth APAC Groundbreakers tour - SQL TechniquesPerth APAC Groundbreakers tour - SQL Techniques
Perth APAC Groundbreakers tour - SQL Techniques
 
APEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLAPEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQL
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
 
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
 
Jfokus 2017 Oracle Dev Cloud and Containers
Jfokus 2017 Oracle Dev Cloud and ContainersJfokus 2017 Oracle Dev Cloud and Containers
Jfokus 2017 Oracle Dev Cloud and Containers
 
GraalVM Native Images by Oleg Selajev @shelajev
GraalVM Native Images by Oleg Selajev @shelajevGraalVM Native Images by Oleg Selajev @shelajev
GraalVM Native Images by Oleg Selajev @shelajev
 
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
 

Similar to Latin America Tour 2019 - slow data and sql processing

Similar to Latin America Tour 2019 - slow data and sql processing (20)

Perth APAC Groundbreakers tour - The Autonomous Database
Perth APAC Groundbreakers tour - The Autonomous DatabasePerth APAC Groundbreakers tour - The Autonomous Database
Perth APAC Groundbreakers tour - The Autonomous Database
 
Melbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and TipsMelbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and Tips
 
Perth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c featuresPerth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c features
 
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
 
MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...
MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...
MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...
 
ILOUG 2019 - Autonomous, what does it mean for DBAs
ILOUG 2019 - Autonomous, what does it mean for DBAsILOUG 2019 - Autonomous, what does it mean for DBAs
ILOUG 2019 - Autonomous, what does it mean for DBAs
 
AUSOUG Analytics Update - Nov 14 2018
AUSOUG Analytics Update - Nov 14 2018AUSOUG Analytics Update - Nov 14 2018
AUSOUG Analytics Update - Nov 14 2018
 
Overview of Oracle Database 18c Express Edition (XE)
Overview of Oracle Database 18c Express Edition (XE)Overview of Oracle Database 18c Express Edition (XE)
Overview of Oracle Database 18c Express Edition (XE)
 
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
 
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
 
The Oracle Autonomous Database
The Oracle Autonomous DatabaseThe Oracle Autonomous Database
The Oracle Autonomous Database
 
GraalVM: Run Programs Faster Everywhere
GraalVM: Run Programs Faster EverywhereGraalVM: Run Programs Faster Everywhere
GraalVM: Run Programs Faster Everywhere
 
“Quantum” Performance Effects: beyond the Core
“Quantum” Performance Effects: beyond the Core“Quantum” Performance Effects: beyond the Core
“Quantum” Performance Effects: beyond the Core
 
Developers vs DBA's - APACOUC webinar 2017
Developers vs DBA's - APACOUC webinar 2017Developers vs DBA's - APACOUC webinar 2017
Developers vs DBA's - APACOUC webinar 2017
 
FOSDEM'18: MySQL InnoDB Cluster - MySQL HA Made Easy!
FOSDEM'18: MySQL InnoDB Cluster - MySQL HA Made Easy!FOSDEM'18: MySQL InnoDB Cluster - MySQL HA Made Easy!
FOSDEM'18: MySQL InnoDB Cluster - MySQL HA Made Easy!
 
Using Machine Learning to Debug complex Oracle RAC Issues
Using Machine Learning  to Debug complex Oracle RAC IssuesUsing Machine Learning  to Debug complex Oracle RAC Issues
Using Machine Learning to Debug complex Oracle RAC Issues
 
ILOUG 2019 - 18c/19c features
ILOUG 2019 - 18c/19c featuresILOUG 2019 - 18c/19c features
ILOUG 2019 - 18c/19c features
 
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Data
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: DataAMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Data
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Data
 
AMIS Oracle OpenWorld & CodeOne Review - Pillar 1 - Data (5 november 2018)
AMIS Oracle OpenWorld & CodeOne Review - Pillar 1 - Data (5 november 2018)AMIS Oracle OpenWorld & CodeOne Review - Pillar 1 - Data (5 november 2018)
AMIS Oracle OpenWorld & CodeOne Review - Pillar 1 - Data (5 november 2018)
 

More from Connor McDonald

More from Connor McDonald (19)

Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
 
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 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL Features
 

Recently uploaded

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Recently uploaded (20)

Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
THE BEST IPTV in GERMANY for 2024: IPTVreel
THE BEST IPTV in  GERMANY for 2024: IPTVreelTHE BEST IPTV in  GERMANY for 2024: IPTVreel
THE BEST IPTV in GERMANY for 2024: IPTVreel
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 

Latin America Tour 2019 - slow data and sql processing

  • 1. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. bienvenido
  • 2. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Lo siento, no hablo español :-(
  • 3. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. But I will do my best to help Pero haré todo lo posible para ayudar
  • 4. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Connor McDonald
  • 5. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 6
  • 6. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 7
  • 7. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 8
  • 9. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 10https://asktom.oracle.com
  • 10. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. https://asktom.oracle.com/officehours
  • 11. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 11
  • 12. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 12
  • 13. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. no matter how many layers ... 13 no importa cuántas capas
  • 14. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. somewhere you are doing ... 14 XXXalgun lado tú lo estás haciendo
  • 15. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. ... data access with SQL 15 acceso a datos con SQL
  • 16. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL is like any language 13 SQL es como ninguna idioma
  • 17. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. compile it 14 compilarlo
  • 18. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. compile it 14 on the fly sobre la marcha
  • 19. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. run it 15 ejecutarlo
  • 20. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. get | store results 16 obtener | almacenar resultados
  • 21. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. for successful applications... 17 para aplicaciones exitosas
  • 22. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. compile it ... fast 18 rápido
  • 23. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. run it ... fast 19 rápido
  • 24. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. get | store results ... fast 20 rápido
  • 25. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. that is all! 21 ¡Eso es!
  • 26. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. what everyone talks about 22 de lo que todos hablan
  • 27. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. compile execute store/fetch results 23
  • 28. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. this session 24 esta sesión
  • 29. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. compile execute store/fetch results 25
  • 30. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. before we begin ... antes de que comencemos
  • 31. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | connor_mc_dconnor mcdonald.com controversy 31 controversia
  • 32. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. here is the problem... 32 aqui esta el problema
  • 33. 33
  • 34. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. a small digression una pequeña digresión
  • 35. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. a little bit of history on servers ... un poco de historia en los servidores
  • 36. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. (not too) long ago no hace mucho
  • 37. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
  • 38. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. FSB = "front side bus" 38
  • 39. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. any access to ... anything cualquier acceso a ... cualquier cosa
  • 40. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. CPU capped
  • 41.
  • 42. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. hypertransport
  • 43.
  • 44. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. memory access direct from CPU 44 acceso a memoria directo desde la CPU
  • 45.
  • 46. ~2007
  • 47. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. "why do I care?" "¿Porqué me importa?"
  • 48. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. you can't blame the server (anymore) 48 ya no puedes culpar al servidor
  • 49. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. if you can't get that performance ... si no puedes obtener ese rendimiento
  • 50. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. ... it is our fault está nuestro culpa
  • 51.
  • 52. 52
  • 53.
  • 54. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. good code buen código
  • 55. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. so what's holding us back ? ¿qué nos está frenando?
  • 56. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. It all comes down to... Todo se reduce a
  • 57. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. too much work or ... demasiado trabajo
  • 58. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. ... not being able to do work 58 no poder hacer el trabajo
  • 59. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. PART #1 56 compiling SQL
  • 60. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. ... how to avoid work when processing SQL cómo evitar el trabajo excesivo al procesar SQL
  • 61. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. terminology 61
  • 63. cursors declare cursor C(p number) is select * from DEPT where DEPTNO = p; begin for rec in C loop … end loop; end; select * from EMPLOYEE where EMPNO > 1234; delete from MY_TABLE; drop table MY_TABLE; begin MY_PROCEDURE(1,2,3); end;
  • 64. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. all of them ! todos ellos !
  • 65. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 3 phases
  • 66. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. open process close give me some memory do some stuff using that memory, maybe access other memory here's your memory back 66 Dame un poco de memoria usa la memoria devolver la memoria
  • 67. memory access = controlled access acceso a memoria = acceso controlado
  • 68. a quick primer on (database) memory una cartilla rápida en memoria
  • 69.
  • 71. 67
  • 72.
  • 73.
  • 74.
  • 75. 71 limited resource lots of people want it concurrent access causes problems it's a complex system recurso limitado mucha gente lo quiere el acceso concurrente causa problemas es un systema complejo
  • 76.
  • 77. 73 same with memory lo mismo con la memoria
  • 78. SGA
  • 87. SGA protected by someone must wait ... alguien debe esperar
  • 90. 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 ? 90
  • 91.
  • 92.
  • 96. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. YOU
  • 97. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. GET
  • 98. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. NOTHING
  • 99. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. DONEno logras nada
  • 100. "When are we talking about SQL?" "¿Cuándo estamos hablando de SQL?
  • 101. to run a SQL statement para ejecutar una declaración SQ
  • 103. Syntax Validity Optimization Rowsourcing Execution (Fetch) SQL> select * 2 frmo emp; frmo emp * ERROR at line 2: ORA-00923: FROM keyword not found where expected 108
  • 104. Syntax Validity Optimization Rowsourcing Execution (Fetch) SQL> select empnoo 2 from emp; select empnoo * ERROR at line 1: ORA-00904: invalid column name
  • 109. lots of preliminary steps muchos pasos preliminares
  • 111. lots of memory access 116 mucha memoria de acceso
  • 113. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. impossible to avoid ? imposible de evitar?
  • 114. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. library cache
  • 115. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. previously executed statements 120 declaraciones ejecutadas previamente
  • 116. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. parse statement select * from emp where empno = 123
  • 117. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. parse statement already in library cache ? select * from emp where empno = 123
  • 118. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. parse statement already in library cache ? select * from emp where empno = 123 syntactically, semantics OK
  • 119. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. parse statement already in library cache ? reuse optimizer info select * from emp where empno = 123 syntactically, semantics OK
  • 120. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. parse statement already in library cache ? reuse optimizer info reuse row source info select * from emp where empno = 123 syntactically, semantics OK
  • 121. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. select surname, firstname from emp where empno = 123 select * from dept where deptno = 4567 select * from customer where locality = 17 select prno from property where reference = 'X123G' select * from dept where deptno = 23 select surname, firstname from emp where empno = 123 select * from customer where locality = 256 select * from organisation where officer = 'OFF876' select surname, firstname from emp where empno = 7632 select * from dept where deptno = 4567 select offender from crimes where crno = 247462 Two full parses avoided library cache
  • 122. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. select surname, firstname from emp where empno = 123 select * from dept where dname = 'SALES' probability of reuse low ? probabilidad de reutilización baja?
  • 123. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. some queries are “nearly the same” 128 select surname, firstname from emp where empno = 123 select surname, firstname from emp where empno = 456 algunas consultas son "casi iguales"
  • 124. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. binding
  • 125. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. binding parse this... select surname, firstname from emp where empno = ?
  • 126. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. binding parse this... now run it with ? = 123 now run it with ? = 456 select surname, firstname from emp where empno = ?
  • 127. select surname, firstname from emp where empno = ? select * from dept where deptno = ? select * from customer where locality = ? select prno from property where reference = ? select * from dept where deptno = ? select surname, firstname from emp where empno = ? select * from customer where locality = ? select * from organisation where officer = ? select surname, firstname from emp where empno = ? select * from dept where deptno = ? select offender from crimes where crno = ? Five full parses avoided library cache
  • 128. demo
  • 130. "performance still looks ok" "el rendimiento todavía se ve bien"
  • 131. let us use real queries hagámoslo real
  • 132. let's make it real ParseDemo2 nn ParseDemo2Bind nn
  • 133. much more serious mucho Más grave
  • 134. building SQL by concatenation construir SQL por concatenación
  • 137. select ename from emp where empno = 6543 select ename from emp where empno = 6543 and 1=0 union all select table_name from all_tables where table_name like '%SECURITY%'
  • 138. select ename from emp where empno = 6543 select ename from emp where empno = 6543 and 1=0 union all select table_name from all_tables where table_name like '%SECURITY%' select ename from emp where empno = 6543 and 1=0 union all select username from app_security where ...
  • 139. 144
  • 140. you'll get hacked ... ... really easily! muy fácil!
  • 141. #1 hacking app .....
  • 142. #1 hacking app ..... Google
  • 143.
  • 144.
  • 145. it takes 5 minutes to hack you se necesita 5 minutos
  • 146.
  • 147. for fast, secure SQL ... para rápido seguro SQL
  • 148. ... always bind user input siempre vincula la entrada del usuario
  • 149. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. while we are talking about binding mientras hablamos de encuadernación
  • 150. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. parse statement already in library cache ? reuse optimizer info reuse row source info select * from emp where empno = 123 syntactically, semantics OK Yes! Yes! ??? ???
  • 151. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. still some parsing to do 156
  • 152. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Syntax Validity Optimization Rowsourcing Execution (Fetch) Hard Parse Soft Parse foundnot found in lib cache
  • 153. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. scott@mydb> select * 2 from EMP 3 where EMPNO = :b1 mike@mydb> select * 2 from EMP 3 where EMPNO = :b1
  • 154. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. scott@mydb> select * 2 from EMP 3 where EMPNO = :b1 anna@mydb> select * 2 from EMP 3 where EMPNO = :b1 SQL> desc anna.emp Name Null? Type ----------------- -------- ------------ EMPNO NOT NULL NUMBER(4) ENAME VARCHAR2(10) JOB VARCHAR2(9)
  • 155. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. (even soft) parsing = memory access = latching
  • 156. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. can we do better ? podemos hacerlo mejor?
  • 157. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. recall recuerda
  • 158. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. open process close give me some memory do some stuff using that memory, maybe access other memory here's your memory back 163 Dame un poco de memoria usa la memoria devolver la memoria
  • 159. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. your SQL is always shareable library cache select * from emp tu SQL siempre se puede compartir
  • 160. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. your cursor points to it library cache select * from emp cursor 165
  • 161. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. close cursor = lose pointer library cache select * from emp cursor cercano = perder puntero cursor
  • 162. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. next time we parse soft parse la próxima vez
  • 163. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. impossible to avoid ? 168 imposible de evitar?
  • 164. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. what if we don't close the cursor Y si nos no lo hagas cierra el cursor
  • 165. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. library cache select * from emp cursor 1 select * from dept cursor 2 select * from emp where ... cursor 3
  • 166. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. library cache select * from emp cursor 1 select * from dept cursor 2 select * from emp where ... cursor 3 pstmt_all_emp = con.prepareStatement("select * from emp");
  • 167. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. emplist(String[] args) { if "first time" { else "reset the pointer, re-execute" } library cache select * from emp cursor 1 select * from dept cursor 2 select * from emp where ... cursor 3 pstmt_all_emp = con.prepareStatement("select * from emp");
  • 168. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. don’t close the cursor no cierres el cursor
  • 169. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. hang on to the memory mantener la memoria
  • 170. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. remember what cursors we’ve used recuerda qué cursores hemos usado
  • 171. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. reuse whenever possible reutilizar siempre que sea posible
  • 172. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. don’t exhaust memory no agotar la memoria
  • 173. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. don’t allow invalid cursor reuse no permitir la reutilización inválida del cursor
  • 174. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. sounds complicated ... Suena complicado
  • 175. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. a free solution exists gratis la solución
  • 176. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. plsql
  • 177. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. create procedure MY_PROC is begin select empno, ename, ... into … from emp where empno = my_plsql_variable ... end;
  • 178. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. static SQL in stored PLSQL automatically uses bind variables hold’s cursors open (even if you close)
  • 179. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. better cursor caching mejor almacenamiento en caché del cursor
  • 180. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. procedure MY_PROC is begin select * into … from dept where … end; select * from dept …
  • 181. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. procedure MY_PROC is cursor c_emp is select * from emp; begin open c_emp; fetch c_emp into …; close c_emp; end; select * from emp procedure MY_PROC is begin select * into … from dept where … end; select * from dept …
  • 182. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. plsql in the database
  • 183. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 171 PART #2 get | store results
  • 184. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 172
  • 185. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. start with reading data 173 Empezar con leyendo datos
  • 186. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. querying data
  • 187. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. data is stored in blocks | pages los datos se almacenan en bloques | paginas
  • 188. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. to read data, you read blocks... para leer datos, lees bloques
  • 189. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> select * 2 from EMP 3 where ... /u01/my_data1.dat memory
  • 190. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. but (database) memory access is complex 195 pero el acceso a la memoria es complejo
  • 191. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 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 /
  • 192. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. we have to latch !
  • 193. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. • 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" 198 Obtener el pestillo Buscar en la lista de bloques en la memoria Leer bloquear Extraer fila de interés Liberar el pestillo Devolver la fila al cliente
  • 194. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. lots of rows muchas filas
  • 195. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. lots of latching
  • 196. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. typical program
  • 197. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. rs = stmt.executeQuery("..."); while(rs.next()) { v1 = rs.getInt(1); v2 = rs.getString(2); ... } 202
  • 198. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. rs = stmt.executeQuery("..."); while(rs.next()) { v1 = rs.getInt(1); v2 = rs.getString(2); ... } • 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 203
  • 199. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. a better strategy.... “pinning” una mejor estrategia
  • 200. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. "fetch a row"
  • 201. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. "fetch a row" “and .. I may need many rows from this block” Puedo necesitar muchos filas de esto bloquear"
  • 202. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. "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 3 back to client … •Give row n to client •Get latch •Walk along list •Remove my pin on the block •Release latch “and .. I may need many rows from this block”
  • 203. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. how do you say ? “I may want many rows” Cómo se dice ? "Puedo querer muchas filas"
  • 204. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. responsibility of the client responsabilidad del cliente
  • 205. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 190
  • 206. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 190
  • 207. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 190
  • 208. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 190
  • 209. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 190 FetchDemo nn
  • 210. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. focus on blocks 191
  • 211. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. focus on roundtrips 192
  • 212. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. nothing in life is free ! 192 nada en la vida es gratis
  • 213. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. all that data goes somewhere 220 todos esos datos van algun lado
  • 214. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> declare . . . 9 begin 10 open c; 11 loop 12 fetch c 13 into r; 14 exit when c%notfound; . . . 19 / Elapsed: 00:01:11.72
  • 215. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> declare . . . 9 begin 10 open c; 11 12 fetch c 13 bulk collect 14 into r; 15 . . . 19 / Elapsed: 00:00:08.93
  • 216. 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 501534672 session pga memory max 501534672
  • 217. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 500m of memory !
  • 218. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. pin rows on a block (8k) 225
  • 219. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> declare . . . 9 begin 10 open c; 11 loop 12 fetch c 13 bulk collect 14 into r limit 100; 15 exit when c%notfound; . . . 19 / Elapsed: 00:00:08.17 NAME VALUE ------------------------------ ---------- session pga memory 625912 session pga memory max 625912
  • 220. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. SQL> declare . . . 9 begin 10 for i in c loop 12 ... 16 end loop; 17 end; 18 / Elapsed: 00:00:08.21
  • 221. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. PART #2(a) storing data
  • 222. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. the same rules apply 205 se aplican las mismas reglas
  • 223. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. think blocks not rows 206 when appropriate pensar bloques no filas
  • 224. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. demo 208 InsertDemo3 InsertDemo4 nn
  • 225. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. summary
  • 226. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. avoid parsing costs for high frequency SQL evitar costos de análisis para SQL de alta frecuencia
  • 227. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. use binding and don't get hacked ! ¡usa el enlace y no te hackeen!
  • 228. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. PLSQL in the database is golden PLSQL en la base de datos es dorado