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

 
 Home
 E-mail Us
 Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


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


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 

 
 

Oracle LIKE clause searches with text indexes

Oracle Tips by Burleson Consulting

 

One serious SQL performance problem occurs when you use the SQL 'LIKE clause' operator to find a string within a large Oracle table column (e.g. VARCHAR(2000), CLOB, BLOB):

 

Select stuff from bigtab where text_column like '%ipod%';
Select stuff from bigtab where full_name like '%JONES';

 

Because standard Oracle cannot index into a large column, there 'like' queries cause full-table scans, and Oracle must examine every row in the table, even when the result set is very small.  These unnecessary full-table scans are a problem:

 

  1. Large-table full-table scans increase the load on the disk I/O sub-system
     

  2. Small table full table scans (in the data buffer) cause high consistent gets and drive-up CPU consumption

For details, see Oracle SQL "like clause" and index access.

 

Oracle*Text Indexes


The Oracle*Text utility (formally called Oracle ConText and Oracle Intermedia) allows us to parse through a large text column and index on the words within the column. 

 

Unlike ordinary b-tree or bitmap indexes, Oracle context, ctxcat and ctxrule indexes can be set not to update as content is changed.  Since most standard Oracle databases will use the ctxcat index with standard relational tables, you must decide on a refresh interval.  Oracle provides the SYNC operator for this.  The default is SYNC=MANUAL and you must manually synchronize the index with CTX_DDL.SYNC_INDEX.

 

SYNC (MANUAL | EVERY "interval-string" | ON COMMIT)]
 

Hence, Oracle Text indexes are only useful for removing full-table scans when the tables are largely read-only and/or the end-users don' t mind not having 100% search recall:
 

  • The target table is relatively static (e.g. nightly batch updates)
     

  • Your end-users would not mind ' missing'  the latest row data

 

Oracle Text works with traditional data columns and also with XML, MS-Word docs and Adobe PDF files that are stored within Oracle.  Oracle Text has several index types:

 

  • CTXCAT Indexes - A CTXCAT index is best for smaller text fragments that must be indexed along with other standard relational data (VARCHAR2).

 

WHERE CATSEARCH(text_column, 'ipod')> 0;

 

  • CONTEXT Indexes - The CONTEXT index type is used to index large amounts of text such as Word, PDF, XML, HTML or plain text documents.

 

   WHERE CONTAINS(test_column, 'ipod', 1) > 0

 

  • CTXRULE Indexes - A CTXRULE index can be used to build document classification applications.

 

These types of indexes allow you to replace the old-fashioned SQL ' LIKE'  syntax with ' CONTAINS'  or ' CATSEARCH'  SQL syntax:

 

When we execute the query with the new index we see that the full-table scan is replaced with a index scan, greatly reducing execution speed and improving hardware stress:

 
Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=FIRST_ROWS
   1    0   SORT (ORDER BY) 
   2    1     TABLE ACCESS (BY INDEX ROWID) OF 'BIGTAB' 
   3    2       DOMAIN INDEX OF 'TEXT-COLUMN_IDX' 

 
 

Index re-synchronization

 

Because rebuilding an Oracle Text index (context, ctxcat, ctxrule) requires a full-table scan and lots of internal parsing, it is not practical to use triggers for instantaneous index updates. 

 

Updating Oracle Text indexes is easy and they can be schedules using dbms_job or the Oracle 10g dbms_scheduler utility package:  Oracle text provides a CTX_DDL package with the sync_index and optimize_index procedures:

 

SQL> EXEC CTX_DDL.SYNC_INDEX('text_column_idx');
SQL> EXEC CTX_DDL.OPTIMIZE_INDEX('text_column_idx','FULL');

 

For example, if you create a nightly dbms_scheduler job to call sync_index, your index will be refreshed, but the structure will become sub-optimal over time.  Oracle recommends that you periodically use the optimize_index package to periodically re-build the whole index from scratch.  Index optimization can be performed in three modes (FAST, FULL or TOKEN).

 

In sum, the Oracle Text indexes are great for removing unnecessary full-table scans from static Oracle tables and they can reduce I/O by several orders of magnitude, greatly improving overall SQL performance.
 

If you like Oracle tuning, see the book "Oracle Tuning: The Definitive Reference", with 950 pages of tuning tips and 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 dba poster
Oracle Linux poster
 
 

 

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 -  2014

All rights reserved by Burleson

Oracle ? is the registered trademark of Oracle Corporation.