3 ms·
This article does not touch on speed that much, but saving your database from reparsing the same SQL over and over is a great thing. Bind variables should be u
by Femur 17y ago
This article does not touch on speed that much, but saving your database from reparsing the same SQL over and over is a great thing. Bind variables should be used in the place of literals whenever possible.
There is a gotcha with this though. Say that you have a table with a column having three distinct values with the following distribution:
"John" - 80%
"Sally" - 10%
"Mary" - 10%
If the first time your database parses a statement where the bind variable has the value of "John", then the shared SQL will have an execution plan optimized for values of "John". Obviously, in this case, using an index to search on that column for values of "John" would not be worth it. However, you absolutely would want an index when searching for values of "Mary". So beware! Your prepared SQL can be suboptimal!
(Note: I speak to the Oracle DBMS of versions 9.2 through 11 only)
- ElmosEverywhere 17y agoFACE!