Comprobar el plan de ejecución con el que se ha compilado una sentencia sql que ya se ha ejecutado, obteniendo los datos de la SHARED POOL (v$sql).
En V$SQL puedo ver las sentencias sql que ya se han ejecutado, de modo que puedo obtener el identificador (V$SQL.SQL_ID) de cualquier sentencia sql, para posteriormente consultar el plan de ejecución haciendo uso del paquete dbms_xplan (DBMS_XPLAN.DISPLAY_CURSOR(SQL_ID)).
SQL> connect system/fabiancrea
Enter password:
Connected.
SQL> select deptno,count(*) from scott.emp group by deptno;
DEPTNO COUNT(*)
30 6
20 5
10 3
SQL> select sql_id from v$sql where sql_text='select deptno,count(*) from scott.emp group by deptno';
SQL_ID
cxwqkgckrcpd8
SQL> select * from table(dbms_xplan.display_cursor('cxwqkgckrcpd8'));
PLAN_TABLE_OUTPUT
SQL_ID cxwqkgckrcpd8, child number 0
select deptno,count(*) from scott.emp group by deptno
Plan hash value: 4067220884
----------------------------------------------------------------------
|Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 7 (100)| |
| 1 | HASH GROUP BY | | 3 | 9 | 7 (15)| 00:00:01 |
| 2 | TABLE ACCESS FULL| EMP | 14 | 42 | 6 (0)| 00:00:01 |
----------------------------------------------------------------------
14
filas seleccionadas.
SQL> connect system/fabiancrea
Enter password:
Connected.
SQL> select deptno,count(*) from scott.emp group by deptno;
DEPTNO COUNT(*)
30 6
20 5
10 3
SQL> select sql_id from v$sql where sql_text='select deptno,count(*) from scott.emp group by deptno';
SQL_ID
cxwqkgckrcpd8
SQL> select * from table(dbms_xplan.display_cursor('cxwqkgckrcpd8'));
PLAN_TABLE_OUTPUT
SQL_ID cxwqkgckrcpd8, child number 0
select deptno,count(*) from scott.emp group by deptno
Plan hash value: 4067220884
----------------------------------------------------------------------
|Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 7 (100)| |
| 1 | HASH GROUP BY | | 3 | 9 | 7 (15)| 00:00:01 |
| 2 | TABLE ACCESS FULL| EMP | 14 | 42 | 6 (0)| 00:00:01 |
----------------------------------------------------------------------
14
filas seleccionadas.
Comentarios