Databases Reference
In-Depth Information
Performance Tip
If your application makes a request only once during its life span, it is
better to use a statement than a prepared statement because it results in
only a single network round trip. Remember, reducing network commu-
nication typically provides the most performance gain. For example, if
you have an application that runs an end-of-day sales report, the query
that generates the data for that report should be sent to the database
server as a statement, not as a prepared statement.
Note that not all database systems support prepared statements; Oracle,
DB2, and MySQL do, and Sybase and Microsoft SQL Server do not. If your appli-
cation sends prepared statements to either Sybase or Microsoft SQL Server, these
database systems create stored procedures. Therefore, the performance of using
prepared statements with these two database systems is slower.
Some database systems, such as Oracle and DB2, let you perform a prepare
and execute together. This functionality provides two benefits. First, it eliminates
a round trip to the database server. Second, when designing your application, you
don't need to know whether you plan to execute the statement again, which
allows you to optimize the next execution of the statement automatically.
Read the next section about statement pooling to see how prepared state-
ments and statement pooling go hand in hand.
Statement Pooling
If you have an application that repeatedly executes the same SQL statements,
statement pooling can improve performance because it prevents the overhead of
repeatedly parsing and creating cursors (server-side resource to manage the SQL
request) for the same statement, along with the associated network round trips.
A statement pool is a group of prepared statements that an application can
reuse. Statement pooling is not a feature of a database system; it is a feature of
database drivers and application servers. A statement pool is owned by a physical
connection, and prepared statements are placed in the pool after their initial exe-
cution. For details about statement pooling, see Chapter 8, “Connection Pooling
and Statement Pooling.”
Search WWH ::




Custom Search