SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Downloaden Sie, um offline zu lesen
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 1
Performance Tuning: Como escribir y correr
correctamente una sentencia SQL
By Ronald Vargas Quesada, Oracle ACE Director
Expertise Database Management & Performance
Technical PreSales Consultant, Netsoft de Centroamérica
Oracledbacr.blogspot.com
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 2
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Background
50% mistype a statement
&
9 out of 10 the incorrectly executed
Performance Tuning: How to write & run correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 3
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Performance Tuning: How to write & run correctly
Programar siempre y de la misma manera es eficiente !
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 4
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Continuo aprendizaje
Performance Tuning: How to write & run correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 5
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
There's a tradeoff between efficiency (fewer conditional
statements) and ease of comprehension.
Existe un equilibrio entre la eficiencia ( menos sentencias
condicionales ) y la facilidad de comprensión.
Declaración #1 absoluta
Performance Tuning: How to write & run correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 6
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
The real world is very complicated; the software we write is supposed to map
those complexities into applications. The result is that we often end up
needing to deal with convoluted logical expressions.
El mundo real es muy complicado; el software que escribimos supone un
mapeo de esas complejidades en las aplicaciones. El resultado es que a
menudo terminamos con la necesidad de lidiar con expresiones lógicas
complejas.
Performance Tuning: How to write & run correctly
Declaración #2 absoluta
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 7
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Following this best practice will make your code more readable and
expressive.
You avoid redundant code, always bad news in a program, since it increases
maintenance costs and the chance of introducing bugs into your code.
Aplicando buenas prácticas se puede lograr que su código sea más legible y
expresivo.
Evite el código redundante, este siempre es una mala noticia en un
programa, ya que aumenta los costos de mantenimiento y la posibilidad de
introducir errores en el código.
Declaración #3 absoluta
Performance Tuning: How to write & run correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 8
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
You need not take out "programmer's insurance": "Gee, I don't know if I need
to declare that or not, so I'd better declare it." Instead, you make certain you
understand how PL/SQL works and write appropriate code.
"Vaya, no sé si tengo que declararlo o no, así que será mejor que lo declare.“
En su lugar, asegúrese de que entiende cómo funciona el PL/SQL y escriba
el código apropiado.
Performance Tuning: How to write & run correctly
Declaración #4 absoluta
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 9
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Your code doesn't do any unnecessary work and so executes more efficiently.
TIP: You can, in general, expect the performance of built-in functions such as
SUBSTR to work more efficiently in SQL than in PL/SQL, so move the
processing to the SQL layer whenever possible.
“El código no hace ningún trabajo innecesario y así se ejecuta de manera
más eficiente.”
En general el desempeño de las funciones integradas tales como SUBSTR
trabajan más eficientemente en SQL que en PL/SQL.
Performance Tuning: How to write & run correctly
Declaración #5 absoluta
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 10
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Performance Tuning: How to write correctly
That´s it !
That´s it friends!
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 11
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
quick example #1
Performance Tuning: How to write correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 12
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
employees by salary
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 13
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
SQL> select employee_id, job_id, hire_date, salary
2 from employees
3 order by salary;
EMPLOYEE_ID JOB_ID HIRE_DATE SALARY
----------- ---------- --------- ----------
132 ST_CLERK 10-APR-07 2100
136 ST_CLERK 06-FEB-08 2200
128 ST_CLERK 08-MAR-08 2200
127 ST_CLERK 14-JAN-07 2400
135 ST_CLERK 12-DEC-07 2400
191 SH_CLERK 19-DEC-07 2500
119 PU_CLERK 10-AUG-07 2500
140 ST_CLERK 06-APR-06 2500
144 ST_CLERK 09-JUL-06 2500
182 SH_CLERK 21-JUN-07 2500
131 ST_CLERK 16-FEB-05 2500
Performance Tuning: How to write correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 14
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Who hired first ?
hiring sequence
Performance Tuning: How to write correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 15
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
1 select e.employee_id, e.first_name, e.job_id, e.hire_date, e.salary, x.sequence
2 from employees e,
3 (select e2.employee_id, count(*) sequence from employees e1, employees e2
4 where e1.hire_date <= e2.hire_date
5 group by e2.employee_id
6 ) x
7 where e.employee_id = x.employee_id
8* order by salary
SQL> /
EMPLOYEE_ID FIRST_NAME JOB_ID HIRE_DATE SALARY SEQUENCE
----------- -------------------- ---------- --------- ---------- ----------
132 TJ ST_CLERK 10-APR-07 2100 85
128 Steven ST_CLERK 08-MAR-08 2200 104
136 Hazel ST_CLERK 06-FEB-08 2200 102
135 Ki ST_CLERK 12-DEC-07 2400 95
127 James ST_CLERK 14-JAN-07 2400 78
144 Peter ST_CLERK 09-JUL-06 2500 71
Performance Tuning: How to write correctly
very
complicated !!
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 16
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Is very simple ?
Performance Tuning: How to write correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 17
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Much or little work ?
Performance Tuning: How to write correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 18
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------------
Plan hash value: 2074273239
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 107 | 5243 | 14 (36)| 00:00:01 |
| 1 | SORT ORDER BY | | 107 | 5243 | 14 (36)| 00:00:01 |
|* 2 | HASH JOIN | | 107 | 5243 | 13 (31)| 00:00:01 |
| 3 | TABLE ACCESS FULL | EMPLOYEES | 107 | 3424 | 3 (0)| 00:00:01 |
| 4 | VIEW | | 107 | 1819 | 9 (34)| 00:00:01 |
| 5 | HASH GROUP BY | | 107 | 2140 | 9 (34)| 00:00:01 |
| 6 | MERGE JOIN | | 5783 | 112K| 8 (25)| 00:00:01 |
| 7 | SORT JOIN | | 107 | 856 | 4 (25)| 00:00:01 |
| 8 | TABLE ACCESS FULL| EMPLOYEES | 107 | 856 | 3 (0)| 00:00:01 |
|* 9 | SORT JOIN | | 107 | 1284 | 4 (25)| 00:00:01 |
| 10 | TABLE ACCESS FULL| EMPLOYEES | 107 | 1284 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("E"."EMPLOYEE_ID"="X"."EMPLOYEE_ID")
9 - access("E1"."HIRE_DATE"<="E2"."HIRE_DATE")
filter("E1"."HIRE_DATE"<="E2"."HIRE_DATE") 24 rows selected.
Performance Tuning: How to write correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 19
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Make it Simple !!
Performance Tuning: How to write correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 20
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
SQL> select employee_id, first_name, job_id, hire_date, salary, rank() over (order by
hire_date) as hire_seq
2 from employees
3 order by salary;
EMPLOYEE_ID FIRST_NAME JOB_ID HIRE_DATE SALARY HIRE_SEQ
----------- -------------------- ---------- --------- ---------- ----------
132 TJ ST_CLERK 10-APR-07 2100 85
136 Hazel ST_CLERK 06-FEB-08 2200 102
128 Steven ST_CLERK 08-MAR-08 2200 104
127 James ST_CLERK 14-JAN-07 2400 78
135 Ki ST_CLERK 12-DEC-07 2400 95
131 James ST_CLERK 16-FEB-05 2500 28
140 Joshua ST_CLERK 06-APR-06 2500 65
144 Peter ST_CLERK 09-JUL-06 2500 71
Performance Tuning: How to write correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 21
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------
Plan hash value: 1701542182
---------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 107 | 3424 | 5 (40)| 00:00:01 |
| 1 | SORT ORDER BY | | 107 | 3424 | 5 (40)| 00:00:01 |
| 2 | WINDOW SORT | | 107 | 3424 | 5 (40)| 00:00:01 |
| 3 | TABLE ACCESS FULL| EMPLOYEES | 107 | 3424 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------------
10 rows selected.
Performance Tuning: How to write correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 22
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
When Should I Use an Index?
Performance Tuning: How to write correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 23
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
When Should I Use an Index?
Performance Tuning: How to write correctly
 No es un puntero
 Segmento con almacenamiento
