Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

Free Oracle Tips

HTML Text

 Home
 E-mail Us
 Oracle Articles


 Oracle Training
 Oracle News

 Oracle Forum
 Class Catalog


 Our Staff
 Our Prices
 Help Wanted!

 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 UNIX
 Oracle UNIX
 Linux
 Oracle Linux
 Monitoring
 Remote help

 Remote plans
 Remote
services
 Oracle C++
 Oracle Java
 Apache
 JDeveloper
 App Server

 Applications
 Oracle Forms
 Oracle Portal
 11i Upgrades
 SQL Server
 Oracle Concepts
 HTML-DB Tips
 Software Help

 Remote Help  
 Development  

 Implementation


 Financials Training
 Oracle 11i
 Oracle Apps 11i
 Oracle Workflow
 Oracle AR 11i Class
 Oracle AP 11i class
 Oracle GL 11i class
 Oracle HR 11i class
 Oracle FA 11i class
 11i Project Mgt
 11i procurement
 11i collections


 Oracle Posters
 Oracle Books

 Oracle Tuning Book
 Oracle RAC Book
 Oracle Security
 Easy Oracle Books
 Oracle Scripts
 SQL Server DBA
 SQL Design Patterns
 Ion
 Excel-DB   


 BC Oracle News


 Rednecks!
 Dress code
 Arabian Stallion

 Burleson Arabians
 Guide Horses
 Don Burleson Blog
 Golf & Travel


 Privacy Policy
 

 

Guard against performance issues when using Oracle9i hints and views
Jan 22, 2002
Donald Burleson

© 2002 TechRepublic, Inc.
 
 
 
Used separately, hints and views are terrific tools for Oracle tuning. But used together, they can cause severe performance problems. Let’s look at what hints, views, and materialized views can do for you. Then, we'll consider when and how to use them.

Hints

Hints are compiler directives that change the execution plan for SQL statements. Of course, if the Oracle cost-based optimizer (CBO) and rule-based optimizer (RBO) always made optimal execution plans, hints would not be necessary.

There are two classes of hints:
 
  • General mode hints—This class of hints changes the overall execution mode for Oracle queries. These hints include /*+ rule */ and /*+ first_rows */.
  • Detailed directive hints—This class of hints directs specific access paths, such as the use of a hash join over a nested loop join, /*+ use_hash */, and the use of a specific index to access a table.


In sum, hints are a necessary and useful tool for tuning SQL statements.

Views

An Oracle view is the encapsulation of a complex query into a single pseudotable that behaves like a single table. For example, here we create a view:

create or replace view
  cust_view
as
select
  customer_name,
   order_nbr,
   item_desc
from
   customer     c,
   order        o,
   item         i,
where
   c.cust_nbr = o.cust_nbr
and
   o_item_nbr = i.item_nbr;


The pseudotable in the following query hides the complexity of the underlying query and has no effect on the performance of the underlying SQL:
select * from cust_view where cust_nbr = 123;

In this example, every time the cust_view is queried, Oracle will join the three tables at runtime.

Since views don't improve performance, why use them? Most Oracle shops that employ views do so for end-user queries or for queries where they want to hide complexity and ensure uniform join methods.

Materialized views

Oracle’s solution to improving performance of standard views is the materialized view. When you create a material view, it prejoins all of the tables in a complex query. Since all of the query joins have been done, running SQL against the materialized view will be far faster than with a standard view. However, materialized views have some shortcomings:
 

  • More storage is required—Since the materialized view actually performs the query, extra disk space is required to store the result table.
  • Materialized views become stale—From the moment the materialized view is created, the view may become out-of-date. To periodically refresh a materialized view, you can use a mechanism that's similar to an Oracle snapshot.

The danger of using views

Some shops create complex views to represent large subsets of their schema and allow developers and end users to access these views. This approach often leads to poor performance. Here are some situations to avoid if you work with complex views:
 

  • Querying subsets—Developers will often query a subset of the complex view, not realizing that all tables in the view will be joined.
  • Adding complex WHERE clauses—Queries against views with complex WHERE clauses will often override any tuning hints that are placed within the view, causing suboptimal execution plans.
  • Hinting the view—A view can't be treated as a finite table, and adding SQL hints to view queries will often result in suboptimal execution plans. Remember, any time the optimizer gets “confused,” it will perform an unnecessary full-table scan. While hints can be used for specific SQL optimization, the use of views is strongly discouraged with hints because they can be invoked in many contexts.


To summarize, Oracle views are an encapsulation of a complex query and must be used with care. Here are the key facts to remember:
 

  • Views are not intended to improve SQL performance. When you need to encapsulate SQL, you should place it inside a stored procedure rather than use a view.
  • Views hide the complexity of the underlying query, making it easier for inexperienced programmers and end users to formulate queries.
  • Views can be used to tune queries with hints, provided that the view is always used in the proper context.


Combining hints and views

Although you must be careful when using hints against a view, here are two ways you can use them without creating performance problems:
 

  • You can embed hints inside the view definition. This is useful for cases where a view will be called without a WHERE clause, but it can be quite damaging to performance when the view result set is altered by calling the view with a complex WHERE clause.
  • You can add hints in the calling query. The danger with using hints in views is that the context of the query may change. When this happens, any existing hints within the view definition may be ignored, which can confuse the SQL optimizer and result in an unnecessary full-table scan.


When views are invoked with certain WHERE clauses, the context of the view may change, as will the functionality of any SQL hints that may be embedded inside the view.

This simple example shows how such a context change can occur:


select
   cust_name,
   cust_address
from
   cust_view
where
   cust_nbr = 123;


We've invoked a view that performs a three-way table join on execution, but the WHERE clause in the SQL indicates that the user is interested only in data within a single table. Any SQL hints that might be embedded inside the view may be ignored.

Conclusion

By themselves, Oracle views, materialized views, and SQL query hints are useful tools for Oracle tuning. However, special care must be taken when implementing views to ensure that developers and end users don't misuse them and create performance problems.



 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.
 
 


Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

 

Remote DBA Services


 

Copyright © 1996 -  2009 by Burleson Enterprises, Inc. All rights reserved.

Oracle © is the registered trademark of Oracle Corporation.