Pages

Thursday, September 23, 2010

Query Parsing

What is Query ParsingThis is a featured page ?

 

In oracle, statement,  DDL/DML, or anything else, gets parsed. Parsing means what Oracle understands about the statement and based on that, how to execute it. This process is also known as Optimization of the query.The idea is how best Oracle can process the query or in other words, optimize its execution.
Parsing is of two types, Hard parse and Soft parse. If the said query is found in Oracle's cache, the query optimization is not needed.Oracle can pick up the optimized query and can execute it. If the query is run for the first time or the query's cached version is obsolete or flushed out from oracle's cache, query needs to be optimized and the process is c called Hard parse of the query. Hard parse , in general , is unavoidable as for the very first time, each query needs to be parsed , atleast for once. But in the subsequent executions, query should be simply soft parsed and executed.
The mechanism which works in the backend for doing all this is called Optimizer. There are two versions of it, Rule Based and Cost Based. The Rule Based optimizer(RBO) is made deprecated from Oracle version release 10g. This was not very much efficient as it was "statement driven". The Cost Based is now the only and supported mode of optimizer which is, as the name suggests, cost based and takes into the account the resource consumption of the query.

Flashback Drop Table

Flashback Drop Table:
When you issue the DROP TABLE command, Oracle merely renames the table and  moves it to a recycle bin.
The recycle bin is merely a data dictionary table that maintains information about dropped tables.
You can use the SELECT command to query the objects in the recycle bin. You can’t use INSERT, UPDATE, and DELETE commands on these objects.

You can view the contents of the recycle bin by using either the DBA_RECYCLEBIN or USER_RECYCLEBIN.


SQL> DROP TABLE EMP;


SQL> SELECT   OBJECT_NAME,    ORIGINAL_NAME,    OWNER,    TYPE ,    SPACE
FROM DBA_RECYCLEBIN;

OBJECT_NAME                                                             ORIGINAL_N              OWNER                      TYPE           SPACE
------------------------------                               ----------                            ------------  ------             ----------
BIN$5j9tXNl6Tn+94FZ4H/ylyQ==$0               PK_EMP                     SCOTT                       INDEX            8
BIN$hJ1qy1xyRomz6c40oBqQvg==$0            EMP                          SCOTT                       TABLE           8

When we drop any table the associated object like also dropped. For example if we drop EMP table the index associated with emp also dropped.

Table are restore with the original name that reside before drop

INDEX also flashback but name not change

Constraint name different from index name

11:56:29 SQL> DROP TABLE SCOTT.E1;
Table dropped.

11:56:34 SQL> FLASHBACK TABLE SCOTT.E1 TO BEFORE DROP ;
Flashback complete.

OR



11:56:34 SQL> FLASHBACK TABLE SCOTT.E1 TO BEFORE DROP  RENAME TO E2;
Flashback complete.

Flashback Database

Flashback Database:


Flashback Database and Restore Points are two related data protection features of Oracle that provide more efficient alternatives to point-in-time recovery for reversing unwanted database changes
create a normal restore point:
SQL> CREATE RESTORE POINT before_truncate;
Restore point created.
OR
create a guaranteed restore point:
SQL> CREATE RESTORE POINT before_truncate GUARANTEE FLASHBACK DATABASE;
Restore point created.

Verify by Querying
 
SELECT NAME, SCN, TIME, DATABASE_INCARNATION#,
        GUARANTEE_FLASHBACK_DATABASE,STORAGE_SIZE
        FROM V$RESTORE_POINT;


Example
 
 A table is truncated after creation of restore point 
 
e.g          truncate table emp;
 
we will perform following step to bring table data back.
 
1.SHUTDOWN DATABASE
2.STARTUP MOUNT EXCLUSIVE
3.FLASHBACK DATABASE TO restore point before_truncate


To Drop Restore point:
DROP RESTORE POINT before_truncate