en un tablespace
 Parámetros de concurrencia
 Mejoran el acceso a los datos
 Degrada gradualmente los
procesos de Update, Insert y
Delete de tuplas.
 No son libres de mantenimiento
 +20% entradas inválidas, el
motor omite el uso del índice.
 Requieren cada cierto tiempo
recrearse para balancear el árbol
y eliminar las entras inválidas
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 24
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Performance Tuning: How to write correctly
Optimización basada en RULE ( Regla ) 10gR2 o inferior
a a a a a b b b b
b b b b a a a a
c c c c c c
d d d
e ...
When Should I Use an Index?
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 25
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Optimización basada en COST (Costo ) 7.x o superior,
11g y superior sólo optimiza basado en COSTO
a
b
c
d
e
When Should I Use an Index?
Performance Tuning: How to write correctly
Un columna que es llave foránea
Siempre debe estar indexada.
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 26
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Driving Table, ( RBO Only )
Performance Tuning: How to write correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 27
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Parseo de instrucciones
Performance Tuning: How to write correctly
La fase de análisis sintáctico para declaraciones se puede disminuir mediante
el uso eficiente de alias. Si un alias no está presente, el motor debe resolver
qué tablas poseen las columnas especificadas. El siguiente es un ejemplo.
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 28
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
 Para la consulta A, todas las filas de TABLA2 serán
leídos por cada fila en la Tabla 1. El efecto será
1.000.000 filas leídas de artículos.
 En el caso de la consulta B, se leerá un máximo de 1
registro de la TABLA2 para cada fila en la TABLA1,
reduciendo así la carga de procesamiento de la
declaración
Si la mayoría de los criterios de filtrado se encuentran en la
subconsulta entonces la variación IN es más eficiente.
Si la mayoría de los criterios de filtrado están en la consulta
entonces la variación de EXISTS es más eficiente.
Se sugiere que usted debe tratar ambas variantes y ver cuál
funciona mejor.
Exists vs IN
Performance Tuning: How to write correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 29
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
SQL> host
[oracle@LAB1 ~]$ vi script1.sql
[oracle@LAB1 ~]$ more script1.sql
set timing on
begin
for i in 1 .. 100000
loop
execute immediate
'insert into t (x,y)
values ( ' || i || ', ''x'') ';
end loop;
end;
/
[oracle@LAB1 ~]$
Not using bind variable
Performance Tuning: How to write correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 30
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
[oracle@LAB1 ~]$ more script2.sql
set timing on
begin
for i in 1 .. 100000
loop
execute immediate
'insert into t (x,y)
values ( :i, ''x'')'
using i;
end loop;
end;
/
[oracle@LAB1 ~]$
Using Bind variable
Performance Tuning: How to write correctly
(*) Up to 1320% higher
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 31
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
PLSQL_CODE_TYPE specifies the compilation mode for
PL/SQL library units.
Syntax PLSQL_CODE_TYPE = { INTERPRETED | NATIVE }
Default INTERPRETED
Modifiable Alter session, Alter system
Basic No
INTERPRETED = interpreter engine / NATIVE = native machine code, without
incurring any interpreter overhead
PLSQL_CODE_TYPE
Performance Tuning: How to run correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 32
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
When the value of this parameter is changed, it has no effect on
PL/SQL library units that have already been compiled. The value of
this parameter is stored persistently with each library unit.
Performance Tuning: How to run correctly
PLSQL_CODE_TYPE
If a PL/SQL library unit is compiled native,
all subsequent automatic recompilations of that
library unit will use native compilation.
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 33
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Performance Tuning: How to run correctly
Environment
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 34
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Performance Tuning: How to run correctly
CREATE OR REPLACE FUNCTION testeo ( n positive ) return integer
is
begin
if ( n = 1) OR ( n = 2 ) then
return 1;
else
return testeo(n-1) + testeo(n-2);
end if;
end testeo;
/
Example
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 35
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Performance Tuning: How to run correctly
set serveroutput on
set timing on
--- anonymous block
declare
x number;
begin
x := testeo(40);
dbms_output.put_line(x);
end;
/
Example
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 36
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Performance Tuning: How to run correctly
[oracle@lab1 admin]$ sqlplus hr/hr@PDB1
SQL*Plus: Release 12.1.0.1.0 Production on Wed Apr 23 17:23:43 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Last Successful login time: Wed Jan 15 2014 12:14:36 -06:00
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit
Production
With the Partitioning, OLAP, Advanced Analytics and Real Application
Testing options
SQL>
Example
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 37
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Performance Tuning: How to run correctly
SQL> @p1.pl
Function created.
SQL> alter session set plsql_code_type = 'INTERPRETED';
Session altered.
SQL> alter function testeo compile;
Function altered.
Example
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 38
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Performance Tuning: How to run correctly
SQL> set linesize 200
SQL> @ver_parametro.pl
Example
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 39
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Performance Tuning: How to run correctly
SQL> @ej1.pl
102334155
PL/SQL procedure successfully completed.
Elapsed: 00:00:52.22
SQL> alter session set plsql_code_type = 'NATIVE';
Session altered.
SQL> alter function testeo compile;
Function altered.
Example
SQL> @ej1.pl
102334155
PL/SQL procedure successfully completed.
Elapsed: 00:00:27.73
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 40
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Performance Tuning: How to run correctly
SQL> @ej1.pl R/ 102334155
PL/SQL procedure successfully completed.
Elapsed: 00:00:56.43
SQL> alter session set plsql_code_type = 'NATIVE';
Session altered.
SQL> @ej1.pl R/ 102334155
PL/SQL procedure successfully completed.
Elapsed: 00:00:57.40
SQL> alter function testeo compile;
Function altered.
Example ( Do not forget: COMPILE )
SQL> @ej1.pl R/ 102334155
PL/SQL procedure successfully completed.
Elapsed: 00:00:29.28
SQL>
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 41
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Performance Tuning: How to run correctly
create or replace procedure insertar
as
begin
for i in 1 .. 100000
loop
execute immediate
'insert into t(x,y)
values (' || i ||',''x'')';
end loop;
end;
/
Example 2 ( Compiled=‘NATIVE’ )
SQL> execute insertar;
PL/SQL procedure successfully completed.
Elapsed: 00:01:12.61
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 42
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
Performance Tuning: How to run correctly
create or replace procedure insertarb
as
begin
for i in 1 .. 100000
loop
execute immediate
'insert into t(x,y)
values (:i,''x'')'
using i;
end loop;
end;
/
Example 2, ( Compiled =‘NATIVE’ )
SQL> execute insertarb;
PL/SQL procedure successfully completed.
Elapsed: 00:00:05.05
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 43
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
The Result Cache is a new memory structure in the SGA.
By adding the RESULT_CACHE clause to your function, Oracle will:
– Cache the values returned by the function, along with the input
values.
– Return the cached values if the same input values are provided –
that is, not execute the function.
– Share this cache among all sessions in the instance.
Result_Cache
Performance Tuning: How to run correctly
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 44
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
SQL> select count(*) from hr.employees2;
COUNT(*)
----------
10700214
Elapsed: 00:00:00.46
SQL> host
[oracle@lab1 ~]$ more cache2_result.sql
SELECT count(*)
FROM ( SELECT department_id, manager_id,
count(*) count
FROM hr.employees
GROUP BY department_id, manager_id )
view1
WHERE department_id <> 30;
SQL> connect hr/hr@pdb1
Connected.
SQL> @cache2_result
COUNT(*)
----------
25
Elapsed: 00:00:02.04
Performance Tuning: How to run correctly
Result_Cache
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 45
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
SQL> connect system/oracle@pdb1
Connected.
SQL> alter system flush buffer_cache;
System altered.
Elapsed: 00:00:00.03
SQL> connect hr/hr@pdb1
Connected.
SQL> @cache2_result
COUNT(*)
----------
25
Elapsed: 00:00:02.11
Performance Tuning: How to run correctly
Result_Cache
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 46
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
SQL> host
[oracle@lab1 ~]$ more cache2_result.sql
CREATE OR REPLACE FUNCTION f1 RETURN number is
x number;
begin
SELECT count(*)
INTO x
FROM ( SELECT /*+ RESULT_CACHE */
department_id, manager_id, count(*)
count
FROM hr.employees2
GROUP BY department_id, manager_id )
view1
WHERE department_id <> 30;
return x;
end f1;
SQL> @cache2_result
Function created.
Performance Tuning: How to run correctly
Result_Cache
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 47
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
SQL> select f1 from dual;
F1
----------
25
Elapsed: 00:00:03.45
SQL> select f1 from dual;
F1
----------
25
Elapsed: 00:00:00.00
SQL> connect system/oracle@pdb1
Connected.
SQL> alter system flush buffer_cache;
System altered.
Elapsed: 00:00:00.38
Performance Tuning: How to run correctly
Result_Cache
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 48
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
SQL> connect hr/hr@pdb1
Connected.
SQL> select f1 from dual;
F1
----------
25
Elapsed: 00:00:00.01
SQL> connect system/oracle@pdb1
Connected.
SQL> select hr.f1 from dual;
F1
----------
25
Elapsed: 00:00:00.02
Performance Tuning: How to run correctly
Result_Cache
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential 49
For Oracle employees and authorized partners only. Do not distribute to third parties.
© 2012 Oracle Corporation – Proprietary and Confidential
@rovaque
oracledbacr.blogspot.com
rvargas@netsoftca.com

