- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- literals vs bind variables
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2003 01:03 AM
тАО04-16-2003 01:03 AM
What are the diffences between literals and bind variables?
How do they work?
A DBA told me that I have a high parse rate because the application is using literals variable. Is it true? Why?
thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2003 01:42 AM
тАО04-16-2003 01:42 AM
SolutionBind variables are a MAJOR way to increase performance, reduce memory needs and free up tons of CPU time.
Consider a system that queries employees by empno. You could generate 10's of thousands of queries like:
select * from emp where empno = 1;
select * from emp where empno = 2;
...
select * from emp where empno = N;
Each query is unique -- never before seen -- because the values are hard coded into it. Each needs to be parsed, security checked, optimized and so on. In many cases -- the time to parse/validate/optimizer the query is an order of MAGNITUDE greater then the time to actually execute the query. You can find your self spending 90% of your runtime parsing queries -- not executing them!
There is also an "auto binder" feature (cursor_sharing = force) whereby the kernel will automagically rewrite the queries with literals in them to use bind variables. That is, the system would see the query select * from emp where empno = 1 and
rewrite that with a bind variable in place of x and bind for you.
Using bind variables - a good system would code the query as:
select * from emp where empno = :x;
Then, everyone would use the same query plan -- saving the parsing, the optimizing and so on (its done once and saved in the shared pool). Now, we all execute the query but use a bind variable to set the empno before we open the cursor.
For you second question, consider these examples:
For example, people who do NOT use bind variables do code like this:
Statement stmt = conn.createStatement();
for( int i = 0; i < 100; i++ )
{
stmt.execute( "insert into t values ( " + i + ")" );
}
Ok, so each time through the loop that does a HARD parse of the statement.
The ONLY proper way to write that is:
PreparedStatement ps = conn.prepareStatement ("insert into t values ( ? )" );
for( int i = 0; i < 100; i++ )
{
ps.setInt( 1, s );
ps.execute();
}
Now that does 1 parse and 100 executes. The soft parse, while much better then a hard parse, is still incredibly inefficient as compared to "not parsing at all".
The soft parse -- latches the library cache just like the hard parse -- limiting scalability, decreasing response time and wasting resources.
hth
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2003 01:52 AM
тАО04-16-2003 01:52 AM
Re: literals vs bind variables
Take the following SQL statements:
select * from employees where name = "BRIAN";
select * from employees where name = "GLORIA";
Because in each statement, I am specificly specifying the name (BRIAN and GLORIA), they are two distinct statements, and the database will have to parse each statement before it can be executed.
By passing bind variables with plsql package DBMS_SQL, you can give it a different statement:
declare
sqlstatement varchar2(50);
username varchar2(10);
tmpcursor integer;
retcursor integer;
begin
username := 'BRIAN';
tmpcursor:=dbms_sql.open_cursor;
dbms_sql.parse(tmpcursor, 'select * from employees where username = :x;', dbms_sql.native);
dbms_sql.bind_variable(tmpcursor, ':x', username);
retcursor:=dbms_sql.execute(tmpcursor);
end;
/
This is of course a simple statement, but is just to show you the path that it takes. Oracle would then see the statement parsed as "select * from employees where username = :x". Because this statement would already be in memory from a previous execution, it would not have to be parsed again, but executed with a new entry for the bind variable.
A possibly simpler solution is to set "cursor_sharing = force" in the init.ora, which will force Oracle to substitute bind variables into statements. There is an associated cost with doing this though, although it can sometimes be less than the cost of rewriting portions of the application to not use bind variables.
Hope this helps,
Thanks,
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2003 08:52 PM
тАО04-16-2003 08:52 PM
Re: literals vs bind variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2003 10:40 PM
тАО04-16-2003 10:40 PM
Re: literals vs bind variables
All major database interfaces support this scheme.
Enjoy, have FUN! H.Merijn