DBA Tips Archive for Oracle


Sharing SQL Statements - (Oracle 8i)

by Jeff Hunter, Sr. Database Administrator

Prior to Oracle 8i, the database would parse and store the following SQL statements as two distinctly different SQL statements in the shared pool:

SQL> SELECT * FROM user_names WHERE name='Jeff' AND county = 'Butler';

SQL> SELECT * FROM user_names WHERE name='Melody' AND county = 'Butler';

Oracle 8i introduces a new init.ora parameter called cursor_sharing that allows you to specify how SQL statements get parsed by the database. Setting cursor_sharing to its default setting of exact allows the database to behave in its traditional manner. A setting of exact would treat the two SQL statements above as two distinctly different SQL statements in the shared pool.

You can however change the setting of cursor_sharing to force in the init.ora file, which allows the database to substitute any hard-coded values in the WHERE clause with temporary bind variables during the parse phase. The two SQL statements listed above would be parsed and stored in the shared pool as a single statement:

SQL> SELECT * FROM user_names WHERE name=:SYS_B_0 AND county = :SYS_B_1;
Having this statement stored as one SQL statement in the shared pool will increase the chance the database can reuse the parsed SQL statement. This will have a positive effect when considering how to reduce latch contention on the shared pool.

Do not consider this new feature in Oracle 8i a permanent fix to your tuning efforts. It was designed to give developers and DBAs only limited relief in solving performance issues in a poorly designed database application. The new cursor_sharing = force feature will not benefit situations where other SQL differences exist like inconsistent spacing, case usage and ordering of column names. Addressing SQL problems at the source in your organization is the only long-term solution for providing a well tuned database environment.

Copyright (c) 1998-2017 Jeffrey M. Hunter. All rights reserved.

All articles, scripts and material located at the Internet address of http://www.idevelopment.info is the copyright of Jeffrey M. Hunter and is protected under copyright laws of the United States. This document may not be hosted on any other site without my express, prior, written permission. Application to host any of the material elsewhere can be made by contacting me at jhunter@idevelopment.info.

I have made every effort and taken great care in making sure that the material included on my web site is technically accurate, but I disclaim any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on it. I will in no case be liable for any monetary damages arising from such loss, damage or destruction.

Last modified on
Friday, 20-Jan-2006 12:37:00 EST
Page Count: 9478