Weitere ähnliche Inhalte

Was ist angesagt?

Oracle supplier ship and debit
Oracle supplier ship and debitOracle supplier ship and debit
Oracle supplier ship and debitFranklin Gomez
 
Oracle Database features every developer should know about
Oracle Database features every developer should know aboutOracle Database features every developer should know about
Oracle Database features every developer should know aboutgvenzl
 
1 z0 062 - oracle certification
1 z0 062 - oracle certification1 z0 062 - oracle certification
1 z0 062 - oracle certificationadam_jhon
 
Optimizing the Enterprise Manager 12c
Optimizing the Enterprise Manager 12cOptimizing the Enterprise Manager 12c
Optimizing the Enterprise Manager 12cKellyn Pot'Vin-Gorman
 
OOW15 - Testing Oracle E-Business Suite Best Practices
OOW15 - Testing Oracle E-Business Suite Best PracticesOOW15 - Testing Oracle E-Business Suite Best Practices
OOW15 - Testing Oracle E-Business Suite Best Practicesvasuballa
 
Oracle performance management_implementation_and_user_guide
Oracle performance management_implementation_and_user_guideOracle performance management_implementation_and_user_guide
Oracle performance management_implementation_and_user_guidegisdev1
 
Oracle Succession Planning Setup
Oracle Succession Planning SetupOracle Succession Planning Setup
Oracle Succession Planning SetupFeras Ahmad
 
1Z0-050 - Oracle Database
1Z0-050 - Oracle Database1Z0-050 - Oracle Database
1Z0-050 - Oracle Databaseadam_jhon
 
OOW16 - Testing Oracle E-Business Suite Best Practices [CON6713]
OOW16 - Testing Oracle E-Business Suite Best Practices [CON6713]OOW16 - Testing Oracle E-Business Suite Best Practices [CON6713]
OOW16 - Testing Oracle E-Business Suite Best Practices [CON6713]vasuballa
 
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c Tuning Fea...
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c Tuning Fea...OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c Tuning Fea...
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c Tuning Fea...Alex Zaballa
 
OOW15 - Oracle E-Business Suite Integration Best Practices
OOW15 - Oracle E-Business Suite Integration Best PracticesOOW15 - Oracle E-Business Suite Integration Best Practices
OOW15 - Oracle E-Business Suite Integration Best Practicesvasuballa
 
As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0Bruno Borges
 
SAP HANA in an EMC Private Cloud
SAP HANA in an EMC Private CloudSAP HANA in an EMC Private Cloud
SAP HANA in an EMC Private CloudEMC
 
Harnessing the Power of Optimizer Hints
Harnessing the Power of Optimizer HintsHarnessing the Power of Optimizer Hints
Harnessing the Power of Optimizer HintsMaria Colgan
 
GlassFish Roadmap
GlassFish RoadmapGlassFish Roadmap
GlassFish Roadmapglassfish
 
GlassFish BOF
GlassFish BOFGlassFish BOF
GlassFish BOFglassfish
 
Heavy duty oracle primavera usage in enterprise environment
Heavy duty oracle primavera usage in enterprise environmentHeavy duty oracle primavera usage in enterprise environment
Heavy duty oracle primavera usage in enterprise environmentInSync Conference
 
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c New Featur...
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c New Featur...OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c New Featur...
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c New Featur...Alex Zaballa
 
How to build an agentry based mobile app from scratch connecting to an sap ba...
How to build an agentry based mobile app from scratch connecting to an sap ba...How to build an agentry based mobile app from scratch connecting to an sap ba...
How to build an agentry based mobile app from scratch connecting to an sap ba...Ganesh Kumar
 
All of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL DeveloperAll of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL DeveloperJeff Smith
 

Was ist angesagt? (20)

Oracle supplier ship and debit
Oracle supplier ship and debitOracle supplier ship and debit
Oracle supplier ship and debit
 
Oracle Database features every developer should know about
Oracle Database features every developer should know aboutOracle Database features every developer should know about
Oracle Database features every developer should know about
 
1 z0 062 - oracle certification
1 z0 062 - oracle certification1 z0 062 - oracle certification
1 z0 062 - oracle certification
 
Optimizing the Enterprise Manager 12c
Optimizing the Enterprise Manager 12cOptimizing the Enterprise Manager 12c
Optimizing the Enterprise Manager 12c
 
OOW15 - Testing Oracle E-Business Suite Best Practices
OOW15 - Testing Oracle E-Business Suite Best PracticesOOW15 - Testing Oracle E-Business Suite Best Practices
OOW15 - Testing Oracle E-Business Suite Best Practices
 
Oracle performance management_implementation_and_user_guide
Oracle performance management_implementation_and_user_guideOracle performance management_implementation_and_user_guide
Oracle performance management_implementation_and_user_guide
 
Oracle Succession Planning Setup
Oracle Succession Planning SetupOracle Succession Planning Setup
Oracle Succession Planning Setup
 
1Z0-050 - Oracle Database
1Z0-050 - Oracle Database1Z0-050 - Oracle Database
1Z0-050 - Oracle Database
 
OOW16 - Testing Oracle E-Business Suite Best Practices [CON6713]
OOW16 - Testing Oracle E-Business Suite Best Practices [CON6713]OOW16 - Testing Oracle E-Business Suite Best Practices [CON6713]
OOW16 - Testing Oracle E-Business Suite Best Practices [CON6713]
 
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c Tuning Fea...
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c Tuning Fea...OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c Tuning Fea...
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c Tuning Fea...
 
OOW15 - Oracle E-Business Suite Integration Best Practices
OOW15 - Oracle E-Business Suite Integration Best PracticesOOW15 - Oracle E-Business Suite Integration Best Practices
OOW15 - Oracle E-Business Suite Integration Best Practices
 
As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0
 
SAP HANA in an EMC Private Cloud
SAP HANA in an EMC Private CloudSAP HANA in an EMC Private Cloud
SAP HANA in an EMC Private Cloud
 
Harnessing the Power of Optimizer Hints
Harnessing the Power of Optimizer HintsHarnessing the Power of Optimizer Hints
Harnessing the Power of Optimizer Hints
 
GlassFish Roadmap
GlassFish RoadmapGlassFish Roadmap
GlassFish Roadmap
 
GlassFish BOF
GlassFish BOFGlassFish BOF
GlassFish BOF
 
Heavy duty oracle primavera usage in enterprise environment
Heavy duty oracle primavera usage in enterprise environmentHeavy duty oracle primavera usage in enterprise environment
Heavy duty oracle primavera usage in enterprise environment
 
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c New Featur...
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c New Featur...OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c New Featur...
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c New Featur...
 
How to build an agentry based mobile app from scratch connecting to an sap ba...
How to build an agentry based mobile app from scratch connecting to an sap ba...How to build an agentry based mobile app from scratch connecting to an sap ba...
How to build an agentry based mobile app from scratch connecting to an sap ba...
 
All of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL DeveloperAll of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL Developer
 

Ähnlich wie Performance tuning how to write and run correctly sql statement

Ronald Vargas 18c cloud service el siguiente paso en la nueva generacion
Ronald Vargas 18c cloud service el siguiente paso en la nueva generacionRonald Vargas 18c cloud service el siguiente paso en la nueva generacion
Ronald Vargas 18c cloud service el siguiente paso en la nueva generacionRonald Francisco Vargas Quesada
 
01 Ronald Vargas Verdades ciertas, mitos y falacias sobre oracle database 19c
01 Ronald Vargas Verdades ciertas, mitos y falacias sobre oracle database 19c01 Ronald Vargas Verdades ciertas, mitos y falacias sobre oracle database 19c
01 Ronald Vargas Verdades ciertas, mitos y falacias sobre oracle database 19cRonald Francisco Vargas Quesada
 
01 Ronald Vargas 18c cloud service el siguiente paso en la nueva generacion
01 Ronald Vargas 18c cloud service el siguiente paso en la nueva generacion01 Ronald Vargas 18c cloud service el siguiente paso en la nueva generacion
01 Ronald Vargas 18c cloud service el siguiente paso en la nueva generacionRonald Francisco Vargas Quesada
 
New PLSQL in Oracle Database 12c
New PLSQL in Oracle Database 12cNew PLSQL in Oracle Database 12c
New PLSQL in Oracle Database 12cConnor McDonald
 
Oracle Database 12c Feature Support in Oracle SQL Developer
Oracle Database 12c Feature Support in Oracle SQL DeveloperOracle Database 12c Feature Support in Oracle SQL Developer
Oracle Database 12c Feature Support in Oracle SQL DeveloperJeff Smith
 
Partner Webcast – Oracle Public Cloud for ISVs: Migrating Java EE and ADF app...
Partner Webcast – Oracle Public Cloud for ISVs: Migrating Java EE and ADF app...Partner Webcast – Oracle Public Cloud for ISVs: Migrating Java EE and ADF app...
Partner Webcast – Oracle Public Cloud for ISVs: Migrating Java EE and ADF app...Thanos TP
 
Oracle Database 12cR2 Hacking Etico. Viaje a la zona desconocida.
Oracle Database 12cR2 Hacking Etico. Viaje a la zona desconocida.Oracle Database 12cR2 Hacking Etico. Viaje a la zona desconocida.
Oracle Database 12cR2 Hacking Etico. Viaje a la zona desconocida.Ronald Francisco Vargas Quesada
 
MySQL Sharding: Tools and Best Practices for Horizontal Scaling
MySQL Sharding: Tools and Best Practices for Horizontal ScalingMySQL Sharding: Tools and Best Practices for Horizontal Scaling
MySQL Sharding: Tools and Best Practices for Horizontal ScalingMats Kindahl
 
Oracle database 12c_and_DevOps
Oracle database 12c_and_DevOpsOracle database 12c_and_DevOps
Oracle database 12c_and_DevOpsMaria Colgan
 
00.Oracle_Biz Engineering_Introduction_20131118
00.Oracle_Biz Engineering_Introduction_2013111800.Oracle_Biz Engineering_Introduction_20131118
00.Oracle_Biz Engineering_Introduction_20131118JongMyoung Park,Ph.D.
 
Take Full Advantage of the Oracle PL/SQL Compiler
Take Full Advantage of the Oracle PL/SQL CompilerTake Full Advantage of the Oracle PL/SQL Compiler
Take Full Advantage of the Oracle PL/SQL CompilerSteven Feuerstein
 
Using Edition-Based Redefinition for Zero Downtime PL/SQL Changes
Using Edition-Based Redefinition for Zero Downtime PL/SQL ChangesUsing Edition-Based Redefinition for Zero Downtime PL/SQL Changes
Using Edition-Based Redefinition for Zero Downtime PL/SQL ChangesChris Saxon
 
Usability - Ignored by Developers and Undervalued by Managers (article)
Usability - Ignored by Developers and Undervalued by Managers (article)Usability - Ignored by Developers and Undervalued by Managers (article)
Usability - Ignored by Developers and Undervalued by Managers (article)Revelation Technologies
 
Using XA for Batch – Bad idea? (article)
Using XA for Batch – Bad idea? (article)Using XA for Batch – Bad idea? (article)
Using XA for Batch – Bad idea? (article)Revelation Technologies
 
Con8811 converged identity governance for speeding up business and reducing c...
Con8811 converged identity governance for speeding up business and reducing c...Con8811 converged identity governance for speeding up business and reducing c...
Con8811 converged identity governance for speeding up business and reducing c...OracleIDM
 
Goutam_Pal_Resume
Goutam_Pal_ResumeGoutam_Pal_Resume
Goutam_Pal_ResumeGoutam Pal
 
Milomir Vojvodic - Business Analytics And Big Data Partner Forum Dubai 15.11.
Milomir Vojvodic - Business Analytics And Big Data Partner Forum Dubai 15.11.Milomir Vojvodic - Business Analytics And Big Data Partner Forum Dubai 15.11.
Milomir Vojvodic - Business Analytics And Big Data Partner Forum Dubai 15.11.Milomir Vojvodic
 

Ähnlich wie Performance tuning how to write and run correctly sql statement (20)

Ronald Vargas 18c cloud service el siguiente paso en la nueva generacion
Ronald Vargas 18c cloud service el siguiente paso en la nueva generacionRonald Vargas 18c cloud service el siguiente paso en la nueva generacion
Ronald Vargas 18c cloud service el siguiente paso en la nueva generacion
 
