SlideShare une entreprise Scribd logo
1  sur  43
Télécharger pour lire hors ligne
Serie Underground
Por Ronald Vargas, Oracle ACE
Oracledbacr.blogspot.com
Indices virtuales


       @rovaque
                    Oracledbacr.blogspot.com
Indices virtuales


    •    El proceso de afinamiento de instrucciones SQL, requiere
         que de manera alterna, podamos definir estrategias de
         indexación, para observar su efecto en los planes de
         ejecución.

    •    Crear índices adicionales, no es el problema.
Indices virtuales

•    El problema es, que crear índices extras sobre tablas grandes, puede
     tomar un monto considerado de tiempo y espacio en disco.

•    Adicionalmente, los índices creados pueden ser utilizados por otras
     sesiones de usuarios y podría afectar el rendimiento en otras partes de la
     aplicación.

•    Esto puede ser problemático cuando estamos intentando identificar el
     problema en un sistema en producción.
Indices virtuales

   –  En contraste a los índices convencionales, los índices virtuales no
      están asociados a un segmento, el tiempo de creación y el espacio
      asociado en disco es irrelevante.

   –  Adicionalmente, no pueden ser vistos por otras sesiones, por tanto,
      no se ve afectado el normal funcionamiento del sistema.

   –  Este clase muestra de manera sencilla como utilizarlos y las
      consideraciones que debemos tener en cuenta.
Indices virtuales
SQL> desc movto_h
 Name                                        Null?      Type
 -----------------------------------------   --------   --------------
 NO_CIA                                      NOT NULL   VARCHAR2(2)
 CENTRO                                      NOT NULL   VARCHAR2(2)
 TIPO_DOC                                    NOT NULL   VARCHAR2(2)
 PERIODO                                     NOT NULL   VARCHAR2(4)
 RUTA                                        NOT NULL   VARCHAR2(4)
 NO_DOCU                                     NOT NULL   VARCHAR2(12)
 FECHA                                       NOT NULL   DATE
 NO_FISICO                                              VARCHAR2(12)
 SERIE_FISICO                                           VARCHAR2(15)
 ...
 FECHA_APLICACION                                       DATE
 TSTAMP                                                 DATE
 NO_TRASLADO                                            VARCHAR2(12)
Indices virtuales


         SQL> select count(*) from movto_h;

          COUNT(*)
           ----------
          6445961
Indices virtuales

   SQL> create index v_movto_h_nofisico on movto_h(no_fisico) nosegment;

   Index created.

   SQL> explain plan for
    2 select count(distinct no_fisico) from movto_h;

   Explained.
Indices virtuales

 SQL> select * from table(dbms_xplan.display);

 PLAN_TABLE_OUTPUT
 ------------------------------------------------------------------------------------
 Plan hash value: 891170817

 ------------------------------------------------------------------------------
 | Id | Operation           | Name    | Rows | Bytes | Cost (%CPU)| Time      |
 ------------------------------------------------------------------------------
 |   0 | SELECT STATEMENT   |         |     1 |     7 | 21381   (3)| 00:04:17 |
 |   1 | SORT GROUP BY      |         |     1 |     7 |            |          |
 |   2 |   TABLE ACCESS FULL| movto_h | 6445K|     43M| 21381   (3)| 00:04:17 |
 ------------------------------------------------------------------------------

 9 rows selected.
Indices virtuales
SQL> explain plan for
  2 select count(distinct no_fisico) from movto_h where no_fisico < 10000;

Explained.

SQL> select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
Plan hash value: 891170817

------------------------------------------------------------------------------
| Id | Operation           | Name    | Rows | Bytes | Cost (%CPU)| Time      |
------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |         |     1 |     7 | 21547   (3)| 00:04:19 |
|   1 | SORT GROUP BY      |         |     1 |     7 |            |          |
|* 2 |    TABLE ACCESS FULL| movto_h |   322K| 2203K| 21547    (3)| 00:04:19 |
------------------------------------------------------------------------------

Predicate Information (identified by operation id):

PLAN_TABLE_OUTPUT
Indices virtuales

 SQL> create index v_movto_h_nofisico2 on
 movto_h(to_number(no_fisico)) nosegment;


 Index created.
 SQL> explain plan for
   2 select count(distinct no_fisico) from movto_h where no_fisico
 < 10000;

 Explained.
Indices virtuales
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------------
Plan hash value: 891170817
------------------------------------------------------------------------------
| Id | Operation           | Name    | Rows | Bytes | Cost (%CPU)| Time      |
------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |         |      1 |     7 | 21547  (3)| 00:04:19 |
|   1 | SORT GROUP BY      |         |      1 |     7 |           |          |
|* 2 |    TABLE ACCESS FULL| movto_h |   322K| 2203K| 21547    (3)| 00:04:19 |
------------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------------
   2 - filter(TO_NUMBER("NO_FISICO")<10000)
14 rows selected.
Indices virtuales
SQL>
SQL> alter session set "_use_nosegment_indexes"=TRUE;
Session altered.

SQL> explain plan for
  2 select count(distinct no_fisico) from movto_h where no_fisico <
10000;

