SQLStatement to optimize the words need to know its implementation plan, and accordingly to adjust. There are several ways to get Oracle's execution plan, and here's a summary1, the use of explain
Oracle RDBMS executes every SQL statement, and must be evaluated by the Oracle Optimizer. So, understanding how the optimizer selects (searching) the path and how the index is used is a great help for optimizing SQL statements. Explain can be used to quickly and easily find out how the query data in a given SQL statement gets the search path (which we often call access path). So we choose the best query method to achieve maximum optimization effect.
1.1 , Ann Pack
To use explain, you first have to execute the appropriate script to create a Explain_plan table.
The specific script executes as follows:
$ORACLE _home/rdbms/admin/utlxplan.sql (UNIX) The script generates a table this program creates a table named Plan_table.
1.2. Use
General usage Syntax:
Explain plan [SET statement_id [=] < string literal >] [into < table_name >]
for < sql_statement >
which
STATEMENT_ID: is a unique string that distinguishes the current execution plan from other execution plans that are stored in the same plan.
TABLE_NAME: is the plan table name, which is structured as shown before, and you can set this name arbitrarily.
Sql_statement: is the real SQL statement.
Like what:
Sql>explain plan set statement_id= ' t_test ' for select * from T_test;
Sql>
Explained
Execute the following statement to query the execution plan
Sql>select a.operation,options,object_name,object_type,id,parent_id
2 from Plan_table A
3 WHERE statement_id= ' t_test '
4 ORDER by Id;
You can also use this sentence to select * from table (dbms_xplan.display); You can list all the data in the plan_table.
2, the use of Autotrace method
2.1, installation
Run script with sys user Ultxplan.sql
The script to build this table is: (UNIX: $ORACLE _home/rdbms/admin, Windows:%oracle_home%/rdbms/admin) ultxplan.sql.
Sql> connect sys/sys@colm2 as SYSDBA;
Sql> @c:/oracle/ora92/rdbms/admin/utlxplan.sql;
sql> create public synonym plan_table a synonym for plan_table;--
Sql> Grant all in plan_table to public;--authorize all users