01 Ronald Vargas Verdades ciertas, mitos y falacias sobre oracle database 19c
01 Ronald Vargas Verdades ciertas, mitos y falacias sobre oracle database 19c01 Ronald Vargas Verdades ciertas, mitos y falacias sobre oracle database 19c
01 Ronald Vargas Verdades ciertas, mitos y falacias sobre oracle database 19c
 
01 Ronald Vargas 18c cloud service el siguiente paso en la nueva generacion
01 Ronald Vargas 18c cloud service el siguiente paso en la nueva generacion01 Ronald Vargas 18c cloud service el siguiente paso en la nueva generacion
01 Ronald Vargas 18c cloud service el siguiente paso en la nueva generacion
 
Oracle SQLcl
Oracle SQLcl Oracle SQLcl
Oracle SQLcl
 
Oracle Database SE2 Single Tenant 12c
Oracle Database SE2 Single Tenant 12cOracle Database SE2 Single Tenant 12c
Oracle Database SE2 Single Tenant 12c
 
New PLSQL in Oracle Database 12c
New PLSQL in Oracle Database 12cNew PLSQL in Oracle Database 12c
New PLSQL in Oracle Database 12c
 
Oracle Database 12c Feature Support in Oracle SQL Developer
Oracle Database 12c Feature Support in Oracle SQL DeveloperOracle Database 12c Feature Support in Oracle SQL Developer
Oracle Database 12c Feature Support in Oracle SQL Developer
 
Partner Webcast – Oracle Public Cloud for ISVs: Migrating Java EE and ADF app...
Partner Webcast – Oracle Public Cloud for ISVs: Migrating Java EE and ADF app...Partner Webcast – Oracle Public Cloud for ISVs: Migrating Java EE and ADF app...
Partner Webcast – Oracle Public Cloud for ISVs: Migrating Java EE and ADF app...
 
Oracle Database 12cR2 Hacking Etico. Viaje a la zona desconocida.
Oracle Database 12cR2 Hacking Etico. Viaje a la zona desconocida.Oracle Database 12cR2 Hacking Etico. Viaje a la zona desconocida.
Oracle Database 12cR2 Hacking Etico. Viaje a la zona desconocida.
 
MySQL Sharding: Tools and Best Practices for Horizontal Scaling
MySQL Sharding: Tools and Best Practices for Horizontal ScalingMySQL Sharding: Tools and Best Practices for Horizontal Scaling
MySQL Sharding: Tools and Best Practices for Horizontal Scaling
 
Oracle database 12c_and_DevOps
Oracle database 12c_and_DevOpsOracle database 12c_and_DevOps
Oracle database 12c_and_DevOps
 
00.Oracle_Biz Engineering_Introduction_20131118
00.Oracle_Biz Engineering_Introduction_2013111800.Oracle_Biz Engineering_Introduction_20131118
00.Oracle_Biz Engineering_Introduction_20131118
 
OOW-TBE-12c-CON7307-Sharable
OOW-TBE-12c-CON7307-SharableOOW-TBE-12c-CON7307-Sharable
OOW-TBE-12c-CON7307-Sharable
 
Take Full Advantage of the Oracle PL/SQL Compiler
Take Full Advantage of the Oracle PL/SQL CompilerTake Full Advantage of the Oracle PL/SQL Compiler
Take Full Advantage of the Oracle PL/SQL Compiler
 
Using Edition-Based Redefinition for Zero Downtime PL/SQL Changes
Using Edition-Based Redefinition for Zero Downtime PL/SQL ChangesUsing Edition-Based Redefinition for Zero Downtime PL/SQL Changes
Using Edition-Based Redefinition for Zero Downtime PL/SQL Changes
 
Usability - Ignored by Developers and Undervalued by Managers (article)
Usability - Ignored by Developers and Undervalued by Managers (article)Usability - Ignored by Developers and Undervalued by Managers (article)
Usability - Ignored by Developers and Undervalued by Managers (article)
 
Using XA for Batch – Bad idea? (article)
Using XA for Batch – Bad idea? (article)Using XA for Batch – Bad idea? (article)
Using XA for Batch – Bad idea? (article)
 
Con8811 converged identity governance for speeding up business and reducing c...
Con8811 converged identity governance for speeding up business and reducing c...Con8811 converged identity governance for speeding up business and reducing c...
Con8811 converged identity governance for speeding up business and reducing c...
 
Goutam_Pal_Resume
Goutam_Pal_ResumeGoutam_Pal_Resume
Goutam_Pal_Resume
 
Milomir Vojvodic - Business Analytics And Big Data Partner Forum Dubai 15.11.
Milomir Vojvodic - Business Analytics And Big Data Partner Forum Dubai 15.11.Milomir Vojvodic - Business Analytics And Big Data Partner Forum Dubai 15.11.
Milomir Vojvodic - Business Analytics And Big Data Partner Forum Dubai 15.11.
 

Mehr von Ronald Francisco Vargas Quesada

Ronald vargas big data universidad hispanoamericana v2.1
Ronald vargas big data universidad hispanoamericana  v2.1Ronald vargas big data universidad hispanoamericana  v2.1
Ronald vargas big data universidad hispanoamericana v2.1Ronald Francisco Vargas Quesada
 
Ronald vargas presente y futuro la adolescencia de los super sistemas computa...
Ronald vargas presente y futuro la adolescencia de los super sistemas computa...Ronald vargas presente y futuro la adolescencia de los super sistemas computa...
Ronald vargas presente y futuro la adolescencia de los super sistemas computa...Ronald Francisco Vargas Quesada
 
Computación Cognitiva: Mejorando la experiencia del Cliente
Computación Cognitiva: Mejorando la experiencia del ClienteComputación Cognitiva: Mejorando la experiencia del Cliente
Computación Cognitiva: Mejorando la experiencia del ClienteRonald Francisco Vargas Quesada
 
Oracle Database 12c Arquitectura Single & Multitenant Español
Oracle Database 12c Arquitectura Single & Multitenant EspañolOracle Database 12c Arquitectura Single & Multitenant Español
Oracle Database 12c Arquitectura Single & Multitenant EspañolRonald Francisco Vargas Quesada
 
Ronald vargas computación cognitiva computación del conocimiento introduccion
Ronald vargas computación cognitiva  computación del conocimiento introduccionRonald vargas computación cognitiva  computación del conocimiento introduccion
Ronald vargas computación cognitiva computación del conocimiento introduccionRonald Francisco Vargas Quesada
 
Performance Tuning: Como escribir y correr correctamente una sentencia SQL en...
Performance Tuning: Como escribir y correr correctamente una sentencia SQL en...Performance Tuning: Como escribir y correr correctamente una sentencia SQL en...
Performance Tuning: Como escribir y correr correctamente una sentencia SQL en...Ronald Francisco Vargas Quesada
 
Ventajas y beneficios de oracle database 12c el manejo de datos en la 3era pl...
Ventajas y beneficios de oracle database 12c el manejo de datos en la 3era pl...Ventajas y beneficios de oracle database 12c el manejo de datos en la 3era pl...
Ventajas y beneficios de oracle database 12c el manejo de datos en la 3era pl...Ronald Francisco Vargas Quesada
 
Charla técnica comercial v3.0 junio 2014 db visit productos
Charla técnica comercial v3.0 junio 2014 db visit productosCharla técnica comercial v3.0 junio 2014 db visit productos
Charla técnica comercial v3.0 junio 2014 db visit productosRonald Francisco Vargas Quesada
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cRonald Francisco Vargas Quesada
 