Explained.
Indices virtuales
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------
Plan hash value: 2481667387
--------------------------------------------------------------------------------------------
| Id | Operation              | Name                | Rows | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT      |                     |     1 |    7 |     7   (0)| 00:00:01 |
|   1 | SORT GROUP BY         |                     |     1 |    7 |            |          |
|* 2 |    INDEX FAST FULL SCAN| V_movto_h_NOFISICO |    322K| 2203K|     7   (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------
   2 - filter(TO_NUMBER("NO_FISICO")<10000)

14 rows selected.
Indices virtuales

SQL> SELECT index_owner, index_name
  2    FROM dba_ind_columns
  3   WHERE index_name NOT LIKE 'BIN$%'
  4 MINUS
  5 SELECT owner, index_name
  6    FROM dba_indexes;

INDEX_OWNER                      INDEX_NAME
------------------------------   ------------------------------
PRUEBAS21                        V_movto_h_NOFISICO
PRUEBAS21                        V_movto_h_NOFISICO2
PRUEBAS21                        V_ARINMN
Indices virtuales

SQL> drop index v_movto_h_nofisico;
Index dropped.

SQL> explain plan for
  2 select count(distinct no_fisico) from movto_h where no_fisico < 10000;
Explained.
Indices virtuales
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------------
Plan hash value: 11771441
--------------------------------------------------------------------------------------
| Id | Operation                     | Name                | Rows | Bytes | Cost (%CPU)|    Time     |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |                     |     1 |     7 |    10   (0)|   00:00:01 |
|   1 | SORT GROUP BY                |                     |     1 |     7 |            |            |
|   2 |   TABLE ACCESS BY INDEX ROWID| movto_h             |   322K| 2203K|     10   (0)|   00:00:01 |
|* 3 |     INDEX RANGE SCAN          | V_movto_h_NOFISICO2 | 58014 |       |     2   (0)|   00:00:01 |
--------------------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   3 - access(TO_NUMBER("NO_FISICO")<10000)

15 rows selected.
Indices virtuales
SQL> select count(*) from movto_h;
  COUNT(*)
----------
   6445961

drop index v_movto_h_nofisico2;

create index v_movto_h_nofisico2 on movto_h(to_number(no_fisico)) nosegment;
drop index v_movto_h_nofisico2;

create index v_movto_h_nofisico2 on movto_h(to_number(no_fisico));

SQL> drop index v_movto_h_nofisico2;
Index dropped.
Indices virtuales
SQL>
SQL> set timing on;
SQL>

SQL> create index v_movto_h_nofisico2 on movto_h(to_number(no_fisico))
nosegment;

Index created.

Elapsed: 00:00:00.03

SQL> drop index v_movto_h_nofisico2;

Index dropped.

Elapsed: 00:00:00.02
Indices virtuales
SQL> create index v_movto_h_nofisico2 on
movto_h(to_number(no_fisico));

Index created.

Elapsed: 00:01:09.56

SQL> explain plan for
  2 select count(distinct no_fisico) from movto_h where no_fisico
< 10000;

Explained.

Elapsed: 00:00:00.01
Indices virtuales
SQL> select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
Plan hash value: 891170817
------------------------------------------------------------------------------
| Id | Operation           | Name    | Rows | Bytes | Cost (%CPU)| Time      |
------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |         |     1 |      7 | 21547  (3)| 00:04:19 |
|   1 | SORT GROUP BY      |         |     1 |      7 |           |          |
|* 2 |    TABLE ACCESS FULL| movto_h |   322K| 2203K| 21547    (3)| 00:04:19 |
------------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------
   2 - filter(TO_NUMBER("NO_FISICO")<10000)

14 rows selected.
Indices virtuales

SQL> alter session set "_use_nosegment_indexes"=FALSE;
Session altered.

Elapsed: 00:00:00.01

SQL> explain plan for
  2 select count(distinct no_fisico) from movto_h where no_fisico < 10000;

Explained.

Elapsed: 00:00:00.01

SQL> select * from table(dbms_xplan.display);
Indices virtuales
PLAN_TABLE_OUTPUT

-----------------------------------------------------------------------------------
Plan hash value: 891170817
------------------------------------------------------------------------------
| Id | Operation           | Name    | Rows | Bytes | Cost (%CPU)| Time      |
------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |         |     1 |      7 | 21547  (3)| 00:04:19 |
|   1 | SORT GROUP BY      |         |     1 |      7 |           |          |
|* 2 |    TABLE ACCESS FULL| movto_h |   322K| 2203K| 21547    (3)| 00:04:19 |
------------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------

   2 - filter(TO_NUMBER("NO_FISICO")<10000)

14 rows selected.
Indices virtuales
Indices virtuales
 Calculando estadísticas al índice virtual

 SQL> drop index V_movto_h_NOFISICO2;

 Index dropped.

 SQL> create index v_movto_h_nofisico2 on
 MOVTO_H(to_number(no_fisico)) nosegment;

 Index created.

 SQL> execute
 dbms_stats.gather_index_stats('PRUEBAS21','V_MOVTO_H_NOFISICO2');

 PL/SQL procedure successfully completed.
Indices virtuales

 SQL> alter session set "_use_nosegment_indexes"=TRUE;

 Session altered.

 SQL> explain plan for
  2 select count(distinct no_fisico) from MOVTO_H where no_fisico < 10000;

 Explained.

 SQL> set linesize 1000
 SQL> select * from table(dbms_xplan.display);
Indices virtuales
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------
Plan hash value: 1788350122

----------------------------------------------------------------------------------------------------
| Id | Operation                     | Name                | Rows | Bytes | Cost (%CPU)| Time      |
----------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |                     |     1 |     7 |    30   (0)| 00:00:01 |
|   1 | SORT GROUP BY                |                     |     1 |     7 |            |          |
|   2 |   TABLE ACCESS BY INDEX ROWID| MOVTO_H             |   218K| 1495K|     30   (0)| 00:00:01 |
|* 3 |     INDEX RANGE SCAN          | V_MOVTO_H_NOFISICO2 |   218K|       |     2   (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------


PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------

   3 - access(TO_NUMBER("NO_FISICO")<10000)
Indices virtuales



   El optimizador de Oracle 10g y superiores trabaja
   basado en optimización por COSTO.

   RBO no esta soportado en Oracle11g
Columnas Virtuales
 Columnas Virtuales
    Fórmula / columnas calculadas - sobre la base de datos
    Restricciones adicionales - sobre la base de datos
    Nueva categoría para la partición - sobre la base de datos
    Integridad creativa de referencia - en la base de datos


 Sin columnas virtuales- inconvenientes
    Triggers - caros
    Vistas- a veces se olvidan
    Re-diseño – Mucho trabajo duro!
Columnas Virtuales
SQL> show user
USER is "DEMO_LAB"
SQL> desc employees
 Name                                        Null?    Type
 -----------------------------------------   -------- ----------------------------
 EMPLOYEE_ID                                          NUMBER(6)
 FIRST_NAME                                           VARCHAR2(20)
 LAST_NAME                                   NOT NULL VARCHAR2(25)
 EMAIL                                       NOT NULL VARCHAR2(25)
 PHONE_NUMBER                                         VARCHAR2(20)
 HIRE_DATE                                   NOT NULL DATE
 JOB_ID                                      NOT NULL VARCHAR2(10)
 SALARY                                               NUMBER(8,2)
 COMMISSION_PCT                                       NUMBER(2,2)
 MANAGER_ID                                           NUMBER(6)
 DEPARTMENT_ID                                        NUMBER(4)
SQL>
SQL>
Columnas Virtuales
 1 insert into employees(employee_id, first_name, last_name, email, hire_date, job_id)
 2* values (&empleado_id, '&nombre', '&apellido', '&email', to_date('&nacimiento','dd-mm-yyyy'),
&id_empleado)
SQL> /
Enter value for empleado_id: 1
Enter value for nombre: Ronald
Enter value for apellido: Vargas
Enter value for email: rvargas@laboratorio.com
Enter value for nacimiento: 03-09-1968
Enter value for id_empleado: 10
old 2: values (&empleado_id, '&nombre', '&apellido', '&email', to_date('&nacimiento','dd-mm-yyyy'),
&id_empleado)
new 2: values (1, 'Ronald', 'Vargas', 'rvargas@laboratorio.com', to_date('03-09-1968','dd-mm-yyyy'), 10)

1 row created.

SQL> commit;
Columnas Virtuales

SQL> select * from employees;

EMPLOYEE_ID FIRST_NAME                             LAST_NAME
----------- -------------------- -------------------------
EMAIL                      PHONE_NUMBER                     HIRE_DATE JOB_ID     SALARY
------------------------- -------------------- --------- ---------- ----------
COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
-------------- ---------- -------------
        1 Ronald                 Vargas
rvargas@laboratorio.com                                 03-SEP-68 10
Columnas Virtuales
SQL> update employees set salary=200000;
1 row updated.
SQL> commit;
Commit complete.

SQL> select * from employees;
EMPLOYEE_ID FIRST_NAME           LAST_NAME
----------- -------------------- -------------------------
EMAIL                     PHONE_NUMBER         HIRE_DATE JOB_ID         SALARY
------------------------- -------------------- --------- ---------- ----------
COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
-------------- ---------- -------------
          1 Ronald               Vargas
rvargas@laboratorio.com                          03-SEP-68 10             200000
Columnas Virtuales
SQL> alter table employees add IMPUESTO_RENTA as (nvl(salary,0)*0.10);
Table altered.
SQL> desc employees
 Name                                        Null?    Type
 -----------------------------------------   -------- ----------------------------
 EMPLOYEE_ID                                          NUMBER(6)
 FIRST_NAME                                           VARCHAR2(20)
 LAST_NAME                                   NOT NULL VARCHAR2(25)
 EMAIL                                       NOT NULL VARCHAR2(25)
 PHONE_NUMBER                                         VARCHAR2(20)
 HIRE_DATE                                   NOT NULL DATE
 JOB_ID                                      NOT NULL VARCHAR2(10)
 SALARY                                               NUMBER(8,2)
 COMMISSION_PCT                                       NUMBER(2,2)
 MANAGER_ID                                           NUMBER(6)
 DEPARTMENT_ID                                        NUMBER(4)
 IMPUESTO_RENTA                                       NUMBER
Columnas Virtuales

SQL> set linesize 200

SQL> select employee_id, first_name, last_name, salary,
impuesto_renta from employees;

EMPLOYEE_ID FIRST_NAME           LAST_NAME                     SALARY IMPUESTO_RENTA
----------- -------------------- ------------------------- ---------- --------------
          1 Ronald               Vargas                        200000          20000



SQL> update employees set salary=400000 where employee_id=1;
1 row updated.
SQL> commit;
Commit complete.
Columnas Virtuales

 SQL> select employee_id, first_name, last_name, salary, impuesto_renta
 from employees;

 EMPLOYEE_ID FIRST_NAME           LAST_NAME                     SALARY IMPUESTO_RENTA
 ----------- -------------------- ------------------------- ---------- --------------
           1 Ronald               Vargas                        400000          40000
 SQL>
Columnas Virtuales
SQL> alter table employees add email_sugerido as (substr(first_name,1,1)||'.'||
last_name||'@'||'laboratorio.com');

Table altered.
SQL> /
FIRST_NAME           LAST_NAME                     SALARY IMPUESTO_RENTA EMAIL_SUGERIDO
-------------------- ------------------------- ---------- --------------
-----------------------------
Ronald               Vargas                        400000          40000 R.Vargas@laboratorio.com


SQL> update employees set first_name='Manuel' where
impuesto_renta=40000;

1 row updated.
SQL> commit;
Commit complete.
Columnas Virtuales
SQL> select first_name, last_name, salary, impuesto_renta, email_sugerido from
employees;

FIRST_NAME           LAST_NAME                     SALARY IMPUESTO_RENTA EMAIL_SUGERIDO
-------------------- ------------------------- ---------- -------------- --------------------------
Manuel               Vargas                        400000          40000 M.Vargas@laboratorio.com
SQL> desc employees
 Name                                         Null?    Type
 -----------------------------------------    -------- ----------------------------
 EMPLOYEE_ID                                           NUMBER(6)
 FIRST_NAME                                            VARCHAR2(20)
 LAST_NAME                                    NOT NULL VARCHAR2(25)
 EMAIL                                        NOT NULL VARCHAR2(25)
 PHONE_NUMBER                                          VARCHAR2(20)
 HIRE_DATE                                    NOT NULL DATE
 JOB_ID                                       NOT NULL VARCHAR2(10)
 SALARY                                                NUMBER(8,2)
 COMMISSION_PCT                                        NUMBER(2,2)
 MANAGER_ID                                            NUMBER(6)
 DEPARTMENT_ID                                         NUMBER(4)
 IMPUESTO_RENTA                                        NUMBER
 EMAIL_SUGERIDO                                        VARCHAR2(41)
Crear un dblink sin tocar el tnsnames
system@TEST11> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0               Production
TNS for Linux: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production

5 rows selected.

system@TEST11> select * from dba_db_links;

no rows selected
Crear un dblink sin tocar el tnsnames
system@TEST1

1> create database link testlink_db2
2 connect to system identified by oracle
3 using
4 '(DESCRIPTION=
5 (ADDRESS=
6 (PROTOCOL=TCP)
7 (HOST=10.2.10.18)
8 (PORT=1525))
9 (CONNECT_DATA=
10 (SID=test10)))'
11 /

Database link created.
Crear un dblink sin tocar el tnsnames
system@TEST11> select * from v$version@testlink_db2;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0               Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production

5 rows selected.

-- cleanout
system@TEST11> drop database link testlink_db2;
Database link dropped.

Contenu connexe

Tendances

Dbms plan - A swiss army knife for performance engineers
Dbms plan - A swiss army knife for performance engineersDbms plan - A swiss army knife for performance engineers
Dbms plan - A swiss army knife for performance engineersRiyaj Shamsudeen
 
Database Management System
Database Management SystemDatabase Management System
Database Management SystemHitesh Mohapatra
 
Performance tuning a quick intoduction
Performance tuning   a quick intoductionPerformance tuning   a quick intoduction
Performance tuning a quick intoductionRiyaj Shamsudeen
 
Developer's Approach to Code Management
Developer's Approach to Code ManagementDeveloper's Approach to Code Management
Developer's Approach to Code ManagementMichael Rosenblum
 
Debunking myths about_redo_ppt
Debunking myths about_redo_pptDebunking myths about_redo_ppt
Debunking myths about_redo_pptRiyaj Shamsudeen
 
Connor McDonald 11g for developers
Connor McDonald 11g for developersConnor McDonald 11g for developers
Connor McDonald 11g for developersInSync Conference
 
Meg bernal insight2014 4219
Meg bernal insight2014 4219Meg bernal insight2014 4219
Meg bernal insight2014 4219Peter Schouboe
 
Demystifying cost based optimization
Demystifying cost based optimizationDemystifying cost based optimization
Demystifying cost based optimizationRiyaj Shamsudeen
 
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...Rainer Schuettengruber
 
pstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle databasepstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle databaseRiyaj Shamsudeen
 
Oracle ERP Personalization for control master items list
Oracle ERP Personalization for control master items listOracle ERP Personalization for control master items list
Oracle ERP Personalization for control master items listAhmed Elshayeb
 
Connor McDonald Partitioning
Connor McDonald PartitioningConnor McDonald Partitioning
Connor McDonald PartitioningInSync Conference
 
Writing MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScriptWriting MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScriptRoland Bouman
 
Using SQL to process hierarchies
Using SQL to process hierarchiesUsing SQL to process hierarchies
Using SQL to process hierarchiesConnor McDonald
 
SQL Plan Directives explained
SQL Plan Directives explainedSQL Plan Directives explained
SQL Plan Directives explainedMauro Pagano
 
The Hidden Face of Cost-Based Optimizer: PL/SQL Specific Statistics
The Hidden Face of Cost-Based Optimizer: PL/SQL Specific StatisticsThe Hidden Face of Cost-Based Optimizer: PL/SQL Specific Statistics
The Hidden Face of Cost-Based Optimizer: PL/SQL Specific StatisticsMichael Rosenblum
 

Tendances (20)

Dbms plan - A swiss army knife for performance engineers
Dbms plan - A swiss army knife for performance engineersDbms plan - A swiss army knife for performance engineers
Dbms plan - A swiss army knife for performance engineers
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Performance tuning a quick intoduction
Performance tuning   a quick intoductionPerformance tuning   a quick intoduction
Performance tuning a quick intoduction
 
Developer's Approach to Code Management
Developer's Approach to Code ManagementDeveloper's Approach to Code Management
Developer's Approach to Code Management
 
Debunking myths about_redo_ppt
Debunking myths about_redo_pptDebunking myths about_redo_ppt
Debunking myths about_redo_ppt
 
Connor McDonald 11g for developers
Connor McDonald 11g for developersConnor McDonald 11g for developers
Connor McDonald 11g for developers
 
Sql2
Sql2Sql2
Sql2
 
PHP tips by a MYSQL DBA
PHP tips by a MYSQL DBAPHP tips by a MYSQL DBA
PHP tips by a MYSQL DBA
 
Meg bernal insight2014 4219
Meg bernal insight2014 4219Meg bernal insight2014 4219
Meg bernal insight2014 4219
 
Demystifying cost based optimization
Demystifying cost based optimizationDemystifying cost based optimization
Demystifying cost based optimization
 
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
 
pstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle databasepstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle database
 
Oracle ERP Personalization for control master items list
Oracle ERP Personalization for control master items listOracle ERP Personalization for control master items list
Oracle ERP Personalization for control master items list
 
Sql 3
Sql 3Sql 3
Sql 3
 
Connor McDonald Partitioning
Connor McDonald PartitioningConnor McDonald Partitioning
Connor McDonald Partitioning
 
Writing MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScriptWriting MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScript
 
Using SQL to process hierarchies
Using SQL to process hierarchiesUsing SQL to process hierarchies
Using SQL to process hierarchies
 
SQL Plan Directives explained
SQL Plan Directives explainedSQL Plan Directives explained
SQL Plan Directives explained
 
The Hidden Face of Cost-Based Optimizer: PL/SQL Specific Statistics
The Hidden Face of Cost-Based Optimizer: PL/SQL Specific StatisticsThe Hidden Face of Cost-Based Optimizer: PL/SQL Specific Statistics
The Hidden Face of Cost-Based Optimizer: PL/SQL Specific Statistics
 
Pro PostgreSQL
Pro PostgreSQLPro PostgreSQL
Pro PostgreSQL
 

En vedette (7)

Oracle - SQL-PL/SQL context switching
Oracle - SQL-PL/SQL context switchingOracle - SQL-PL/SQL context switching
Oracle - SQL-PL/SQL context switching
 
Oracle SQL, PL/SQL Performance tuning
Oracle SQL, PL/SQL Performance tuningOracle SQL, PL/SQL Performance tuning
Oracle SQL, PL/SQL Performance tuning
 
Oracle query optimizer
Oracle query optimizerOracle query optimizer
Oracle query optimizer
 
Oracle PL/SQL exception handling
Oracle PL/SQL exception handlingOracle PL/SQL exception handling
Oracle PL/SQL exception handling
 
Oracle Complete Interview Questions
Oracle Complete Interview QuestionsOracle Complete Interview Questions
Oracle Complete Interview Questions
 
Sql queries interview questions
Sql queries interview questionsSql queries interview questions
Sql queries interview questions
 
Oracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practicesOracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practices
 

Similaire à Oracle 11g caracteristicas poco documentadas 3 en 1

Managing Statistics for Optimal Query Performance
Managing Statistics for Optimal Query PerformanceManaging Statistics for Optimal Query Performance
Managing Statistics for Optimal Query PerformanceKaren Morton
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleGuatemala User Group
 
Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Hemant K Chitale
 
Writing efficient sql
Writing efficient sqlWriting efficient sql
Writing efficient sqlj9soto
 
EvolveExecutionPlans.pdf
EvolveExecutionPlans.pdfEvolveExecutionPlans.pdf
EvolveExecutionPlans.pdfPraveenPolu1
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?Andrej Pashchenko
 
All on Adaptive and Extended Cursor Sharing
All on Adaptive and Extended Cursor SharingAll on Adaptive and Extended Cursor Sharing
All on Adaptive and Extended Cursor SharingMohamed Houri
 
12c SQL Plan Directives
12c SQL Plan Directives12c SQL Plan Directives
12c SQL Plan DirectivesFranck Pachot
 
Exadata - Smart Scan Testing
Exadata - Smart Scan TestingExadata - Smart Scan Testing
Exadata - Smart Scan TestingMonowar Mukul
 
Informix Warehouse Accelerator (IWA) features in version 12.1
Informix Warehouse Accelerator (IWA) features in version 12.1Informix Warehouse Accelerator (IWA) features in version 12.1
Informix Warehouse Accelerator (IWA) features in version 12.1Keshav Murthy
 
Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...
Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...
Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...Informatik Aktuell
 
Oracle dbms_xplan.display_cursor format
Oracle dbms_xplan.display_cursor formatOracle dbms_xplan.display_cursor format
Oracle dbms_xplan.display_cursor formatFranck Pachot
 
了解IO协议栈
了解IO协议栈了解IO协议栈
了解IO协议栈Feng Yu
 
Io 120404052713-phpapp01
Io 120404052713-phpapp01Io 120404052713-phpapp01
Io 120404052713-phpapp01coxchen
 
Sydney Oracle Meetup - access paths
Sydney Oracle Meetup - access pathsSydney Oracle Meetup - access paths
Sydney Oracle Meetup - access pathspaulguerin
 

Similaire à Oracle 11g caracteristicas poco documentadas 3 en 1 (20)

Managing Statistics for Optimal Query Performance
Managing Statistics for Optimal Query PerformanceManaging Statistics for Optimal Query Performance
Managing Statistics for Optimal Query Performance
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
 
Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)
 
Writing efficient sql
Writing efficient sqlWriting efficient sql
Writing efficient sql
 
EvolveExecutionPlans.pdf
EvolveExecutionPlans.pdfEvolveExecutionPlans.pdf
EvolveExecutionPlans.pdf
 
Oracle 12c SPM
Oracle 12c SPMOracle 12c SPM
Oracle 12c SPM
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 
Do You Know The 11g Plan?
Do You Know The 11g Plan?Do You Know The 11g Plan?
Do You Know The 11g Plan?
 
All on Adaptive and Extended Cursor Sharing
All on Adaptive and Extended Cursor SharingAll on Adaptive and Extended Cursor Sharing
All on Adaptive and Extended Cursor Sharing
 
SQLQueries
SQLQueriesSQLQueries
SQLQueries
 
12c SQL Plan Directives
12c SQL Plan Directives12c SQL Plan Directives
12c SQL Plan Directives
 
PoC Oracle Exadata - Retour d'expérience
PoC Oracle Exadata - Retour d'expériencePoC Oracle Exadata - Retour d'expérience
PoC Oracle Exadata - Retour d'expérience
 
Sql queries
Sql queriesSql queries
Sql queries
 
Exadata - Smart Scan Testing
Exadata - Smart Scan TestingExadata - Smart Scan Testing
Exadata - Smart Scan Testing
 
Informix Warehouse Accelerator (IWA) features in version 12.1
Informix Warehouse Accelerator (IWA) features in version 12.1Informix Warehouse Accelerator (IWA) features in version 12.1
Informix Warehouse Accelerator (IWA) features in version 12.1
 
Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...
Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...
Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...
 
Oracle dbms_xplan.display_cursor format
Oracle dbms_xplan.display_cursor formatOracle dbms_xplan.display_cursor format
Oracle dbms_xplan.display_cursor format
 
了解IO协议栈
了解IO协议栈了解IO协议栈
了解IO协议栈
 
Io 120404052713-phpapp01
Io 120404052713-phpapp01Io 120404052713-phpapp01
Io 120404052713-phpapp01
 
Sydney Oracle Meetup - access paths
Sydney Oracle Meetup - access pathsSydney Oracle Meetup - access paths
Sydney Oracle Meetup - access paths
 

Plus de Ronald 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
 
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
 
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 Performance Tuning how to write and run correctly sql statement...
Ronald Vargas Performance Tuning how to write and run correctly sql statement...Ronald Vargas Performance Tuning how to write and run correctly sql statement...
Ronald Vargas Performance Tuning how to write and run correctly sql statement...Ronald 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
 
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
 
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 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
 
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
 
Performance tuning how to write and run correctly sql statement
Performance tuning how to write and run correctly sql statementPerformance tuning how to write and run correctly sql statement
Performance tuning how to write and run correctly sql statementRonald 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
 

