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
 

 

 

 
 

Oracle Regular expressions indexes as a tuning tool

Oracle Tips by Burleson Consulting

Oracle Regular Expression syntax has profound implications for Oracle tuning, especially in the area of indexing where indexes can be created on regular expressions, eliminating expensive full-table scans in-favor of fast index access.  Regular expressions are extremely powerful for extracting facts from large text columns, especially the regexp_like syntax.

Oracle expert Jonathan Gennick notes that regular expression can be used in an Oracle index, a powerful tool for improving the speed of complex SQL queries, and notes that regular expression indexes (a type of function-based index) can dramatically reduce database overhead for pattern-matching queries.  I've noted in my book "Oracle Tuning: The Definitive Reference", that function-based indexes are one of the most powerful and underutilized tools for Oracle professionals.

Here are some little know facts about regular expressions:

  • They can be used with bind variables

  • They can be included in function-based indexes

Indexing on regular expressions

In Parsing with regular expressions regexp_like Jonathan Gennick shows a great example where we use Oracle regular expressions to extract “acreage” references from inside a text string, ignoring important factors such as case sensitivity and words stems (acre, acres, acreage):

COLUMN park_name format a30
COLUMN acres     format a13
 
SELECT
  park_name,
  REGEXP_SUBSTR(description,'[^ ]+[- ]acres?',1,1,'i') acres
  FROM michigan_park
  WHERE REGEXP_LIKE(description, '[^ ]+[- ]acres?','i');

Here is the output, where we see that the regular expression has parsed-out the acreage figures, just as-if they were a discrete data column with the table:

PARK_NAME                       ACRES
____________________________    ___________
Mackinac Island State Park      1800 acres
Muskallonge Lake State Park     217-acre
Porcupine Mountains State Park  60,000 acres
Tahquamenon Falls State Park    40,000+ acres

The only problem with this query is that it will always perform a large-table full-table scan on the michigan_park table, causing unnecessary overhead for Oracle.

However, using the powerful function-based indexes we could eliminate the unnecessary overhead by using the regular expression directly in the index.

CREATE INDEX
   parks_acreage

ON
   michigan_parks

 (REGEXP_LIKE(description, '[^ ]+[- ]acres?','i'));

However, Laurent Schneider notes that it is illegal to have an index on a Boolean function, but you could have an index on a case expression returning 1.

create index
   i
on
   michigan_parks
  (case when
      description like '_% acre%'
   or
      description like '_%-acre%'
   then 1 end);

select
   *
from
   michigan_parks
where
   (case when
      description like '_% acre%'
    or
      description like '_%-acre%' then 1 end)
is not null;

This simple index definition would create a yes/no index on all park records that contain a reference to "acre", "acres", "acreage".  The database overhead would be once, when each rows is added to the table, and not over-and-over again when queries are executed.

The rules for choosing a function-based index on a complex expression (regular expression, decode) is a trade-off between several factors:

  • The number of blocks in the table - A full-table scan of a super-large table can cause I/O contention.
     

  • The percentage of rows returned - If the regular expression returns only a small percentage of the total table rows, a regular expression index will greatly reduce I/O.
     

  • The frequency of the query - If the query is executed frequently, Oracle may do millions of unnecessary full-table scans.
     

  • The tolerance for slower row inserts - Parsing the text column at insert time (to add the row to the regular expression index) will slow-down inserts.

It's the age-old quandary. If we build the regular expression once (at insert time) it can be used over-and-over again with little overhead.  Conversely, using regular expressions in SQL without a supporting index will cause repeated full-table scans.



 

For detailed information on learning regular expression and using them in the database see Jonathan Gennick and Peter Linsley's book Oracle Regular Expressions Pocket Reference.

 

 

If you like Oracle tuning, you may enjoy my new book "Oracle Tuning: The Definitive Reference", over 900 pages of BC's favorite tuning tips & scripts. 

You can buy it direct from the publisher for 30%-off and get instant access to the code depot of Oracle tuning scripts.


 

 

  
 

Oracle performance tuning software 
 
 
 
 

Oracle performance tuning book

 

 
Search oracle
 
Oracle performance Tuning 10g reference poster
 
 
 
Oracle training in Linux commands
 
Oracle training Excel
 
Oracle training & performance tuning books
 

 

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


 

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

Oracle © is the registered trademark of Oracle Corporation.