Wednesday, December 22, 2004

Moving a Table from one table space to another

ALTER TABLE Table_Name MOVE TABLESPACE Tablespace_Name;

Inline views are nothing but sub queries used as tables. There is no difference in performance in using views that are edxplicitly created and inline views.

Example is given below:

SQL> create view v_emp as select EMPNO , ENAME , JOB , DEPTNO from scott.emp
2 ;

View created.

SQL> set autotrace on
SQL> select EMPNO , ENAME , JOB ,scott.dept.DEPTNO ,DNAME from v_emp ,scott.dept
2 where v_emp.deptno = scott.dept.deptno
3 ;

EMPNO ENAME JOB DEPTNO DNAME
---------- ---------- --------- ---------- --------------
7782 CLARK MANAGER 10 ACCOUNTING
7839 KING PRESIDENT 10 ACCOUNTING
7934 MILLER CLERK 10 ACCOUNTING
7369 SMITH CLERK 20 RESEARCH
7876 ADAMS CLERK 20 RESEARCH
7902 FORD ANALYST 20 RESEARCH
7788 SCOTT ANALYST 20 RESEARCH
7566 JONES MANAGER 20 RESEARCH
7499 ALLEN SALESMAN 30 SALES
7698 BLAKE MANAGER 30 SALES
7654 MARTIN SALESMAN 30 SALES

EMPNO ENAME JOB DEPTNO DNAME
---------- ---------- --------- ---------- --------------
7900 JAMES CLERK 30 SALES
7844 TURNER SALESMAN 30 SALES
7521 WARD SALESMAN 30 SALES

14 rows selected.


Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=14 Bytes=47
6)

1 0 MERGE JOIN (Cost=6 Card=14 Bytes=476)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'DEPT' (TABLE) (Cost=2
Card=4 Bytes=52)

3 2 INDEX (FULL SCAN) OF 'PK_DEPT' (INDEX (UNIQUE)) (Cost=
1 Card=4)

4 1 SORT (JOIN) (Cost=4 Card=14 Bytes=294)
5 4 TABLE ACCESS (FULL) OF 'EMP' (TABLE) (Cost=3 Card=14 B
ytes=294)





Statistics
----------------------------------------------------------
8 recursive calls
0 db block gets
13 consistent gets
0 physical reads
0 redo size
986 bytes sent via SQL*Net to client
508 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
14 rows processed

SQL> select EMPNO , ENAME , JOB ,scott.dept.DEPTNO ,DNAME from (select EMPNO , ENAME , JOB ,deptno FROM scott.emp) iv_emp ,scott.dept
2 where iv_emp.deptno = scott.dept.deptno;

EMPNO ENAME JOB DEPTNO DNAME
---------- ---------- --------- ---------- --------------
7782 CLARK MANAGER 10 ACCOUNTING
7839 KING PRESIDENT 10 ACCOUNTING
7934 MILLER CLERK 10 ACCOUNTING
7369 SMITH CLERK 20 RESEARCH
7876 ADAMS CLERK 20 RESEARCH
7902 FORD ANALYST 20 RESEARCH
7788 SCOTT ANALYST 20 RESEARCH
7566 JONES MANAGER 20 RESEARCH
7499 ALLEN SALESMAN 30 SALES
7698 BLAKE MANAGER 30 SALES
7654 MARTIN SALESMAN 30 SALES

EMPNO ENAME JOB DEPTNO DNAME
---------- ---------- --------- ---------- --------------
7900 JAMES CLERK 30 SALES
7844 TURNER SALESMAN 30 SALES
7521 WARD SALESMAN 30 SALES

14 rows selected.


Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=14 Bytes=47
6)

1 0 MERGE JOIN (Cost=6 Card=14 Bytes=476)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'DEPT' (TABLE) (Cost=2
Card=4 Bytes=52)

3 2 INDEX (FULL SCAN) OF 'PK_DEPT' (INDEX (UNIQUE)) (Cost=
1 Card=4)

4 1 SORT (JOIN) (Cost=4 Card=14 Bytes=294)
5 4 TABLE ACCESS (FULL) OF 'EMP' (TABLE) (Cost=3 Card=14 B
ytes=294)





Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
11 consistent gets
0 physical reads
0 redo size
986 bytes sent via SQL*Net to client
508 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
14 rows processed

SQL> set autotrace off
SQL> spool off


Except for the recursive calls we find that there is no much difference between the two execution plans.








No comments: