25+ Oracle Performance Tuning Interview Questions [ 95% SUCCESS ] | 2020
Oracle Performance Tuning Interview Questions and Answers

25+ Oracle Performance Tuning Interview Questions [ 95% SUCCESS ]

Last updated on 04th Jul 2020, Blog, Interview Questions

About author

Pranavkumar (Lead Data Engineer )

High level Domain Expert in TOP MNCs with 8+ Years of Experience. Also, Handled Around 20+ Projects and Shared his Knowledge by Writing these Blogs for us.

(5.0) | 15212 Ratings 9751

Performance tuning is the process of optimizing Oracle performance by streamlining the execution of SQL statements. In other words, performance tuning simplifies the process of accessing and altering information contained by the database with the intention of improving query response times and application operations.

1) What Is Performance Tuning?

Ans:

Making optimal use of system using existing resources called performance tuning.

2) What Are The Types Of Tuning?

Ans:

  • CPU Tuning
  • Memory Tuning
  • IO Tuning
  • Application Tuning
  • Database Tuning

3) What Mainly Database Tuning Contains?

Ans:

  • Hit Ratios
  • Wait Events

4) What Is An Optimizer?

Ans:

Optimizer is a mechanism which will make the execution plan of an sql statement.

5) What Are The Types Of Optimizers?

Ans:

  • RBO(Rule Based Optimizer)
  • CBO(Cost Based Optimizer)

6) Which Optimizer Is The Best One?

Ans:

CBO

7) What Are The Pre Requsited To Make Use Of Optimizer?

Ans:

  • Set the optimizer mode
  • Collect the statistics of an object

8) How Do You Collect Statistics Of A Table?

Ans:

Analyze table emp compute statistics or analyze table emp estimate statistics.

9) What Is The Diff Between Compute And Estimate?

Ans:

If you use compute, The FTS will happen, if you use estimate just 10% of the table will be read

10) Data Dictionary Follows Which Optimizer Mode?

Ans:

RBO.

11) How Do You Delete Statistics Of An Object?
Ans:

Analyze table emp delete statistics.

12) How Do You Collect Statistics Of A User/schema?
Ans:

exec dbms_stats.gather_schema_stats(scott)

13) How Do You See The Statistics Of A Table?
Ans:

select num_rows,blocks,empty_blocks from dba_tables where tab_name=’emp’

14) What Are Chained Rows?
Ans:

These are rows, it spans in multiple blocks.

15) How Do You Collect Statistics Of A User In Oracle Apps?

Ans:

fnd_stats package.

16) How Do You Know What Sql Is Currently Being Used By The Session?

Ans:

By goind v$sql and v$sql_area.

17) What Is A Execution Plan?

Ans:

Its a road map how sql is being executed by oracle db..

18) How Do You Get The Index Of A Table And On Which Column The Index Is?

Ans:

dba_indexes and dba_ind_columns

19) Which Init Parameter You Have To Set To Bypass Parsing?

Ans:

cursor_sharing=force

20) How Do You Know Which Session Is Running Long Jobs?

Ans:

by going v$session_longops

    Subscribe For Free Demo

    21) How Do You Flush The Shared Pool?
    Ans:

    alter system flush shared_pool

    22) How Do You Get The Info About Fts?
    Ans:

    using v$sysstat

    23) How Do You Increase The Db Cache?
    Ans:

    alter table emp cache

    24) Where Do You Get The Info Of Library Cache?
    Ans:

    v$librarycache

    25) How Do You Get The Information Of Specific Session?
    Ans :

    v$mystat

    26) How Do You See The Trace Files?
    Ans:

    using tkprof usage: tkprof allllle.trc llkld.txt

    27) How Many Types Of Hits Are There And What Are They?

    Ans:

    There are two types of hits, they are:

    • Buffer hit
    • library hit

    28) What Are The Types Of Wait Events?
    Ans:

    • cpu time
    • direct path read

    29) A Table Space Has A Table With 30 Extents In It. Is This Bad? Why Or Why Not?
    Ans:

    Multiple extents in and of themselves aren’t bad. However if you also have chained rows this can hurt performance.

    30) How Do You Set Up Tablespaces During An Oracle Installation?
    Ans:

    You should always attempt to use the Oracle Flexible Architecture standard or another partitioning scheme to ensure proper separation of SYSTEM, ROLLBACK, REDO LOG, DATA, TEMPORARY and INDEX segments.

    31) You See Multiple Fragments In The System Tablespace, What Should You Check First?
    Ans:

    Ensure that users don’t have the SYSTEM tablespace as their TEMPORARY or DEFAULT tablespace assignment by checking the DBA_USERS view.

    32) What Are Some Indications That You Need To Increase The Shared_pool_size Parameter?
    Ans:

    Poor data dictionary or library cache hit ratios, getting error ORA-04031. Another indication is steadily decreasing performance with all other tuning parameters the same.

    33) What Is The General Guideline For Sizing Db_block_size And Db_multi_block_read For An Application That Does Many Full Table Scans?
    Ans:

    Oracle almost always reads in 64k chunks. The two should have a product equal to 64 or a multiple of 64.

    34) What Is The Fastest Query Method For A Table?
    Ans:

    Fetch by rowid.

    35) Explain The Use Of Tkprof? What Initialization Parameter Should Be Turned On To Get Full Tkprof Output?
    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.

    36) When Looking At V$sysstat You See That Sorts (disk) Is High. Is This Bad Or Good? If Bad, How Do You Correct It?
    Ans:

    If you get excessive disk sorts this is bad. This indicates you need to tune the sort area parameters in the initialization files. The major sort are parameter is the SORT_AREA_SIZe parameter.

    Course Curriculum

    Get Practical Oriented Oracle Performance Tuning Certification Course

    Weekday / Weekend BatchesSee Batch Details

    37) When Should You Increase Copy Latches? What Parameters Control Copy Latches?
    Ans:

    When you get excessive contention for the copy latches as shown by the “redo copy” latch hit ratio. You can increase copy latches via the initialization parameter LOG_SIMULTANEOUS_COPIES to twice the number of CPUs on your system.

    38) Where Can You Get A List Of All Initialization Parameters For Your Instance? How About An Indication If They Are Default Settings Or Have Been Changed?
    Ans:

    You can look in the init.ora file for an indication of manually set parameters. For all parameters, their value and whether or not the current value is the default value, look in the v$parameter view.

    39) Describe Hit Ratio As It Pertains To The Database Buffers. What Is The Difference Between Instantaneous And Cumulative Hit Ratio; Which Should Be Used For Tuning?
    Ans:

    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 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. Generally speaking an instantaneous reading gives more valuable data since it will tell you what your instance is doing for the time it was generated over.

    40) Discuss Row Chaining, How Does It Happen? How Can You Reduce It? How Do You Correct It?
    Ans:

    Row chaining occurs when a VARCHAR2 value is updated and the length of the new value is longer than the old value and won’t fit in the remaining block space. This results in the row chaining to another block. It can be reduced by setting the storage parameters on the table to appropriate values. It can be corrected by export and import of the effected table.

    41) When Looking At The Estate Events Report You See That You Are Getting Busy Buffer Waits. Is This Bad? How Can You Find What Is Causing It?
    Ans:

    Buffer busy waits may indicate contention in redo, rollback or data blocks. You need to check the v$waitstat view to see what areas are causing the problem. The value of the “count” column tells where the problem is, the “class” column tells you with what. UNDO is rollback segments, DATA is data base buffers.

    42) If You See Contention For Library Caches How Can You Fix It?
    Ans:

    Increase the size of the shared pool.

    43) If You See Statistics That Deal With “undo” What Are They Really Talking About?
    Ans:

    Rollback segments and associated structures.

    44) If A Tablespace Has A Default Pct Increase Of Zero What Will This Cause (in Relationship To The Smon Process)?
    Ans:

    The SMON process won’t automatically coalesce its free space fragments.

    45) If A Tablespace Shows Excessive Fragmentation What Are Some Methods To Defragment The Tablespace? (7.1,7.2 And 7.3 Only)
    Ans:

    In Oracle 7.0 to 7.2 The use of the ‘alter session set events ‘immediate trace name coalesce level ts#’;’ command is the easiest way to defragment contiguous free space fragmentation. The ts# parameter corresponds to the ts# value found in the ts$ SYS table. In version 7.3 the ‘alter tablespace coalesce;’ is best. If free space isn’t contiguous then export, drop and import of the tablespace contents may be the only way to reclaim non-contiguous free space.

    46) How Can You Tell If A Tablespace Has Excessive Fragmentation?
    Ans:

    If a select against the dba_free_space table shows that the count of a tablespaces extents is greater than the count of its data files, then it is fragmented.

    47) You See The Following On A Status Report:
    redo Log Space Requests 23
    redo Log Space Wait Time 0
    is This Something To Worry About? What If Redo Log Space Wait Time Is High? How Can You Fix This?
    Ans:

    Since wait time is zero, no. If wait time was high it might indicate a need for more or larger redo logs.

    48) What Can Cause A High Value For Recursive Calls? How Can This Be Fixed?
    Ans:

    A high value for recursive calls is cause by improper cursor usage, excessive dynamic space management actions, and or excessive statement re-parses. You need to determine the cause and correct it By either relinking applications to hold cursors, use proper space management techniques (proper storage and sizing) or ensure repeat queries are placed in packages for proper reuse.

    49) If You See A Pin Hit Ratio Of Less Than 0.8 In The Estate Library Cache Report Is This A Problem? If So, How Do You Fix It?
    Ans:

    This indicates that the shared pool may be too small. Increase the shared pool size.

    50) If You See The Value For Reloads Is High In The Estate Library Cache Report Is This A Matter For Concern?
    Ans:

    Yes, you should strive for zero reloads if possible. If you see excessive reloads then increase the size of the shared pool.

    51) You Look At The Dba_rollback_segs View And See That There Is A Large Number Of Shrinks And They Are Of Relatively Small Size, Is This A Problem? How Can It Be Fixed If It Is A Problem?
    Ans:

    A large number of small shrinks indicates a need to increase the size of the rollback segment extents. Ideally you should have no shrinks or a small number of large shrinks. To fix this just increase the size of the extents and adjust optimal accordingly.

    52) You Look At The Dba_rollback_segs View And See That You Have A Large Number Of Wraps Is This A Problem?
    Ans:

    A large number of wraps indicates that your extent size for your rollback segments are probably too small. Increase the size of your extents to reduce the number of wraps. You can look at the average transaction size in the same view to get the information on transaction size.

    53) In A System With An Average Of 40 Concurrent Users You Get The Following From A Query On Rollback Extents:
    rollback Cur Extents
    r01 11
    r02 8
    r03 12
    r04 9
    system 4
    you Have Room For Each To Grow By 20 More Extents Each. Is There A Problem? Should You Take Any Action?
    Ans:

    No there is not a problem. You have 40 extents showing and an average of 40 concurrent users. Since there is plenty of room to grow no action is needed.

    54) Explain rule-based optimizer and cost-based optimizer.?

    Ans:

    Oracle decides how to retrieve the necessary data whenever a valid SQL training Hyderabad statement is processed.This decision can be made using one of two methods:

    • Rule Based Optimizer: If the server has no internal statistics relating to the objects referenced by the statement, then the RBO method is used.This method will be deprecated in the future releases of Oracle.
    • Cost Based Optimizer: The CBO method is used if internal statistics are present.The CBO checks several possible execution plans and selects the one with the lowest cost based on the system resources.

    55) What are object data types? Explain the use of object data types.?

    Ans:

    Object data types are user defined data types. Both column and row can represent an object type. Object types instance can be stored in the database. Object datatypes make it easier to work with complex data, such as images, audio, and video. Object types provide higher-level ways to organize and access data in the database.The SQL attributes of Select into clause, i.e., SQL % Not found, SQL % found, SQL % Isopen, SQL %Rowcount.

    1. % Not found: True if no rows returned
      • E.g., If SQL%NOTFOUND then return some_value
    2. % found: True if at least one or more rows returned
      • E.g., If SQL%FOUND then return some_value
    3. %Isopen: True if the SQL cursor is open. Will always be false, because the database opens and closes the implicit cursor used to retrieve the data
    4. %Rowcount: Number of rows returned. Equals 0 if no rows were found (but the exception is raised) and a 1, if one or more rows are found (if more than one an exception is raised).

    56) What is translate and decode in Oracle?

    Ans:

    Translate: translate function replaces a sequence of characters in a string with another set of characters. The replacement is done single character at a time.

    Syntax: translate( string1, string_to_replace, replacement_string )

    Example: translate (‘1tech23’, ‘123’, ‘456);

    Decode: The DECODE function compares one expression to one or more other expressions and, when the base expression is equal to a search expression, it returns the corresponding result expression; or, when no match is found, returns the default expression when it is specified, or NA when it is not.

    Syntax: DECODE (expr , search, result [, search , result]… [, default])

    Example: SELECT employee_name, decode(employee_id, 10000, ‘tom’, 10001, ‘peter’, 10002, ‘jack’ ‘Gateway’) result FROM employee;

    Course Curriculum

    Get In Depth Knowledge on Oracle Performance Tuning Training

    • Instructor-led Sessions
    • Real-life Case Studies
    • Assignments
    Explore Curriculum

    57) What is Oracle correlated sub-queries? Explain with an example?

    Ans:

    A query which uses values from the outer query is called as a correlated sub query. The subquery is executed once and uses the results of all the evaluations in the outer query.

    Example:

    Here, the sub query references the employee_id in the outer query. The value of the employee_id changes by the row of the outer query, so the database must rerun the subquery for each row comparison. The outer query knows nothing about the inner query except its results.

    select employee_id, appraisal_id, appraisal_amount From employee

    where appraisal_amount < (select max(appraisal_amount)

    from employee e

    where employee_id = e. employee_id);

    58) Explain union and intersect with examples?

    Ans:

    UNION: The UNION operator is used to combine the result-set of two or more SELECT statements Tables of both the select statement must have the same number of columns with similar data types. It eliminates duplicates.

    Syntax:

    • SELECT column_name(s) FROM table_name1
    • UNION
    • SELECT column_name(s) FROM table_name2

    Example:

    • SELECT emp_Name FROM Employees_india
    • UNION
    • SELECT emp_Name FROM Employees_USA
    • INTERSECT allows combining results of two or more select queries. If a record exists in one query and not on the other, it will be omitted from the INTERSECT results.

    59) What is the difference between open_form and call_form? What is new_form built-in in oracle form?

    Ans:

    Open_form opens the indicated form. Call_form not just opens the indicated form, but also keeps the parent form alive.When new_form is called, the new indicted form is opened, and the old one is exited by releasing the memory. The new form is run using the same Run form options as the parent form.

    60) What is the difference between DBFile Sequential and Scattered Reads?

    Ans:

    Both “db file sequential read” and “db file scattered read” events signify time waited for I/O read requests to complete. Time is reported in 100’s of a second for Oracle 8i releases and below, and 1000’s of a second for Oracle 9i and above. Most people confuse these events with each other as they think of how data is read from disk. Instead, they should think of how data is read into the SGA buffer cache.

    db file sequential read: A sequential read operation reads data into contiguous memory (usually a single-block read with p3=1, but can be multiple blocks). Single block I/Os are usually the result of using indexes. This event is also used for rebuilding the control file and reading datafile headers (P2=1). In general, this event is indicative of disk contention on index reads.

    db file scattered read: Similar to db file sequential reads, except that the session is reading multiple data blocks and scatters them into different discontinuous buffers in the SGA. This statistic is NORMALLY indicating disk contention on full table scans. Rarely, data from full table scans could be fitted into a contiguous buffer area; these waits would then show up as sequential reads instead of scattered reads.

    The following query shows average wait time for sequential versus scattered reads: 

    • prompt “AVERAGE WAIT TIME FOR READ REQUESTS”
    • select a.average_wait “SEQ READ”, b.average_wait “SCAT READ”
    • from sys.v_$system_event a, sys.v_$system_event b
    • where a.event = ‘db file sequential read’
    • and b.event = ‘db file scattered read’;

    61) Explain about performance tuning enhancements?

    Ans:

    Oracle includes many performance tuning enhancements like:

    • Automatic Performance Diagnostic and Tuning Features
    • Automatic Shared Memory Management – Automatic Shared Memory Management puts Oracle in control of allocating memory within the SGA
    • Wait Model Improvements – A number of views have been updated and added to improve the wait model.
    • Automatic Optimizer Statistics Collection – gathers optimizer statistics using a scheduled job called GATHER_STATS_JOB
    • Dynamic Sampling – enables the server to improve performance
    • CPU Costing – default cost model for the optimizer (CPU+I/O), with the cost unit as time Optimizer Hints
    • Rule Based Optimizer Obsolescence – No more used
    • Tracing Enhancements – End to End Application Tracing which allows a client process to be identified via the client identifier rather than the typical session id
    • SAMPLE Clause Enhancements Hash Partitioned Global Indexes

    62) You see multiple fragments in the SYSTEM tablespace, what should you check first?

    Ans:

    Ensure that users don’t have the SYSTEM tablespace as their TEMPORARY or DEFAULT tablespace assignment by checking the DBA_USERS view.

    63) What are some indications that you need to increase the SHARED_POOL_SIZE parameter?

    Ans:

    Poor data dictionary or library cache hit ratios, getting error ORA-04031. Another indication is steadily decreasing performance with all other tuning parameters the same.

    64) When should you increase copy latches? What parameters control copy latches?

    Ans:

    When you get excessive contention for the copy latches as shown by the “redo copy” latch hit ratio. You can increase copy latches via the initialization parameter LOG_SIMULTANEOUS_COPIES to twice the number of CPUs on your system.

    65) If you see statistics that deal with “undo” what are they talking about?

    Ans:

    Rollback segments and associated structures.

    66) If a tablespace has a default pct increase of zero what will this cause (in relation to the SMON process)?

    Ans:

    The SMON process won’t automatically coalesce its free space fragments.

    67) How can you tell if a tablespace has excessive fragmentation?

    Ans:

    If a select against the dba_free_space table shows that the count of a tablespaces extents is greater than the count of its data files, then it is fragmented.

    68) Why and when should one tune?

    Ans:

    One of the biggest responsibilities of a DBA is to ensure that the Oracle database is tuned properly. The Oracle RDBMS is highly tunable and allows the database to be monitored and adjusted to increase its performance.

    One should do performance tuning for the following reasons:

    • The speed of computing might be wasting valuable human time (users waiting for response);
    • Enable your system to keep-up with the speed business is conducted; and Optimize hardware usage to save money (companies are spending millions on hardware).
    • Although this FAQ is not overly concerned with hardware issues, one needs to remember than you cannot tune a Buick into a Ferrari.

    69) What database aspects should be monitored?

    Ans:

    One should implement a monitoring system to constantly monitor the following aspects of a database. Writing custom scripts, implementing Oracle’s Enterprise Manager, or buying a third-party monitoring product can achieve this. If an alarm is triggered, the system should automatically notify the DBA (e-mail, page, etc.) to take appropriate action.

    Infrastructure availability:

    • Is the database up and responding to requests
    • Are the listeners up and responding to requests
    • Are the Oracle Names and LDAP Servers up and responding to requests
    • Are the Web Listeners up and responding to requests

    Things that can cause service outages:

    • Is the archive log destination filling up?
    • Objects getting close to their max extents
    • Tablespaces running low on free space/ Objects what would not be able to extend
    • User and process limits reached

    Things that can cause bad performance:

    See question “What tuning indicators can one use?”.

    70) Where should the tuning effort be directed?

    Ans:

    Consider the following areas for tuning. The order in which steps are listed needs to be maintained to prevent tuning side effects. For example, it is no good increasing the buffer cache if you can reduce I/O by rewriting a SQL statement.

    • Database Design (if it’s not too late): Poor system performance usually results from a poor database design. One should generally normalize to the 3NF. Selective demoralization can provide valuable performance improvements. When designing, always keep the “data access path” in mind. Also look at proper data partitioning, data replication, aggregation tables for decision support systems, etc.
    • Application Tuning: Experience showed that approximately 80% of all Oracle system performance problems are resolved by coding optimal SQL. Also consider proper scheduling of batch tasks after peak working hours.
    • Memory Tuning: Properly size your database buffers (shared pool, buffer cache, log buffer, etc) by looking at your buffer hit ratios. Pin large objects into memory to prevent frequent reloads.
    • Disk I/O Tuning: Database files needs to be properly sized and placed to provide maximum disk subsystem throughput. Also look for frequent disk sorts, full table scans, missing indexes, row chaining, data fragmentation, etc.
    • Eliminate Database Contention: Study database locks, latches and wait events carefully and eliminate where possible.
    • Tune the Operating System: Monitor and tune operating system CPU, I/O and memory utilization. For more information, read the related Oracle FAQ dealing with your specific operating system.

    71) What tuning indicators can one use?

    Ans:

    The following high-level tuning indicators can be used to establish if a database is performing optimally or not:

    Buffer Cache Hit Ratio

    Formula: Hit Ratio = (Logical Reads – Physical Reads) / Logical Reads

    Action: Increase DB_CACHE_SIZE (DB_BLOCK_BUFFERS prior to 9i) to increase hit ratio

    Library Cache Hit Ratio

    Action: Increase the SHARED_POOL_SIZE to increase hit ratio

    72) What tools/utilities does Oracle provide to assist with performance tuning?

    Ans:

    Oracle provide the following tools/ utilities to assist with performance monitoring and tuning:

    • TKProf
    • UTLBSTAT.SQL and UTLESTAT.SQL – Begin and end stats monitoring
    • Statspack
    • Oracle Enterprise Manager – Tuning Pack

    73) What is STATSPACK and how does one use it?

    Ans:

    Statspack is a set of performance monitoring and reporting utilities provided by Oracle from Oracle8i and above. Statspack provides improved BSTAT/ESTAT functionality, though the old BSTAT/ESTAT scripts are still available. For more information about STATSPACK, read the documentation in file $ORACLE_HOME/rdbms/admin/spdoc.txt.

    Install Statspack:

    cd $ORACLE_HOME/rdbms/admin

    sqlplus “/ as sysdba” @spdrop.sql — Install Statspack –

    sqlplus “/ as sysdba” @spcreate.sql– Enter tablespace names when prompted

    Use Statspack:

    sqlplus perfstat/perfstat

    exec statspack.snap; — Take a performance snapshots

    exec statspack.snap;

    Get a list of snapshots:

    select SNAP_ID, SNAP_TIME from STATS$SNAPSHOT;

    @spreport.sql — Enter two snapshot id’s for difference report

    Other Statspack Scripts:

    sppurge.sqlPurge a range of Snapshot Id’s between the specified begin and end Snap Id’s
    spauto.sqlSchedule a dbms_job to automate the collection of STATPACK statistics
    spcreate.sqlInstalls the STATSPACK user, tables and package on a database (Run as SYS)
    spdrop.sqlDeinstall STATSPACK from database (Run as SYS)
    sppurge.sqlDelete a range of Snapshot Id’s from the database
    spreport.sqlReport on differences between values recorded in two snapshots
    sptrunc.sqlTruncates all data in Statspack tables

    74) When is cost based optimization triggered?

    Ans:

    It’s important to have statistics on all tables for the CBO (Cost Based Optimizer) to work correctly. If one table involved in a statement does not have statistics, Oracle has to revert to rule-based optimization for that statement. So you really want for all tables to have statistics right away; it won’t help much to just have the larger tables analyzed.

    Generally, the CBO can change the execution plan when you:

    • Change statistics of objects by doing an ANALYZE;
    • Change some initialization parameters (for example: hash_join_enabled, sort_area_size,
      db_file_multiblock_read_count).

    75) How can one optimize %XYZ% queries?

    Ans:

    It is possible to improve %XYZ% queries by forcing the optimizer to scan all the entries from the index instead of the table. This can be done by specifying hints.

    If the index is physically smaller than the table (which is usually the case) it will take less time to scan the entire index than to scan the entire table.

    76) Where can one find I/O statistics per table?

    Ans:

    The UTLESTAT report shows I/O per tablespace but one cannot see what tables in the tablespace has the most I/O.

    The $ORACLE_HOME/rdbms/admin/catio.sql script creates a sample_io procedure and table to gather the required information.

    After executing the procedure, one can do a simple SELECT * FROM io_per_object; to extract the required information.

    Oracle Performance Tuning Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

    77)My query was fine last week and now it is slow. Why?

    Ans:

    The likely cause of this is because the execution plan has changed. Generate a current explain plan of the offending query and compare it to a previous one that was taken when the query was performing well. Usually the previous plan is not available.

    Some factors that can cause a plan to change are:

    • Which tables are currently analyzed? Were they previously analyzed? (ie. Was the query using RBO and now CBO?)
    • Has OPTIMIZER_MODE been changed in INIT.ORA?
    • Has the DEGREE of parallelism been defined/changed on any table?
    • Have the tables been re-analyzed? Were the tables analyzed using estimate or compute? If estimate, what percentage was used?
    • Have the statistics changed?
    • Has the INIT.ORA parameter DB_FILE_MULTIBLOCK_READ_COUNT been changed?
    • Has the INIT.ORA parameter SORT_AREA_SIZE been changed?
    • Have any other INIT.ORA parameters been changed?
    • What do you think the plan should be? Run the query with hints to see if this produces the required performance.

    78) Why is Oracle not using the damn index?

    Ans:

    This problem normally only arises when the query plan is being generated by the Cost Based Optimizer. The usual cause is because the CBO calculates that executing a Full Table Scan would be faster than accessing the table via the index. Fundamental things that can be checked are:

    USER_TAB_COLUMNS.NUM_DISTINCT – This column defines the number of distinct values the column holds.

    USER_TABLES.NUM_ROWS – If NUM_DISTINCT = NUM_ROWS then using an index would be preferable to doing a FULL TABLE SCAN. As the NUM_DISTINCT decreases, the cost of using an index increase thereby is making the index less desirable.

    USER_INDEXES.CLUSTERING_FACTOR – This defines how ordered the rows are in the

    index. If CLUSTERING_FACTOR approaches the number of blocks in the table, the rows are ordered. If it approaches the number of rows in the table, the rows are randomly ordered. In such a case, it is unlikely that index entries in the same leaf block will point to rows in the same data blocks.

    Decrease the INIT.ORA parameter DB_FILE_MULTIBLOCK_READ_COUNT – A higher value will make the cost of a FULL TABLE SCAN cheaper.

    Remember that you MUST supply the leading column of an index, for the index to be used (unless you use a FAST FULL SCAN or SKIP SCANNING).

    Many other factors affect the cost, but sometimes the above can help to show why the CBO is not using an index. If from checking the above you still feel that the query should be using an index, try specifying an index hint. Obtain an explain plan of the query either using TKPROF with TIMED_STATISTICS, so that one can see the CPU utilization, or with AUTOTRACE to see the statistics. Compare this to the explain plan when not using an index.

    79) When should one rebuild an index?

    Ans:

    You can run the ‘ANALYZE INDEX VALIDATE STRUCTURE’ command on the affected indexes – each invocation of this command creates a single row in the INDEX_STATS view. This row is overwritten by the next ANALYZE INDEX command, so copy the contents of the view into a local table after each ANALYZE. The ‘badness’ of the index can then be judged by the ratio of ‘DEL_LF_ROWS’ to ‘LF_ROWS’.

    Are you looking training with Right Jobs?

    Contact Us
    Get Training Quote for Free