You are on page 1of 5

PERFORMANCE TUNING

1.What is a HINT and what are types HINT?


Hints are suggestions that give the optimizer for optimizing a SQL statement.
Hints allows to make decisions usually made by the optimizer.
Hints give specific information that we know about our data and application.
USE OF HINTS:

Oracle optimizer may not always choose the best execution plan

Using hints may improve the performance by changing the execution plan
oracle takes.

Hints can be used in the Select, Delete, and Update clauses.

In each statement, the hint goes directly after the Select, Delete, or Update
keyword. A few hints use Insert.

Hints are placed in the /*+ */ tag, where the hint goes after the + sign

select /*+ index(emp_alias ix_emp) */ ... from scott.emp emp_alias

Ex: SELECT /*+ ALL_ROWS */ From


Types of Hints:

Approach hints

Access hints

Join hints

Misc. hints
1.Approach Hints:

ALL_ROWS: Minimizes total resource consumption. Results will be returned


only after all processing has been completed

FIRST_ROWS(n): Minimized response time, or minimal resource usage to


return the first n rows.
2.Access Hints:

FULL(table): Chooses a full table scan for the table, even if there is an index
available.

INDEX(table [index [index]...]): Chooses an Index scan for the table.


3.Index Hint Example:

CIS Department has far more males than females

SELECT /*+ FULL(s) */ id, name


FROM Student s
WHERE sex = m;

SELECT /*+ Index(s sex_index) */ id, name


FROM Student s
WHERE sex = f;
4.Join hints:

ORDERED: tables are joined in the order in which they appear in the FROM
clause.

LEADING(table): specified table is the first table used in the join order.

USE_HASH(table [table] ): Tables are joined using a hash join. Smaller table
is used to make a hash table on join key. The larger table is scanned using
hash table to find joined rows.

USE_NL(table [table]): Joins tables using nested loops join, using specified
table as inner join. For every row in outer table, oracle accesses every row in
inner table.

USE_MERGE(table [table]): Joins tables using a sort-merge join. Sorted list


are made and then merged together. Best if tables are already sorted.

56.What is tkprof and how is it used?


Ans: The tkprof tool is a tuning tool used to determine cpu and execution
times for SQL statements. You use it by first setting timed_statistics to true in
the initialization file and then turning on tracing for either the entire
database via the sql_trace parameter or for the session using the ALTER

SESSION command. Once the trace file is generated you run the tkprof tool
against the trace file and then look at the output from the tkprof tool . This
can also be used to generate explain plan output.
57.What is explain plan and how is it used?
Ans: The EXPLAIN PLAN command is a tool to tune SQL statements. To use it
you must have an explain_table generated in the user you are running the
explain plan for. This is created using the utlxplan.sql script. Once the explain
plan table exists you run the explain plan command giving as its argument
the SQL statement to be explained. The explain_plan table is then queried to
see the execution plan of the statement. Explain plans can also be run using
tkprof.
EXPLAIN PLAN FOR
SELECT *
FROM emp e, dept d
WHERE e.deptno = d.deptno
AND

e.ename = 'SMITH';

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);

47.What do you mean by Parsing?


Ans: Parsing : Parsing is the process of:
1. Translating a SQL statement, verifying it to be a valid statement
2. Performing data dictionary lookups to check table and column definitions
3. Acquiring parse locks on required objects so that their definitions do not
change during the statement's parsing
4. Checking privileges to access referenced schema objects

5. Determining the execution plan to be used when executing the statement


6. Loading it into a shared SQL area
7. For distributed statements, routing all or part of the statement to remote
nodes that contain referenced data.

66.Describe hit ratio as it pertains to the database buffers. What is


the difference between instantaneous and cumulative hit ratio and
which should be used for tuning?
Ans: The hit ratio is a measure of how many times the database was able to
read a value from the buffers verses how many times it had to re-read a data
value from the disks. A value greater than 80-90% is good, less could
indicate problems. If you simply take the ratio of existing parameters this will
be a cumulative value since the database started. If you do a comparison
between pairs of readings based on some arbitrary time span, this is the
instantaneous ratio for that time span. An instantaneous reading gives more
valuable data since it will tell you what your instance is doing for the time it
was generated over.
Rule Based Optimization and Cost Based Optimization
Rule Based Optimization: This is an old technique. Basically, the RBO used a set of rules to determine how to
execute a query. E.g. If an index is available on a table, the RBO rules can be to always use that index (a RBO
for our travel analogy can be avoid all routes with speed brakers). As it turns out that this is simpler to
implement but not the best strategy always and can backfire. A Classic example of indexing a gender column
is shown here in a similar post. RBO was supported in earlier versions of Oracle. (SQL Server supports table
hints which in a way can be compared to RBO, as they force optimizer to follow certain path).
Cost Based Optimization: Motivation behind CBO is to come up with the cheapest execution plan available for
each SQL statement. The cheapest plan is the one that will use the least amount of resources (CPU, Memory,
I/O, etc.) to get the desired output (in relation to our travel analogy this can be Petrol, time, etc.). This can be
a daunting task for DB engine as complex queries can thousands of possible execution paths, and selecting
the best one can be quite expensive. For more information on CBO I suggest you go through Inside MS SQL
Server 2005 T-SQL Querying. CBO is supported by most of databases including Oracle, SQL Server, etc.

You might also like