Oracle cloud 2013 infraestructura software plataforma y base de datos como se...
Oracle cloud 2013 infraestructura software plataforma y base de datos como se...Oracle cloud 2013 infraestructura software plataforma y base de datos como se...
Oracle cloud 2013 infraestructura software plataforma y base de datos como se...Ronald Francisco Vargas Quesada
 

Mehr von Ronald Francisco Vargas Quesada (20)

Análisis de Datos: La guerra, la humanidad y el futuro
Análisis de Datos: La guerra, la humanidad y el futuroAnálisis de Datos: La guerra, la humanidad y el futuro
Análisis de Datos: La guerra, la humanidad y el futuro
 
Oracle Database XE 18c
Oracle Database XE 18cOracle Database XE 18c
Oracle Database XE 18c
 
Ronald vargas big data universidad hispanoamericana v2.1
Ronald vargas big data universidad hispanoamericana  v2.1Ronald vargas big data universidad hispanoamericana  v2.1
Ronald vargas big data universidad hispanoamericana v2.1
 
Ronald vargas presente y futuro la adolescencia de los super sistemas computa...
Ronald vargas presente y futuro la adolescencia de los super sistemas computa...Ronald vargas presente y futuro la adolescencia de los super sistemas computa...
Ronald vargas presente y futuro la adolescencia de los super sistemas computa...
 
Computación Cognitiva: Mejorando la experiencia del Cliente
Computación Cognitiva: Mejorando la experiencia del ClienteComputación Cognitiva: Mejorando la experiencia del Cliente
Computación Cognitiva: Mejorando la experiencia del Cliente
 
Oracle Database 12c Arquitectura Single & Multitenant Español
Oracle Database 12c Arquitectura Single & Multitenant EspañolOracle Database 12c Arquitectura Single & Multitenant Español
Oracle Database 12c Arquitectura Single & Multitenant Español
 
Ronald vargas computación cognitiva computación del conocimiento introduccion
Ronald vargas computación cognitiva  computación del conocimiento introduccionRonald vargas computación cognitiva  computación del conocimiento introduccion
Ronald vargas computación cognitiva computación del conocimiento introduccion
 
Performance Tuning: Como escribir y correr correctamente una sentencia SQL en...
Performance Tuning: Como escribir y correr correctamente una sentencia SQL en...Performance Tuning: Como escribir y correr correctamente una sentencia SQL en...
Performance Tuning: Como escribir y correr correctamente una sentencia SQL en...
 
Oracle Database Hacking Etico
Oracle Database Hacking EticoOracle Database Hacking Etico
Oracle Database Hacking Etico
 
Ventajas y beneficios de oracle database 12c el manejo de datos en la 3era pl...
Ventajas y beneficios de oracle database 12c el manejo de datos en la 3era pl...Ventajas y beneficios de oracle database 12c el manejo de datos en la 3era pl...
Ventajas y beneficios de oracle database 12c el manejo de datos en la 3era pl...
 
A todo vapor con oracle forms & services laouc
A todo vapor con oracle forms & services laoucA todo vapor con oracle forms & services laouc
A todo vapor con oracle forms & services laouc
 
Charla técnica comercial v3.0 junio 2014 db visit productos
Charla técnica comercial v3.0 junio 2014 db visit productosCharla técnica comercial v3.0 junio 2014 db visit productos
Charla técnica comercial v3.0 junio 2014 db visit productos
 
Sociedades de conocimiento
Sociedades de conocimientoSociedades de conocimiento
Sociedades de conocimiento
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12c
 
Cedes cloud 2013 ronald vargas quesada
Cedes cloud 2013 ronald vargas quesadaCedes cloud 2013 ronald vargas quesada
Cedes cloud 2013 ronald vargas quesada
 
Oracle database 12c new features v1 2013 mayo
Oracle database 12c new features v1 2013 mayoOracle database 12c new features v1 2013 mayo
Oracle database 12c new features v1 2013 mayo
 
Oracle cloud 2013 infraestructura software plataforma y base de datos como se...
Oracle cloud 2013 infraestructura software plataforma y base de datos como se...Oracle cloud 2013 infraestructura software plataforma y base de datos como se...
Oracle cloud 2013 infraestructura software plataforma y base de datos como se...
 
Weblogic server 12c agosto 2012
Weblogic server 12c agosto 2012Weblogic server 12c agosto 2012
Weblogic server 12c agosto 2012
 
Presentación instalacion de base de datos 2012 r3.0
Presentación instalacion de base de datos 2012 r3.0Presentación instalacion de base de datos 2012 r3.0
Presentación instalacion de base de datos 2012 r3.0
 
Oracle golden gate veridata
Oracle golden gate veridataOracle golden gate veridata
Oracle golden gate veridata
 

Kürzlich hochgeladen

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...itnewsafrica
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 

Kürzlich hochgeladen (20)

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 

