16.10.2015 Views

Getting Startedwith pureQuery

Create successful ePaper yourself

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

D<br />

Appendix D – Static SQL in DB2<br />

D.1 What is static SQL?<br />

Static SQL means different things to different database vendors. This appendix describes<br />

static SQL and its benefits for DB2.<br />

Whenever DB2 executes an SQL statement, the system creates an access plan describing<br />

the steps it will take, and in what order, to perform the execution. For example, the system<br />

might create a plan by analyzing table statistics to decide what indexes to use and which<br />

columns to access first to perform a join.<br />

When SQL is executed dynamically, the access plan is selected on the fly, at runtime, as<br />

part of execution processing. As a result, dynamic execution of an SQL statement is<br />

usually delayed by the creation of its access plan. Even though mechanisms such as<br />

dynamic statement caching exist to improve this sequence of steps, in dynamic and<br />

improvised workloads, generating access plans can be a key negative factor in the overall<br />

system performance.<br />

Static SQL is an alternative to this dynamic execution model. When SQL is executed<br />

statically, it uses a precompiled version of the SQL statement, which means that the<br />

access path was generated before the statement was executed (see the section on<br />

“Precompile and Bind” for more information). As a result, when the SQL execution request<br />

is sent to the database, the system already knows the access plan it will use to evaluate<br />

the statement.<br />

Figure D.5 compares the runtime processing required for dynamic vs. static SQL execution<br />

modes.

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

Saved successfully!

Ooh no, something went wrong!