Professional Documents
Culture Documents
Pag 160 - Tablas y Otros Segmentos de Datos
Pag 160 - Tablas y Otros Segmentos de Datos
Pag 160 - Tablas y Otros Segmentos de Datos
2 (id number,
3 valor varchar2(50),
4 valor2 varchar2(1000));
Tabla creada.
SQL> begin
2 for x in 1..1000
3 loop
4 insert into test_migracion values (x,'VALOR',NULL);
5 end loop;
6 end;
7 /
SQL> commit;
Confirmaci�n terminada.
DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) COUNT(*)
------------------------------------ ----------
80125 491
80126 484
80127 25
SQL> select DBMS_ROWID.ROWID_BLOCK_NUMBER(rowid), count(*)
2 from test_migracion
3 where id<=10
4 group by DBMS_ROWID.ROWID_BLOCK_NUMBER(rowid);
DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) COUNT(*)
------------------------------------ ----------
80125 10
SQL> declare
2 texto varchar2(1000);
3 begin
4 for x in 1..100
5 loop
6 texto:=texto||'X';
7 end loop;
8 update test_migracion set valor2=texto where id<=10;
9 end;
10 /
SQL> commit;
Confirmaci�n terminada.
Tabla borrada.
SQL> @?/rdbms/admin/utlchain
Tabla creada.
Tabla analizada.
SQL> select table_name, head_rowid
2 from chained_rows;
TABLE_NAME HEAD_ROWID
------------------------------ ------------------
TEST_MIGRACION AAAXnIAAEAAATj9AAI
TEST_MIGRACION AAAXnIAAEAAATj9AAJ
ID
----------
9
10
ID VALOR VALOR2
---------- ----- ------------------------------------------------------------
1 VALOR XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2 VALOR XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3 VALOR XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4 VALOR XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5 VALOR XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6 VALOR XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7 VALOR XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
8 VALOR XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
11 VALOR
12 VALOR
13 VALOR
14 VALOR
15 VALOR
16 VALOR
17 VALOR
18 VALOR
19 VALOR
20 VALOR
9 VALOR XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
10 VALOR XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
20 filas seleccionadas.
Tabla truncada.
Tabla modificada.
Tabla analizada.
Table created.
Table created.
SQL> select table_name from user_tables;
TABLE_NAME
------------------------------
OBJETOS_ESTANDAR
OBJETOS_IOT
SEGMENT_NAME SEGMENT_TYPE
------------------------- ------------------
OBJETOS_ESTANDAR TABLE
PK_OBJETOS_IOT INDEX --> Este segmento corresponde a la tabla
OBJETOS_IOT
PK_OBJETOS_STD INDEX
Explained.
SQL> @?/rdbms/admin/utlxpls
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
-----
Plan hash value: 3057118431
-----------------------------------------------------------------------------------
-----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
-----------------------------------------------------------------------------------
-----
| 0 | SELECT STATEMENT | | 10492 | 809K| 142 (0)|
00:00:02 |
| 1 | TABLE ACCESS BY INDEX ROWID|OBJETOS_ESTANDAR| 10492 |809K|142 (0)|
00:00:02 |
|* 2 | INDEX RANGE SCAN | PK_OBJETOS_STD | 10492 | | 29 (0)|
00:00:01 |
-----------------------------------------------------------------------------------
-----
Explained.
SQL> @?/rdbms/admin/utlxpls
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
-----
Plan hash value: 2341284110
-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 11063 | 853K| 4 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| PK_OBJETOS_IOT | 11063 | 853K| 4 (0)| 00:00:01 |
-----------------------------------------------------------------------------------
Cluster created.
Index created.
Table created.
SQL> create table linea_factura (
2 id_detalle number primary key,
3 articulo varchar2(50),
4 precio number,
5 unidades number,
6 id_factura number references factura(id_factura))
7 cluster clu_factura(id_factura);
Table created.
SEGMENT_NAME SEGMENT_TYPE
------------------------- ------------------
CLU_FACTURA CLUSTER
PK_FACTURA INDEX
PK_DETALLE INDEX
IDX_CLU_FACTURA INDEX
TABLE_NAME CLUSTER_NAME
------------------------------ ------------------------------
FACTURA CLU_FACTURA
LINEA_FACTURA CLU_FACTURA
SQL> begin
2 for x in 1..10
3 loop
4 insert into factura
5 values (x,'CLIENTE'||to_char(x,'9999'),sysdate);
6 end loop;
7 end;
8 /
SQL> commit;
Commit complete.
SEGMENT_NAME NUM_BLOCKS
------------------------- ----------
PK_DETALLE 8
IDX_CLU_FACTURA 8
CLU_FACTURA 16
PK_FACTURA 8
SQL> begin
2 for x in 11..500
3 loop
4 insert into factura
5 values (x,'CLIENTE'||to_char(x,'9999'),sysdate);
6 end loop;
7 end;
8 /
SQL> commit;
Commit complete.
SEGMENT_NAME NUM_BLOCKS
------------------------- ----------
PK_DETALLE 8
IDX_CLU_FACTURA 8
CLU_FACTURA 640
PK_FACTURA 8
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 1325426376
-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 79 | 170 (0)| 00:00:03 |
| 1 | TABLE ACCESS FULL| LINEA_FACTURA | 1 | 79 | 170 (0)| 00:00:03 |
-----------------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
536 consistent gets
0 physical reads
0 redo size
618 bytes sent via SQL*Net to client
509 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
Execution Plan
----------------------------------------------------------
Plan hash value: 2931952114
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 504 | 24696 | 170 (0)| 00:00:03 |
| 1 | TABLE ACCESS FULL| FACTURA | 504 | 24696 | 170 (0)| 00:00:03 |
-----------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
538 consistent gets
0 physical reads
0 redo size
32252 bytes sent via SQL*Net to client
883 bytes received via SQL*Net from client
35 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
500 rows processed
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> insert into linea_factura values (8,'ART-008',2,11,1);
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
12 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 1409678405
-----------------------------------------------------------------------------------
-----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
-----------------------------------------------------------------------------------
-----
| 0 | SELECT STATEMENT | | 1 | 79 | 1 (0)|
00:00:01 |
| 1 | TABLE ACCESS CLUSTER| LINEA_FACTURA | 1 | 79 | 1 (0)|
00:00:01 |
|* 2 | INDEX UNIQUE SCAN | IDX_CLU_FACTURA | 1 | | 0 (0)|
00:00:01 |
-----------------------------------------------------------------------------------
-----
2 - access("ID_FACTURA"=3)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
922 bytes sent via SQL*Net to client
520 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
3 rows processed
SQL> create cluster clu_libros (isbn number) tablespace users hashkeys 1000000;
Cluster created.
Elapsed: 00:10:43.95
SEGMENT_NAME NUM_BLOCKS
------------------------------ ----------
CLU_LIBROS 1005056
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> commit;
Commit complete.
10 rows selected.
Elapsed: 00:00:00.01
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
1 consistent gets
0 physical reads
0 redo size
751 bytes sent via SQL*Net to client
520 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
Elapsed: 00:01:04.18
Statistics
----------------------------------------------------------
30 recursive calls
0 db block gets
1000109 consistent gets
1000126 physical reads
0 redo size
751 bytes sent via SQL*Net to client
520 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
CN_COMP SUM(IMPORTE)
------------------------------ ------------
Spanair 3386479,12
Air France 1720119,06
British Airways 3454955,5
Alitalia 3415356,57
Iberia 3463249,72
Air Europa 3387305,26
Air Nostrum 3463869,83
KLM 3367617,09
8 filas seleccionadas.
1 fila creada.
SQL> commit;
Confirmaci�n terminada.
CN_COMP SUM(IMPORTE)
------------------------------ ------------
Spanair 3386479,12
British Airways 3454955,5
Air France 1720119,06
Alitalia 3415356,57
Iberia 3463249,72
Air Europa 3387305,26
Air Nostrum 3463869,83
KLM 3368617,09 <-- el total se ha visto incrementado
en
1000 con la nueva reserva.
8 filas seleccionadas.
SQL> @?/rdbms/admin/utlxmv.sql
Tabla creada.
19 filas seleccionadas.
1 fila actualizada.
SQL> commit;
Confirmaci�n terminada.
CN_COMP SUM(IMPORTE)
------------------------------ ------------
KLM 3368617,09 <-- la vista NO se ha refrescado.
SQL> select cn_comp, sum(importe)
2 from companias, vuelos, reservas
3 where companias.id_comp=vuelos.comp_id_comp
4 and vuelos.id_vuelo=reservas.vue_id_vuelo
5 and cn_comp='KLM'
6 group by cn_comp;
CN_COMP SUM(IMPORTE)
------------------------------ ------------
KLM 3370617,09 <-- Las tablas muestran el c�mputo
real,
tras el update.
Tabla truncada.
1 fila suprimida.
SQL> commit;
Confirmaci�n terminada.
8 filas seleccionadas.
Tabla truncada.
SQL> exec dbms_mview.explain_mview('MV_TOTALES_COMPANIA');
8 filas seleccionadas.
SQL> explain plan for
2 select cn_comp, sum(importe)
3 from companias, vuelos, reservas
4 where companias.id_comp=vuelos.comp_id_comp
5 and vuelos.id_vuelo=reservas.vue_id_vuelo
6 and cn_comp='KLM'
7 group by cn_comp;
Explicado.
SQL> @?/rdbms/admin/utlxpls
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
-----
Plan hash value: 1279300060
-----------------------------------------------------------------------------------
-----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
-----------------------------------------------------------------------------------
-----
| 0 | SELECT STATEMENT | | 1 | 30 | 3 (0)|
00:00:01 |
|* 1 | MAT_VIEW REWRITE ACCESS FULL| MV_TOTALES_COMPANIA | 1 |30 | 3 (0)|
00:00:01 |
-----------------------------------------------------------------------------------
-----
1 - filter("MV_TOTALES_COMPANIA"."CN_COMP"='KLM')