Plus de Ronald Francisco Vargas Quesada (20)

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
 
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
 
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 Performance Tuning how to write and run correctly sql statement...
Ronald Vargas Performance Tuning how to write and run correctly sql statement...Ronald Vargas Performance Tuning how to write and run correctly sql statement...
Ronald Vargas Performance Tuning how to write and run correctly sql statement...
 
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 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
 
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 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.
 
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
 
Oracle Database SE2 Single Tenant 12c
Oracle Database SE2 Single Tenant 12cOracle Database SE2 Single Tenant 12c
Oracle Database SE2 Single Tenant 12c
 
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
 
Performance tuning how to write and run correctly sql statement
Performance tuning how to write and run correctly sql statementPerformance tuning how to write and run correctly sql statement
Performance tuning how to write and run correctly sql statement
 
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
 

Oracle 11g caracteristicas poco documentadas 3 en 1

  • 1. Serie Underground Por Ronald Vargas, Oracle ACE Oracledbacr.blogspot.com
  • 2. Indices virtuales @rovaque Oracledbacr.blogspot.com
  • 3. Indices virtuales •  El proceso de afinamiento de instrucciones SQL, requiere que de manera alterna, podamos definir estrategias de indexación, para observar su efecto en los planes de ejecución. •  Crear índices adicionales, no es el problema.
  • 4. Indices virtuales •  El problema es, que crear índices extras sobre tablas grandes, puede tomar un monto considerado de tiempo y espacio en disco. •  Adicionalmente, los índices creados pueden ser utilizados por otras sesiones de usuarios y podría afectar el rendimiento en otras partes de la aplicación. •  Esto puede ser problemático cuando estamos intentando identificar el problema en un sistema en producción.
  • 5. Indices virtuales –  En contraste a los índices convencionales, los índices virtuales no están asociados a un segmento, el tiempo de creación y el espacio asociado en disco es irrelevante. –  Adicionalmente, no pueden ser vistos por otras sesiones, por tanto, no se ve afectado el normal funcionamiento del sistema. –  Este clase muestra de manera sencilla como utilizarlos y las consideraciones que debemos tener en cuenta.
  • 6. Indices virtuales SQL> desc movto_h Name Null? Type ----------------------------------------- -------- -------------- NO_CIA NOT NULL VARCHAR2(2) CENTRO NOT NULL VARCHAR2(2) TIPO_DOC NOT NULL VARCHAR2(2) PERIODO NOT NULL VARCHAR2(4) RUTA NOT NULL VARCHAR2(4) NO_DOCU NOT NULL VARCHAR2(12) FECHA NOT NULL DATE NO_FISICO VARCHAR2(12) SERIE_FISICO VARCHAR2(15) ... FECHA_APLICACION DATE TSTAMP DATE NO_TRASLADO VARCHAR2(12)
  • 7. Indices virtuales SQL> select count(*) from movto_h; COUNT(*) ---------- 6445961
  • 8. Indices virtuales SQL> create index v_movto_h_nofisico on movto_h(no_fisico) nosegment; Index created. SQL> explain plan for 2 select count(distinct no_fisico) from movto_h; Explained.
  • 9. Indices virtuales SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------ Plan hash value: 891170817 ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 7 | 21381 (3)| 00:04:17 | | 1 | SORT GROUP BY | | 1 | 7 | | | | 2 | TABLE ACCESS FULL| movto_h | 6445K| 43M| 21381 (3)| 00:04:17 | ------------------------------------------------------------------------------ 9 rows selected.
  • 10. Indices virtuales SQL> explain plan for 2 select count(distinct no_fisico) from movto_h where no_fisico < 10000; Explained. SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ----------------------------------------------------------------------------------- Plan hash value: 891170817 ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 7 | 21547 (3)| 00:04:19 | | 1 | SORT GROUP BY | | 1 | 7 | | | |* 2 | TABLE ACCESS FULL| movto_h | 322K| 2203K| 21547 (3)| 00:04:19 | ------------------------------------------------------------------------------ Predicate Information (identified by operation id): PLAN_TABLE_OUTPUT
  • 11. Indices virtuales SQL> create index v_movto_h_nofisico2 on movto_h(to_number(no_fisico)) nosegment; Index created. SQL> explain plan for 2 select count(distinct no_fisico) from movto_h where no_fisico < 10000; Explained.
  • 12. Indices virtuales SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------- Plan hash value: 891170817 ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 7 | 21547 (3)| 00:04:19 | | 1 | SORT GROUP BY | | 1 | 7 | | | |* 2 | TABLE ACCESS FULL| movto_h | 322K| 2203K| 21547 (3)| 00:04:19 | ------------------------------------------------------------------------------ Predicate Information (identified by operation id): PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------- 2 - filter(TO_NUMBER("NO_FISICO")<10000) 14 rows selected.
  • 13. Indices virtuales SQL> SQL> alter session set "_use_nosegment_indexes"=TRUE; Session altered. SQL> explain plan for 2 select count(distinct no_fisico) from movto_h where no_fisico < 10000; Explained.
  • 14. Indices virtuales SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------------------- Plan hash value: 2481667387 -------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 7 | 7 (0)| 00:00:01 | | 1 | SORT GROUP BY | | 1 | 7 | | | |* 2 | INDEX FAST FULL SCAN| V_movto_h_NOFISICO | 322K| 2203K| 7 (0)| 00:00:01 | -------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------------------- 2 - filter(TO_NUMBER("NO_FISICO")<10000) 14 rows selected.
  • 15. Indices virtuales SQL> SELECT index_owner, index_name 2 FROM dba_ind_columns 3 WHERE index_name NOT LIKE 'BIN$%' 4 MINUS 5 SELECT owner, index_name 6 FROM dba_indexes; INDEX_OWNER INDEX_NAME ------------------------------ ------------------------------ PRUEBAS21 V_movto_h_NOFISICO PRUEBAS21 V_movto_h_NOFISICO2 PRUEBAS21 V_ARINMN
  • 16. Indices virtuales SQL> drop index v_movto_h_nofisico; Index dropped. SQL> explain plan for 2 select count(distinct no_fisico) from movto_h where no_fisico < 10000; Explained.
  • 17. Indices virtuales SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------- Plan hash value: 11771441 -------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 7 | 10 (0)| 00:00:01 | | 1 | SORT GROUP BY | | 1 | 7 | | | | 2 | TABLE ACCESS BY INDEX ROWID| movto_h | 322K| 2203K| 10 (0)| 00:00:01 | |* 3 | INDEX RANGE SCAN | V_movto_h_NOFISICO2 | 58014 | | 2 (0)| 00:00:01 | -------------------------------------------------------------------------------------- PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 3 - access(TO_NUMBER("NO_FISICO")<10000) 15 rows selected.
  • 18. Indices virtuales SQL> select count(*) from movto_h; COUNT(*) ---------- 6445961 drop index v_movto_h_nofisico2; create index v_movto_h_nofisico2 on movto_h(to_number(no_fisico)) nosegment; drop index v_movto_h_nofisico2; create index v_movto_h_nofisico2 on movto_h(to_number(no_fisico)); SQL> drop index v_movto_h_nofisico2; Index dropped.
  • 19. Indices virtuales SQL> SQL> set timing on; SQL> SQL> create index v_movto_h_nofisico2 on movto_h(to_number(no_fisico)) nosegment; Index created. Elapsed: 00:00:00.03 SQL> drop index v_movto_h_nofisico2; Index dropped. Elapsed: 00:00:00.02
  • 20. Indices virtuales SQL> create index v_movto_h_nofisico2 on movto_h(to_number(no_fisico)); Index created. Elapsed: 00:01:09.56 SQL> explain plan for 2 select count(distinct no_fisico) from movto_h where no_fisico < 10000; Explained. Elapsed: 00:00:00.01
  • 21. Indices virtuales SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ----------------------------------------------------------------------------------- Plan hash value: 891170817 ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 7 | 21547 (3)| 00:04:19 | | 1 | SORT GROUP BY | | 1 | 7 | | | |* 2 | TABLE ACCESS FULL| movto_h | 322K| 2203K| 21547 (3)| 00:04:19 | ------------------------------------------------------------------------------ Predicate Information (identified by operation id): PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------ 2 - filter(TO_NUMBER("NO_FISICO")<10000) 14 rows selected.
  • 22. Indices virtuales SQL> alter session set "_use_nosegment_indexes"=FALSE; Session altered. Elapsed: 00:00:00.01 SQL> explain plan for 2 select count(distinct no_fisico) from movto_h where no_fisico < 10000; Explained. Elapsed: 00:00:00.01 SQL> select * from table(dbms_xplan.display);
  • 23. Indices virtuales PLAN_TABLE_OUTPUT ----------------------------------------------------------------------------------- Plan hash value: 891170817 ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 7 | 21547 (3)| 00:04:19 | | 1 | SORT GROUP BY | | 1 | 7 | | | |* 2 | TABLE ACCESS FULL| movto_h | 322K| 2203K| 21547 (3)| 00:04:19 | ------------------------------------------------------------------------------ Predicate Information (identified by operation id): PLAN_TABLE_OUTPUT ----------------------------------------------------------------------------------- 2 - filter(TO_NUMBER("NO_FISICO")<10000) 14 rows selected.
  • 25. Indices virtuales Calculando estadísticas al índice virtual SQL> drop index V_movto_h_NOFISICO2; Index dropped. SQL> create index v_movto_h_nofisico2 on MOVTO_H(to_number(no_fisico)) nosegment; Index created. SQL> execute dbms_stats.gather_index_stats('PRUEBAS21','V_MOVTO_H_NOFISICO2'); PL/SQL procedure successfully completed.
  • 26. Indices virtuales SQL> alter session set "_use_nosegment_indexes"=TRUE; Session altered. SQL> explain plan for 2 select count(distinct no_fisico) from MOVTO_H where no_fisico < 10000; Explained. SQL> set linesize 1000 SQL> select * from table(dbms_xplan.display);
  • 27. Indices virtuales PLAN_TABLE_OUTPUT ----------------------------------------------------------------------------------------------------- Plan hash value: 1788350122 ---------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 7 | 30 (0)| 00:00:01 | | 1 | SORT GROUP BY | | 1 | 7 | | | | 2 | TABLE ACCESS BY INDEX ROWID| MOVTO_H | 218K| 1495K| 30 (0)| 00:00:01 | |* 3 | INDEX RANGE SCAN | V_MOVTO_H_NOFISICO2 | 218K| | 2 (0)| 00:00:01 | ---------------------------------------------------------------------------------------------------- PLAN_TABLE_OUTPUT ----------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 3 - access(TO_NUMBER("NO_FISICO")<10000)
  • 28. Indices virtuales El optimizador de Oracle 10g y superiores trabaja basado en optimización por COSTO. RBO no esta soportado en Oracle11g
  • 29.
  • 30. Columnas Virtuales Columnas Virtuales Fórmula / columnas calculadas - sobre la base de datos Restricciones adicionales - sobre la base de datos Nueva categoría para la partición - sobre la base de datos Integridad creativa de referencia - en la base de datos Sin columnas virtuales- inconvenientes Triggers - caros Vistas- a veces se olvidan Re-diseño – Mucho trabajo duro!
  • 31. Columnas Virtuales SQL> show user USER is "DEMO_LAB" SQL> desc employees Name Null? Type ----------------------------------------- -------- ---------------------------- EMPLOYEE_ID NUMBER(6) FIRST_NAME VARCHAR2(20) LAST_NAME NOT NULL VARCHAR2(25) EMAIL NOT NULL VARCHAR2(25) PHONE_NUMBER VARCHAR2(20) HIRE_DATE NOT NULL DATE JOB_ID NOT NULL VARCHAR2(10) SALARY NUMBER(8,2) COMMISSION_PCT NUMBER(2,2) MANAGER_ID NUMBER(6) DEPARTMENT_ID NUMBER(4) SQL> SQL>
  • 32. Columnas Virtuales 1 insert into employees(employee_id, first_name, last_name, email, hire_date, job_id) 2* values (&empleado_id, '&nombre', '&apellido', '&email', to_date('&nacimiento','dd-mm-yyyy'), &id_empleado) SQL> / Enter value for empleado_id: 1 Enter value for nombre: Ronald Enter value for apellido: Vargas Enter value for email: rvargas@laboratorio.com Enter value for nacimiento: 03-09-1968 Enter value for id_empleado: 10 old 2: values (&empleado_id, '&nombre', '&apellido', '&email', to_date('&nacimiento','dd-mm-yyyy'), &id_empleado) new 2: values (1, 'Ronald', 'Vargas', 'rvargas@laboratorio.com', to_date('03-09-1968','dd-mm-yyyy'), 10) 1 row created. SQL> commit;
  • 33. Columnas Virtuales SQL> select * from employees; EMPLOYEE_ID FIRST_NAME LAST_NAME ----------- -------------------- ------------------------- EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY ------------------------- -------------------- --------- ---------- ---------- COMMISSION_PCT MANAGER_ID DEPARTMENT_ID -------------- ---------- ------------- 1 Ronald Vargas rvargas@laboratorio.com 03-SEP-68 10
  • 34. Columnas Virtuales SQL> update employees set salary=200000; 1 row updated. SQL> commit; Commit complete. SQL> select * from employees; EMPLOYEE_ID FIRST_NAME LAST_NAME ----------- -------------------- ------------------------- EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY ------------------------- -------------------- --------- ---------- ---------- COMMISSION_PCT MANAGER_ID DEPARTMENT_ID -------------- ---------- ------------- 1 Ronald Vargas rvargas@laboratorio.com 03-SEP-68 10 200000
  • 35. Columnas Virtuales SQL> alter table employees add IMPUESTO_RENTA as (nvl(salary,0)*0.10); Table altered. SQL> desc employees Name Null? Type ----------------------------------------- -------- ---------------------------- EMPLOYEE_ID NUMBER(6) FIRST_NAME VARCHAR2(20) LAST_NAME NOT NULL VARCHAR2(25) EMAIL NOT NULL VARCHAR2(25) PHONE_NUMBER VARCHAR2(20) HIRE_DATE NOT NULL DATE JOB_ID NOT NULL VARCHAR2(10) SALARY NUMBER(8,2) COMMISSION_PCT NUMBER(2,2) MANAGER_ID NUMBER(6) DEPARTMENT_ID NUMBER(4) IMPUESTO_RENTA NUMBER
  • 36. Columnas Virtuales SQL> set linesize 200 SQL> select employee_id, first_name, last_name, salary, impuesto_renta from employees; EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY IMPUESTO_RENTA ----------- -------------------- ------------------------- ---------- -------------- 1 Ronald Vargas 200000 20000 SQL> update employees set salary=400000 where employee_id=1; 1 row updated. SQL> commit; Commit complete.
  • 37. Columnas Virtuales SQL> select employee_id, first_name, last_name, salary, impuesto_renta from employees; EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY IMPUESTO_RENTA ----------- -------------------- ------------------------- ---------- -------------- 1 Ronald Vargas 400000 40000 SQL>
  • 38. Columnas Virtuales SQL> alter table employees add email_sugerido as (substr(first_name,1,1)||'.'|| last_name||'@'||'laboratorio.com'); Table altered. SQL> / FIRST_NAME LAST_NAME SALARY IMPUESTO_RENTA EMAIL_SUGERIDO -------------------- ------------------------- ---------- -------------- ----------------------------- Ronald Vargas 400000 40000 R.Vargas@laboratorio.com SQL> update employees set first_name='Manuel' where impuesto_renta=40000; 1 row updated. SQL> commit; Commit complete.
  • 39. Columnas Virtuales SQL> select first_name, last_name, salary, impuesto_renta, email_sugerido from employees; FIRST_NAME LAST_NAME SALARY IMPUESTO_RENTA EMAIL_SUGERIDO -------------------- ------------------------- ---------- -------------- -------------------------- Manuel Vargas 400000 40000 M.Vargas@laboratorio.com SQL> desc employees Name Null? Type ----------------------------------------- -------- ---------------------------- EMPLOYEE_ID NUMBER(6) FIRST_NAME VARCHAR2(20) LAST_NAME NOT NULL VARCHAR2(25) EMAIL NOT NULL VARCHAR2(25) PHONE_NUMBER VARCHAR2(20) HIRE_DATE NOT NULL DATE JOB_ID NOT NULL VARCHAR2(10) SALARY NUMBER(8,2) COMMISSION_PCT NUMBER(2,2) MANAGER_ID NUMBER(6) DEPARTMENT_ID NUMBER(4) IMPUESTO_RENTA NUMBER EMAIL_SUGERIDO VARCHAR2(41)
  • 40.
  • 41. Crear un dblink sin tocar el tnsnames system@TEST11> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production PL/SQL Release 11.1.0.7.0 - Production CORE 11.1.0.7.0 Production TNS for Linux: Version 11.1.0.7.0 - Production NLSRTL Version 11.1.0.7.0 - Production 5 rows selected. system@TEST11> select * from dba_db_links; no rows selected
  • 42. Crear un dblink sin tocar el tnsnames system@TEST1 1> create database link testlink_db2 2 connect to system identified by oracle 3 using 4 '(DESCRIPTION= 5 (ADDRESS= 6 (PROTOCOL=TCP) 7 (HOST=10.2.10.18) 8 (PORT=1525)) 9 (CONNECT_DATA= 10 (SID=test10)))' 11 / Database link created.
  • 43. Crear un dblink sin tocar el tnsnames system@TEST11> select * from v$version@testlink_db2; BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod PL/SQL Release 10.2.0.4.0 - Production CORE 10.2.0.4.0 Production TNS for Linux: Version 10.2.0.4.0 - Production NLSRTL Version 10.2.0.4.0 - Production 5 rows selected. -- cleanout system@TEST11> drop database link testlink_db2; Database link dropped.