Performance tuning how to write and run correctly sql statement

  • 1. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 1 Performance Tuning: Como escribir y correr correctamente una sentencia SQL By Ronald Vargas Quesada, Oracle ACE Director Expertise Database Management & Performance Technical PreSales Consultant, Netsoft de Centroamérica Oracledbacr.blogspot.com
  • 2. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 2 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Background 50% mistype a statement & 9 out of 10 the incorrectly executed Performance Tuning: How to write & run correctly
  • 3. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 3 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Performance Tuning: How to write & run correctly Programar siempre y de la misma manera es eficiente !
  • 4. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 4 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Continuo aprendizaje Performance Tuning: How to write & run correctly
  • 5. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 5 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential There's a tradeoff between efficiency (fewer conditional statements) and ease of comprehension. Existe un equilibrio entre la eficiencia ( menos sentencias condicionales ) y la facilidad de comprensión. Declaración #1 absoluta Performance Tuning: How to write & run correctly
  • 6. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 6 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential The real world is very complicated; the software we write is supposed to map those complexities into applications. The result is that we often end up needing to deal with convoluted logical expressions. El mundo real es muy complicado; el software que escribimos supone un mapeo de esas complejidades en las aplicaciones. El resultado es que a menudo terminamos con la necesidad de lidiar con expresiones lógicas complejas. Performance Tuning: How to write & run correctly Declaración #2 absoluta
  • 7. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 7 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Following this best practice will make your code more readable and expressive. You avoid redundant code, always bad news in a program, since it increases maintenance costs and the chance of introducing bugs into your code. Aplicando buenas prácticas se puede lograr que su código sea más legible y expresivo. Evite el código redundante, este siempre es una mala noticia en un programa, ya que aumenta los costos de mantenimiento y la posibilidad de introducir errores en el código. Declaración #3 absoluta Performance Tuning: How to write & run correctly
  • 8. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 8 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential You need not take out "programmer's insurance": "Gee, I don't know if I need to declare that or not, so I'd better declare it." Instead, you make certain you understand how PL/SQL works and write appropriate code. "Vaya, no sé si tengo que declararlo o no, así que será mejor que lo declare.“ En su lugar, asegúrese de que entiende cómo funciona el PL/SQL y escriba el código apropiado. Performance Tuning: How to write & run correctly Declaración #4 absoluta
  • 9. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 9 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Your code doesn't do any unnecessary work and so executes more efficiently. TIP: You can, in general, expect the performance of built-in functions such as SUBSTR to work more efficiently in SQL than in PL/SQL, so move the processing to the SQL layer whenever possible. “El código no hace ningún trabajo innecesario y así se ejecuta de manera más eficiente.” En general el desempeño de las funciones integradas tales como SUBSTR trabajan más eficientemente en SQL que en PL/SQL. Performance Tuning: How to write & run correctly Declaración #5 absoluta
  • 10. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 10 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Performance Tuning: How to write correctly That´s it ! That´s it friends!
  • 11. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 11 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential quick example #1 Performance Tuning: How to write correctly
  • 12. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 12 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential employees by salary
  • 13. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 13 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential SQL> select employee_id, job_id, hire_date, salary 2 from employees 3 order by salary; EMPLOYEE_ID JOB_ID HIRE_DATE SALARY ----------- ---------- --------- ---------- 132 ST_CLERK 10-APR-07 2100 136 ST_CLERK 06-FEB-08 2200 128 ST_CLERK 08-MAR-08 2200 127 ST_CLERK 14-JAN-07 2400 135 ST_CLERK 12-DEC-07 2400 191 SH_CLERK 19-DEC-07 2500 119 PU_CLERK 10-AUG-07 2500 140 ST_CLERK 06-APR-06 2500 144 ST_CLERK 09-JUL-06 2500 182 SH_CLERK 21-JUN-07 2500 131 ST_CLERK 16-FEB-05 2500 Performance Tuning: How to write correctly
  • 14. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 14 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Who hired first ? hiring sequence Performance Tuning: How to write correctly
  • 15. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 15 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 1 select e.employee_id, e.first_name, e.job_id, e.hire_date, e.salary, x.sequence 2 from employees e, 3 (select e2.employee_id, count(*) sequence from employees e1, employees e2 4 where e1.hire_date <= e2.hire_date 5 group by e2.employee_id 6 ) x 7 where e.employee_id = x.employee_id 8* order by salary SQL> / EMPLOYEE_ID FIRST_NAME JOB_ID HIRE_DATE SALARY SEQUENCE ----------- -------------------- ---------- --------- ---------- ---------- 132 TJ ST_CLERK 10-APR-07 2100 85 128 Steven ST_CLERK 08-MAR-08 2200 104 136 Hazel ST_CLERK 06-FEB-08 2200 102 135 Ki ST_CLERK 12-DEC-07 2400 95 127 James ST_CLERK 14-JAN-07 2400 78 144 Peter ST_CLERK 09-JUL-06 2500 71 Performance Tuning: How to write correctly very complicated !!
  • 16. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 16 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Is very simple ? Performance Tuning: How to write correctly
  • 17. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 17 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Much or little work ? Performance Tuning: How to write correctly
  • 18. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 18 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------- Plan hash value: 2074273239 ------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 107 | 5243 | 14 (36)| 00:00:01 | | 1 | SORT ORDER BY | | 107 | 5243 | 14 (36)| 00:00:01 | |* 2 | HASH JOIN | | 107 | 5243 | 13 (31)| 00:00:01 | | 3 | TABLE ACCESS FULL | EMPLOYEES | 107 | 3424 | 3 (0)| 00:00:01 | | 4 | VIEW | | 107 | 1819 | 9 (34)| 00:00:01 | | 5 | HASH GROUP BY | | 107 | 2140 | 9 (34)| 00:00:01 | | 6 | MERGE JOIN | | 5783 | 112K| 8 (25)| 00:00:01 | | 7 | SORT JOIN | | 107 | 856 | 4 (25)| 00:00:01 | | 8 | TABLE ACCESS FULL| EMPLOYEES | 107 | 856 | 3 (0)| 00:00:01 | |* 9 | SORT JOIN | | 107 | 1284 | 4 (25)| 00:00:01 | | 10 | TABLE ACCESS FULL| EMPLOYEES | 107 | 1284 | 3 (0)| 00:00:01 | ------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("E"."EMPLOYEE_ID"="X"."EMPLOYEE_ID") 9 - access("E1"."HIRE_DATE"<="E2"."HIRE_DATE") filter("E1"."HIRE_DATE"<="E2"."HIRE_DATE") 24 rows selected. Performance Tuning: How to write correctly
  • 19. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 19 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Make it Simple !! Performance Tuning: How to write correctly
  • 20. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 20 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential SQL> select employee_id, first_name, job_id, hire_date, salary, rank() over (order by hire_date) as hire_seq 2 from employees 3 order by salary; EMPLOYEE_ID FIRST_NAME JOB_ID HIRE_DATE SALARY HIRE_SEQ ----------- -------------------- ---------- --------- ---------- ---------- 132 TJ ST_CLERK 10-APR-07 2100 85 136 Hazel ST_CLERK 06-FEB-08 2200 102 128 Steven ST_CLERK 08-MAR-08 2200 104 127 James ST_CLERK 14-JAN-07 2400 78 135 Ki ST_CLERK 12-DEC-07 2400 95 131 James ST_CLERK 16-FEB-05 2500 28 140 Joshua ST_CLERK 06-APR-06 2500 65 144 Peter ST_CLERK 09-JUL-06 2500 71 Performance Tuning: How to write correctly
  • 21. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 21 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------- Plan hash value: 1701542182 --------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 107 | 3424 | 5 (40)| 00:00:01 | | 1 | SORT ORDER BY | | 107 | 3424 | 5 (40)| 00:00:01 | | 2 | WINDOW SORT | | 107 | 3424 | 5 (40)| 00:00:01 | | 3 | TABLE ACCESS FULL| EMPLOYEES | 107 | 3424 | 3 (0)| 00:00:01 | --------------------------------------------------------------------------------- 10 rows selected. Performance Tuning: How to write correctly
  • 22. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 22 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential When Should I Use an Index? Performance Tuning: How to write correctly
  • 23. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 23 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential When Should I Use an Index? Performance Tuning: How to write correctly  No es un puntero  Segmento con almacenamiento en un tablespace  Parámetros de concurrencia  Mejoran el acceso a los datos  Degrada gradualmente los procesos de Update, Insert y Delete de tuplas.  No son libres de mantenimiento  +20% entradas inválidas, el motor omite el uso del índice.  Requieren cada cierto tiempo recrearse para balancear el árbol y eliminar las entras inválidas
  • 24. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 24 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Performance Tuning: How to write correctly Optimización basada en RULE ( Regla ) 10gR2 o inferior a a a a a b b b b b b b b a a a a c c c c c c d d d e ... When Should I Use an Index?
  • 25. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 25 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Optimización basada en COST (Costo ) 7.x o superior, 11g y superior sólo optimiza basado en COSTO a b c d e When Should I Use an Index? Performance Tuning: How to write correctly Un columna que es llave foránea Siempre debe estar indexada.
  • 26. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 26 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Driving Table, ( RBO Only ) Performance Tuning: How to write correctly
  • 27. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 27 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Parseo de instrucciones Performance Tuning: How to write correctly La fase de análisis sintáctico para declaraciones se puede disminuir mediante el uso eficiente de alias. Si un alias no está presente, el motor debe resolver qué tablas poseen las columnas especificadas. El siguiente es un ejemplo.
  • 28. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 28 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential  Para la consulta A, todas las filas de TABLA2 serán leídos por cada fila en la Tabla 1. El efecto será 1.000.000 filas leídas de artículos.  En el caso de la consulta B, se leerá un máximo de 1 registro de la TABLA2 para cada fila en la TABLA1, reduciendo así la carga de procesamiento de la declaración Si la mayoría de los criterios de filtrado se encuentran en la subconsulta entonces la variación IN es más eficiente. Si la mayoría de los criterios de filtrado están en la consulta entonces la variación de EXISTS es más eficiente. Se sugiere que usted debe tratar ambas variantes y ver cuál funciona mejor. Exists vs IN Performance Tuning: How to write correctly
  • 29. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 29 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential SQL> host [oracle@LAB1 ~]$ vi script1.sql [oracle@LAB1 ~]$ more script1.sql set timing on begin for i in 1 .. 100000 loop execute immediate 'insert into t (x,y) values ( ' || i || ', ''x'') '; end loop; end; / [oracle@LAB1 ~]$ Not using bind variable Performance Tuning: How to write correctly
  • 30. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 30 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential [oracle@LAB1 ~]$ more script2.sql set timing on begin for i in 1 .. 100000 loop execute immediate 'insert into t (x,y) values ( :i, ''x'')' using i; end loop; end; / [oracle@LAB1 ~]$ Using Bind variable Performance Tuning: How to write correctly (*) Up to 1320% higher
  • 31. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 31 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential PLSQL_CODE_TYPE specifies the compilation mode for PL/SQL library units. Syntax PLSQL_CODE_TYPE = { INTERPRETED | NATIVE } Default INTERPRETED Modifiable Alter session, Alter system Basic No INTERPRETED = interpreter engine / NATIVE = native machine code, without incurring any interpreter overhead PLSQL_CODE_TYPE Performance Tuning: How to run correctly
  • 32. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 32 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential When the value of this parameter is changed, it has no effect on PL/SQL library units that have already been compiled. The value of this parameter is stored persistently with each library unit. Performance Tuning: How to run correctly PLSQL_CODE_TYPE If a PL/SQL library unit is compiled native, all subsequent automatic recompilations of that library unit will use native compilation.
  • 33. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 33 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Performance Tuning: How to run correctly Environment
  • 34. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 34 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Performance Tuning: How to run correctly CREATE OR REPLACE FUNCTION testeo ( n positive ) return integer is begin if ( n = 1) OR ( n = 2 ) then return 1; else return testeo(n-1) + testeo(n-2); end if; end testeo; / Example
  • 35. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 35 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Performance Tuning: How to run correctly set serveroutput on set timing on --- anonymous block declare x number; begin x := testeo(40); dbms_output.put_line(x); end; / Example
  • 36. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 36 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Performance Tuning: How to run correctly [oracle@lab1 admin]$ sqlplus hr/hr@PDB1 SQL*Plus: Release 12.1.0.1.0 Production on Wed Apr 23 17:23:43 2014 Copyright (c) 1982, 2013, Oracle. All rights reserved. Last Successful login time: Wed Jan 15 2014 12:14:36 -06:00 Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options SQL> Example
  • 37. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 37 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Performance Tuning: How to run correctly SQL> @p1.pl Function created. SQL> alter session set plsql_code_type = 'INTERPRETED'; Session altered. SQL> alter function testeo compile; Function altered. Example
  • 38. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 38 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Performance Tuning: How to run correctly SQL> set linesize 200 SQL> @ver_parametro.pl Example
  • 39. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 39 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Performance Tuning: How to run correctly SQL> @ej1.pl 102334155 PL/SQL procedure successfully completed. Elapsed: 00:00:52.22 SQL> alter session set plsql_code_type = 'NATIVE'; Session altered. SQL> alter function testeo compile; Function altered. Example SQL> @ej1.pl 102334155 PL/SQL procedure successfully completed. Elapsed: 00:00:27.73
  • 40. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 40 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Performance Tuning: How to run correctly SQL> @ej1.pl R/ 102334155 PL/SQL procedure successfully completed. Elapsed: 00:00:56.43 SQL> alter session set plsql_code_type = 'NATIVE'; Session altered. SQL> @ej1.pl R/ 102334155 PL/SQL procedure successfully completed. Elapsed: 00:00:57.40 SQL> alter function testeo compile; Function altered. Example ( Do not forget: COMPILE ) SQL> @ej1.pl R/ 102334155 PL/SQL procedure successfully completed. Elapsed: 00:00:29.28 SQL>
  • 41. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 41 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Performance Tuning: How to run correctly create or replace procedure insertar as begin for i in 1 .. 100000 loop execute immediate 'insert into t(x,y) values (' || i ||',''x'')'; end loop; end; / Example 2 ( Compiled=‘NATIVE’ ) SQL> execute insertar; PL/SQL procedure successfully completed. Elapsed: 00:01:12.61
  • 42. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 42 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential Performance Tuning: How to run correctly create or replace procedure insertarb as begin for i in 1 .. 100000 loop execute immediate 'insert into t(x,y) values (:i,''x'')' using i; end loop; end; / Example 2, ( Compiled =‘NATIVE’ ) SQL> execute insertarb; PL/SQL procedure successfully completed. Elapsed: 00:00:05.05
  • 43. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 43 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential The Result Cache is a new memory structure in the SGA. By adding the RESULT_CACHE clause to your function, Oracle will: – Cache the values returned by the function, along with the input values. – Return the cached values if the same input values are provided – that is, not execute the function. – Share this cache among all sessions in the instance. Result_Cache Performance Tuning: How to run correctly
  • 44. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 44 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential SQL> select count(*) from hr.employees2; COUNT(*) ---------- 10700214 Elapsed: 00:00:00.46 SQL> host [oracle@lab1 ~]$ more cache2_result.sql SELECT count(*) FROM ( SELECT department_id, manager_id, count(*) count FROM hr.employees GROUP BY department_id, manager_id ) view1 WHERE department_id <> 30; SQL> connect hr/hr@pdb1 Connected. SQL> @cache2_result COUNT(*) ---------- 25 Elapsed: 00:00:02.04 Performance Tuning: How to run correctly Result_Cache
  • 45. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 45 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential SQL> connect system/oracle@pdb1 Connected. SQL> alter system flush buffer_cache; System altered. Elapsed: 00:00:00.03 SQL> connect hr/hr@pdb1 Connected. SQL> @cache2_result COUNT(*) ---------- 25 Elapsed: 00:00:02.11 Performance Tuning: How to run correctly Result_Cache
  • 46. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 46 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential SQL> host [oracle@lab1 ~]$ more cache2_result.sql CREATE OR REPLACE FUNCTION f1 RETURN number is x number; begin SELECT count(*) INTO x FROM ( SELECT /*+ RESULT_CACHE */ department_id, manager_id, count(*) count FROM hr.employees2 GROUP BY department_id, manager_id ) view1 WHERE department_id <> 30; return x; end f1; SQL> @cache2_result Function created. Performance Tuning: How to run correctly Result_Cache
  • 47. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 47 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential SQL> select f1 from dual; F1 ---------- 25 Elapsed: 00:00:03.45 SQL> select f1 from dual; F1 ---------- 25 Elapsed: 00:00:00.00 SQL> connect system/oracle@pdb1 Connected. SQL> alter system flush buffer_cache; System altered. Elapsed: 00:00:00.38 Performance Tuning: How to run correctly Result_Cache
  • 48. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 48 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential SQL> connect hr/hr@pdb1 Connected. SQL> select f1 from dual; F1 ---------- 25 Elapsed: 00:00:00.01 SQL> connect system/oracle@pdb1 Connected. SQL> select hr.f1 from dual; F1 ---------- 25 Elapsed: 00:00:00.02 Performance Tuning: How to run correctly Result_Cache
  • 49. For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential 49 For Oracle employees and authorized partners only. Do not distribute to third parties. © 2012 Oracle Corporation – Proprietary and Confidential @rovaque oracledbacr.blogspot.com rvargas@netsoftca.com