Home » RDBMS Server » Performance Tuning » Bind vs non-Bind query performance
Bind vs non-Bind query performance [message #147709] Sat, 19 November 2005 18:23 Go to next message
sbushong@cox.net
Messages: 1
Registered: November 2005
Junior Member
Does anyone have experience with queries that perform much worse when using bind variables than when using specific values in the "where" clause? We have a TCL (oratcl OCI) based application that has some fairly complicated queries. We almost always use variable binding, but have come across a few queries that perform much better (instantaneous response vs many seconds or even minutes) when we remove the bind variables and just submit the queries with actual values. These are always dynamically constructed queries with "where" values unknown until actual query execution.
Re: Bind vs non-Bind query performance [message #147721 is a reply to message #147709] Sun, 20 November 2005 00:45 Go to previous messageGo to next message
scottwmackey
Messages: 515
Registered: March 2005
Senior Member
Yes, all the time. I know for certain that Oracle creates different explain plans when the parameters are hard coded, often giving exactly the different results you are finding. As I hear it, if Oracle knows the values it is going to process, it looks at different statistics for the indexes and can better decide which one to use. I don't know exactly how that works, but I know it happens...all the time.
Re: Bind vs non-Bind query performance [message #147747 is a reply to message #147721] Sun, 20 November 2005 16:33 Go to previous messageGo to next message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
What happens is that the CBO looks at the histograms for the columns and determines whether there is likely to be a lot of matching rows or just a few for the given constant value.

With bind variables, it has to go on averages alone.

A classic example is a table of payments. Paid transactions will have a CHEQUE_NO set to a unique value for the table, but unpaid transactions may have a default value, eg. 0.

A query WHERE CHEQUE_NO = 0 would be better performing a Full Table Scan, whereas WHERE CHEQUE_NO = 12345 would be better using an index. Using histograms, Oracle can tell that the value "0" has terrible selectivity and adjusts the plan accordingly. Using bind variables (WHERE CHEQUE_NO = :1), the CBO will go on averages, which means using the index, even though the bind value may be 0.

This shows a bit more on histograms.

_____________
Ross Leishman

Re: Bind vs non-Bind query performance [message #147799 is a reply to message #147709] Mon, 21 November 2005 02:38 Go to previous messageGo to next message
dmitry.nikiforov
Messages: 723
Registered: March 2005
Senior Member
Seems you are using Oracle 9i. This release uses techique of
bind variable value pick-up. This can cause some confusion when
variable value doesn't give the representative plan. Use V$SQL_PLAN view to look on cached execution plan for your query with binding variable.

Rgds.
Re: Bind vs non-Bind query performance [message #147858 is a reply to message #147799] Mon, 21 November 2005 06:21 Go to previous messageGo to next message
Frank
Messages: 7901
Registered: March 2000
Senior Member
dmitry.nikiforov wrote on Mon, 21 November 2005 09:38

...This release uses techique of
bind variable value pick-up.



Don't you mean bind variable peeking? (If so, it makes searching/googling a lot easier)

hth
Re: Bind vs non-Bind query performance [message #147864 is a reply to message #147858] Mon, 21 November 2005 06:59 Go to previous message
dmitry.nikiforov
Messages: 723
Registered: March 2005
Senior Member
Oh, thank you Frank for correction.
Sorry, my mistyping of course. Embarassed
Need more caffeine. Laughing

Rgds.
Previous Topic: Difference in Toad & Oracle Report Builder
Next Topic: Informatica
Goto Forum:
  


Current Time: Sat Nov 23 18:03:03 CST 2024