The sequence of operations that Oracle performs to execute a SQL statement is called an execution plan. Sometimes it’s useful to look at the execution plan for a statement, in order to determine whether the plan picked by the optimizer is an efficient one. You can use Oracle’s EXPLAIN PLAN statement for this purpose. EXPLAIN PLAN takes a SQL statement, determines the execution plan, and stores that plan in a special table known as the plan table.
If you are not familiar with the use of EXPLAIN PLAN, you may want to consult Oracle Corporation’s Oracle8 Tuning manual, Oracle SQL*Plus: The Definitive Guide by Jonathan Gennick (O’Reilly & Associates, 1998), or Oracle SQL: The Essential Reference by David Kreines (O’Reilly & Associates, 2000).
The plan table used by EXPLAIN PLAN is most often named PLAN_TABLE. The columns of the table describe various aspects of the execution plan. Two columns are of special importance for parallel execution:
Describes the order in which the output from execution plan operations is consumed.
Describes the parallel or serial relationships between steps. The possible values for the OTHER_TAG column are described in Table 5.4.
Table 5-4. Values of the OTHER_TAG Column in the Plan Table
Value |
Meaning |
---|---|
SERIAL |
A serial operation |
No value; the column is null |
A serial operation |
SERIAL_FROM_REMOTE |
A serial operation at a remote site |
PARALLEL_FROM_SERIAL |
A serial operation that passes output to a set of parallel slave processes |
PARALLEL_TO_PARALLEL |
A parallel operation that passes output to a second set of parallel slave processes |
PARALLEL_TO_SERIAL |
A parallel operation that passes output to the parallel coordinator |
PARALLEL_COMBINED_WITH_PARENT |
A parallel operation, the parent step of which also was executed in parallel by the same set of slave processes |
PARALLEL_COMBINED_WITH_CHILD |
A parallel operation, the child step of which also was executed in parallel by the same set of slave processes |
When a query is executed in parallel, make sure that you don’t have any serial execution steps in the execution plan. You can check for that by using EXPLAIN PLAN to view the execution plan of your parallel SQL statements and checking the values for the OTHER_TAG column. The values that you want to see are the following:
PARALLEL_TO_PARALLEL |
PARALLEL_TO_SERIAL |
PARALLEL_COMBINED_WITH_PARENT |
PARALLEL_COMBINED_WITH_CHILD |
Any other value indicates a serial operation, which may represent a bottleneck. The following example shows an execution plan for a statement with just such a bottleneck. Notice the DEGREE values for the two tables involved in the query. You’ll see that these have a drastic effect on the query’s performance:
SQL>SELECT table_name, degree, instances FROM user_tables;
TABLE_NAME DEGREE INSTANCES ------------------------------ ---------- ---------- DEPTTEST 1 1 EMPTEST 4 1 2 rows selected. SQL>EXPLAIN PLAN SET statement_id = 's1' FOR
2SELECT empno, ename, sal, comm, dname FROM
3emptest e, depttest d
4WHERE e.deptno = d.deptno
5ORDER BY empno;
Explained. SQL>SELECT LPAD(' ',2*(level-1))||operation||' '||options
2||' '||object_name
3|| DECODE(other_tag,NULL,'','(') || other_tag
4|| DECODE(other_tag,NULL,'',')') "Query Plan"
5FROM plan_table
6START WITH id = 0 AND statement_id = '&stid'
7CONNECT BY PRIOR id = parent_id AND statement_id ='&stid';
Enter value for stid:s1
old 5: START WITH id = 0 AND statement_id = '&stid' new 5: START WITH id = 0 AND statement_id = 's1' Enter value for stid:s1
old 6: CONNECT BY PRIOR id = parent_id AND statement_id ='&stid' new 6: CONNECT BY PRIOR id = parent_id AND statement_id ='s1' Query Plan -------------------------------------------------------------------- SELECT STATEMENT SORT ORDER BY (PARALLEL_TO_SERIAL) MERGE JOIN (PARALLEL_TO_PARALLEL) SORT JOIN (PARALLEL_COMBINED_WITH_PARENT) TABLE ACCESS FULL EMPTEST(PARALLEL_TO_PARALLEL) SORT JOIN (PARALLEL_COMBINED_WITH_PARENT) TABLE ACCESS FULL DEPTTEST(PARALLEL_FROM_SERIAL) 7 rows selected.
This execution plan indicates that the table scan of the DEPTTEST table is being performed in serial. You can tell this because the OTHER_TAG for that step is PARALLEL_FROM_SERIAL. The reason for this step is because the DEPTTEST table has DEGREE set to 1 in its definition. The problem, though, is that the results of this serial operation are being fed into a parallel operation. It’s unlikely that a serial table scan will be able to feed a parallel operation fast enough to take full advantage of that parallelism.
One way to fix the problem, and get rid of the PARALLEL_FROM_SERIAL step, is to increase the DEGREE setting for the DEPTTEST table. This example shows how to do this and then shows the resulting change in the execution plan:
SQL>ALTER TABLE depttest PARALLEL (DEGREE 4);
Table altered. SQL>EXPLAIN PLAN SET statement_id = 's4' FOR
2SELECT empno, ename, sal, comm, dname FROM
3emptest e, depttest d
4WHERE e.deptno = d.deptno
5ORDER BY empno
6/
Explained. SQL>SELECT LPAD(' ',2*(LEVEL-1))||operation||' '||options
2||' '||object_name
3|| DECODE(other_tag,NULL,'','(') || other_tag
4|| DECODE(other_tag,NULL,'',')') "Query Plan"
5FROM plan_table
6START WITH id = 0 AND statement_id = '&stid'
7CONNECT BY PRIOR id = parent_id AND statement_id ='&stid';
Enter value for stid:s4
old 6: START WITH id = 0 AND statement_id = '&stid' new 6: START WITH id = 0 AND statement_id = 's4' Enter value for stid:s4
old 7: CONNECT BY PRIOR id = parent_id AND statement_id ='&stid' new 7: CONNECT BY PRIOR id = parent_id AND statement_id ='s4' Query Plan -------------------------------------------------------------------- SELECT STATEMENT SORT ORDER BY (PARALLEL_TO_SERIAL) MERGE JOIN (PARALLEL_TO_PARALLEL) SORT JOIN (PARALLEL_COMBINED_WITH_PARENT) TABLE ACCESS FULL EMPTEST(PARALLEL_TO_PARALLEL) SORT JOIN (PARALLEL_COMBINED_WITH_PARENT) TABLE ACCESS FULL DEPTTEST(PARALLEL_TO_PARALLEL) 7 rows selected.
Notice the change in the execution plan. The PARALLEL_TO_PARALLEL value in the last step indicates that the depttest table now will be scanned in parallel. You now have one parallel operation feeding another parallel operation, and the potential serial bottleneck has been removed.
Oracle8i comes with a script named
utlxplp.sql
that displays the execution plan of
parallel SQL statements in a useful manner. You can find this script
in your $ORACLE_HOME/rdbms/admin
directory, and
you can use it to analyze the EXPLAIN PLAN outputs of your parallel
SQL statements. For more information on the
utlxplp.sql
script, refer to Oracle
Corporation’s Oracle8i Tuning manual.
3.143.5.201