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.

Appendix D – Static SQL in DB2 349<br />

Once the optimal plan is identified it can be locked in for the static SQL statement. This<br />

means that for static SQL, performance can be maximized and then locked-in via a fixed<br />

access plan. For certain applications it is essential to understand and lock in performance<br />

behavior before a production system is rolled out.<br />

Dynamic SQL can approach the benefits of a predetermined access plan by using a<br />

dynamic statement cache. With a dynamic statement cache, the access plan is calculated<br />

the first time a dynamic statement is executed. The plan for the dynamic SQL string is<br />

cached by the database and reused the next time the same statement is executed. For<br />

certain applications and environments that have high dynamic statement cache hit ratios,<br />

it’s possible to approach the database performance of static SQL, by limiting the number of<br />

times access plans are calculated at runtime. However, these dynamic applications must<br />

be coded to produce maximum cache hits, and the dynamic cache environment must be<br />

well tuned, in order to get a similar advantage using a dynamic cache to the one obtained<br />

with static SQL. Static SQL is the only way to completely lock in the access plan ahead of<br />

execution time for every statement.<br />

D.3.2 Package level security<br />

In addition to a locked-in access plan, static SQL provides a different SQL security model<br />

using package level privileges. Because static SQL statements are known ahead of time,<br />

users can be given authorization only for a specific set of SQL statements. These<br />

statements are combined into a unit called a package. Static SQL statements can be<br />

logically grouped into packages according to the needs of the security model. Users are<br />

only granted permission to execute packages containing SQL that matches their access<br />

level. With package level privileges, users cannot execute any SQL statements unless the<br />

statements are contained in the packages the users have been granted the privilege to<br />

execute.<br />

This provides an important alternative to table-based privileges, which is the common<br />

security model for dynamic SQL. With dynamic SQL, privileges are granted for specific<br />

table operations, such as read or update on a table. The risk with granting table privileges<br />

is they do not limit users to executing specific SQL statements. Users could potentially<br />

execute any query or any update SQL statement on a table, once they have been granted<br />

read or update privileges on the table. Even though a user’s application may be hardcoded<br />

with a specific SQL string, a malicious user could potentially use table privileges to<br />

execute dynamic SQL that is not contained within their application. Dynamic SQL injection<br />

is one form of malicious behavior that takes advantage of this fact. Static SQL, with a<br />

previously designed fix set of packages, and package level privileges, prevents this<br />

unwanted behavior. Only the package owner, not each user, needs to be granted table<br />

level privileges for static SQL. The package owner is usually the administrator who binds<br />

the packages. Therefore good static package design can eliminate the risk of a user<br />

maliciously executing unwanted SQL.

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

Saved successfully!

Ooh no, something went wrong!