05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 1 ■ DEVELOPING SUCCESSFUL ORACLE APPLICATIONS 45<br />

The plans were subtly different (sometimes you’ll find them to be radically different); they<br />

did different amounts of work. So, just turning on cursor sharing is something to do with great<br />

trepidation (well, testing really—you need to test this). It will potentially change the behavior<br />

of your application (e.g., the column widths) <strong>and</strong> because it removes all literals from SQL,<br />

even those that never really change, it can have a negative impact on your query plans.<br />

Additionally, I have proven that while CURSOR_SHARING = FORCE runs much faster than<br />

parsing <strong>and</strong> optimizing lots of unique queries, I have also found it to be slower than using<br />

queries where the developer did the binding. This arises not from any inefficiency in the cursor<br />

sharing code, but rather in inefficiencies in the program itself. In many cases, an application<br />

that does not use bind variables is not efficiently parsing <strong>and</strong> reusing cursors either. Since the<br />

application believes each query is unique (it built them as unique statements), it will never<br />

use a cursor more than once. The fact is that if the programmer had used bind variables in the<br />

first place, he or she could have parsed a query once <strong>and</strong> reused it many times. It is this overhead<br />

of parsing that decreases the overall potential performance.<br />

Basically, it is important to keep in mind that simply turning on CURSOR_SHARING = FORCE<br />

will not necessarily fix your problems. It may well introduce new ones. CURSOR_SHARING is, in<br />

some cases, a very useful tool, but it is not a silver bullet. A well-developed application would<br />

never need it. In the long term, using bind variables where appropriate, <strong>and</strong> constants when<br />

needed, is the correct approach.<br />

■Note There are no silver bullets—none. If there were, they would be the default behavior <strong>and</strong> you would<br />

never hear about them.<br />

Even if there are some switches that can be thrown at the database level—<strong>and</strong> they are<br />

truly few <strong>and</strong> far between—problems relating to concurrency issues <strong>and</strong> poorly executing<br />

queries (due to poorly written queries or poorly structured data) cannot be fixed with a<br />

switch. These situations require rewrites (<strong>and</strong> frequently a re-architecture). Moving data files<br />

around, changing the multiblock read count, <strong>and</strong> other database-level switches frequently<br />

have a minor impact on the overall performance of an application. Definitely not anywhere<br />

near the two, three, . . . n times increase in performance you need to achieve to make the<br />

application acceptable. How many times has your application been 10 percent too slow? No<br />

one complains about 10 percent too slow. Five times too slow, <strong>and</strong> people get upset. I repeat:<br />

you will not get a five times increase in performance by moving data files around. You will only<br />

achieve this by fixing the application, perhaps by making it do significantly less I/O.<br />

Performance is something you have to design for, to build to, <strong>and</strong> to test for continuously<br />

throughout the development phase. It should never be something considered after the fact. I<br />

am amazed at how often people wait until the application has been shipped to their customer,<br />

put in place, <strong>and</strong> actually running before they even start to tune it. I’ve seen implementations<br />

where applications are shipped with nothing more than primary keys—no other indexes<br />

whatsoever. The queries have never been tuned or stress-tested. The application has never<br />

been tried out with more than a h<strong>and</strong>ful of users. Tuning is considered to be part of the installation<br />

of the product. To me, that is an unacceptable approach. Your end users should be<br />

presented with a responsive, fully tuned system from day one. There will be enough “product

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!