Professional Documents
Culture Documents
Solving The SQL Tuning Problem Secrets of Quest SQL Optimizer Technical Brief 26740
Solving The SQL Tuning Problem Secrets of Quest SQL Optimizer Technical Brief 26740
Solving The SQL Tuning Problem Secrets of Quest SQL Optimizer Technical Brief 26740
Tuning Problem
Secrets of Quest® SQL Optimizer
0 a1 a1 a a 0 C.f2 = 0
0 a2 a2 a b 1
1 b1 a3 a c 2
1 b2 a4 a d 3
2 c1 b1 b e 4
2 c2 b2 b f 5
Figure 1. The driving path starts from table C to table B, which matches four rows from
table B. Then those four rows are matched to the rows in table A. The rows highlighted
in gray in table B show the two records that caused extra scan operations using this
driving path.
2
Table A Table B Table C
0 a1 a1 a a 0
A.f2 = 0
0 a2 a2 a b 1
1 b1 a3 a c 2
1 b2 a4 a d 3
2 c1 b1 b e 4
2 c2 b2 b f 5
Figure 2. The driving path starts from table A to table B, which matches two rows. Then
those two rows are used to match to the rows in table C. So with this driving path, no
unnecessary table scans are performed. Though starting with a condition of lower
selectivity, the overall scan operations are more optimistic.
3
Data dictionary
External SQL
rewriter
Problematic SQL Recursive SQL
Identify problematic
transformation
SQL from
program source
Eliminate duplicate
execution plans
Figure 4. Quest SQL Optimizer is an external SQL rewriter that mimics human expertise
to rewrite SQL statements to help the database's internal SQL optimizer make
better decisions.
Plan J Plan I Plan H Plan G Plan F Plan E Plan D Plan C Plan B Plan A
Figure 5. Relationships with SQL syntax changes and the execution plan generation
4
CHANGING SQL SYNTAX TO original set of plans. If one of the execu-
IMPROVE SQL PERFORMANCE tion plans from those rewritten SQL has
better performance, the programmer can
Limitations of internal SQL
use the new syntax to replace the orig-
rewrite functionality
inal SQL in the source to improve the
Due to limitations in the database's inter- SQL performance without changing the
nal SQL rewrite capability, it cannot results. This is what we call SQL tuning
transform a SQL statement into very without creating new indexes or data-
many semantically equivalent SQL alter- base configuration changes.
natives. Therefore, it is not possible for it
to generate every possible way to rewrite SQL tuning experts may find that some
a SQL statement. For example, assume rules of SQL syntax restructuring improve
that five SQL statements from SQL 1 to SQL statements in certain environments.
SQL 5 are semantically equivalent but For example, a nested loop join access- The database's internal
syntactically different. The database SQL ing a small table first and using an index
search on a large table is normally better
SQL rewrite capability
optimizer may generate a different set of
execution plans accordingly (see Figure than joining the data from the large cannot transform
5). For each set of execution plans (SQL 1 table to the small table. But for complex
has Plan A, B, C), the database SQL opti- SQL statements with many table joins, a SQL statement
mizer will carry out a cost estimation and a general rule like that may be hard to into very many
will execute the execution plan with the apply. This is especially true in situations
lowest cost. If the database SQL opti- with many join operations, where sorting semantically equivalent
mizer fails to select a good execution and filtering methods are combined into
plan due to an inaccurate cost estimation one long and complex execution plan.
SQL alternatives.
or because it is limited by the number of
execution plans generated, the corre- Quest SQL Optimizer’s Recursive
sponding SQL statement’s performance SQL Transformation Engine
will be degraded. The Recursive SQL Transformation tech-
nology used in Quest SQL Optimizer
In order to rectify this situation, a simulates human SQL transforma-
programmer can rewrite the original SQL tion techniques. It incorporates a set of
multiple times. For each rewritten SQL, transformation rules to transform SQL
the database SQL optimizer creates a statements on a section-by-section basis.
set of execution plans. Based on this This replaces the trial-and-error method
new set of execution plans, the data- used by a person to rewrite the syntax of
base SQL optimizer may select to use an a SQL statement.
execution plan that was not found in the
5
Rules
Protector Transform
Protector Transform
Protector Transform
Protector Transform
Each transformation rule in the opti- results as the original SQL. When a SQL
mization engine is independent from statement is transformed by one rule
The Recursive SQL one another, like a capsule; the rule’s to produce a new SQL syntax, the new
Transformation Engine ‘capsule’ can be opened only when all
necessary conditions are satisfied (see
syntax may now satisfy the requirements
of another rule; hence, transforma-
replaces the trial- Figure 6). This guarantees the seman- tion is carried out in a recursive manner
tic equivalence of the rewritten SQL (see Figure 7).
and-error method statements so they produce the same
used by a person to
rewrite the syntax of
a SQL statement.
SQL
6
SELECT *
FROM A
WHERE A.C1 IN (SELECT B.C1
FROM B
WHERE EXISTS (SELECT ‘x’
FROM C
WHERE B.C2 = C.C2 ))
IN to EXISTS EXISTS to IN
EXISTS to IN IN to EXISTS
7
Figure 9. If a programmer tells you that table B is not necessary, the SQL on the left can
be rewritten into a SQL statement that eliminates table B and joins only tables A and C.
8
Example 1
Transform
Example 2
Transform
Figure 10. Quest SQL Optimizer includes rules to correct common but inefficient
practices in writing SQL.
For Example 1 in Figure 10, the operation, I have seen a SQL statement (in an
+10, was applied to the emp_id column. electric power company’s applica-
This causes a full table scan since 10 tion) that involved more than a 13-table
must be added to the emp_id value for join. If you calculate all possible join
each row of the table. By transforming paths, the permutation would be 13!=
the syntax to subtract 10 from the other 6,227,020,800. This would almost
side of the operation, it makes it possible require a supercomputer to do an opti-
for an index to be used. mization before the execution of the SQL
statement. Consequently, the database
For Example 2 in Figure 10, Quest SQL SQL optimizer does a rough estima-
Optimizer will check the emp_id to deter-
mine if the column was defined as NOT
tion and runs the SQL immediately, When there are many
which is much faster than trying to do a
NULL. If it is a NOT NULL field, the NVL comprehensive analysis to find the very table operations in
function can be eliminated. This trans- best table join path before beginning
formation may also eliminate a full table the execution.
a SQL statement,
scan by making it possible for an index there is no way for
to be used.
select * from the database SQL
JOIN PATHS T1,T2,T3,T4,T5,T6,T7,T8 optimizer to evaluate
Why evaluating join paths where T1.key=T2.key
is complicated and T2.key=T3.key all possible paths for
and T3.key=T4.key
The join path is the order in which the
and T4.key=T5.key
joining the tables.
data is retrieved from two or more tables.
and T5.key=T6.key
Theoretically, the database SQL opti-
and T6.key=T7.key
mizer should find the best path to join
and T7.key=T8.key
two or more tables for a given SQL state-
ment. The problem is that when there are
many table operations in a SQL state-
ment, there is no way for the database Why join paths matter
SQL optimizer to evaluate all possible
The basic nested loop join operation
paths for joining the tables, given the
is supported by most RDBMS since it
limited amount of time it has to select an
requires less memory and temporary
execution plan. Let’s take a look at the
space. Normally, it provides faster data
following SQL statement. It involves join-
response time than other join opera-
ing eight tables, and each table has a
tions. However, the path of a nested loop
relationship with the seven other tables.
join will significantly affect the speed of
If we consider only the Nested Loop join,
the join operation. Let’s use a two-table
the total permutation is 8!= 40,320 possi-
join as an example to understand how
bilities. So, you can see it would take a
this works:
long time for the database SQL optimizer
to evaluate all possible paths.
9
select * from A,B Let’s assume that A.key and B.key are
unique B-Tree indexed
where A.key = B.key (assume B-tree has two nodes for each parent)
A table has 100,000 records
B table has 1000 records
If we focus on the Nested Loop join oper- in a real live application, the SQL state-
ation and assume these two tables are ments can be far more complicated than
cached in memory, we can calculate the a simple two-table join operation. For
number of operations to retrieve both example, the key for both tables may
tables for the two possible join paths: not be unique. There may be some filter-
ing criteria for both tables that make it
The path from table A to table B means so no histogram can be referenced. This
that we open table A, looking at each makes it so that the database SQL opti-
row to then use an index to search for mizer cannot accurately estimate the cost
matching rows in table B: of each join path. Human expertise is
needed to solve the problem when the
Number of operations (A→B) = 100,000 * database SQL optimizer chooses a poor
RoundUp(LN(1000) / LN(2)) / 2 = 100,000 * execution plan.
10 / 2 = 500,000
For other join methods, such as hash
Where LN(1000)/LN(2) is the height of the join or sort merge, the join path may not
B-tree for index of B.key, half the height significantly affect the SQL speed for a
Quest SQL Optimizer is assumed as an average searching two-table join. But in some situations, like
depth for a specific record from B.key.
is not attempting to those illustrated in Figure 1 and Figure 2,
you may find that the join path still plays
directly find the best The path from table B to table A means
that we open B table, looking at each
a major role in the performance of a
alternative SQL rewrite. row to then use an index to search for
SQL statement.
matching rows in table A: How to control the join path
Number of operations (B→A) = 1000 * The design concept used in Quest SQL
RoundUp(LN(100,000) / LN(2)) / 2 = 1000 Optimizer to apply recursive SQL trans-
* 17 / 2 = 8,500 formation rules is different from common
SQL tuning tools or human SQL tuning
Where LN(100,000)/LN(2) is the height knowledge. Quest SQL Optimizer is
of the B-tree for index of A.key, half the not attempting to directly find the best
height is assumed as an average search- alternative SQL rewrite like a human
ing depth for a specific record from A.key. expert would. Quite frankly, no human
knowledge can address all possible
According to the calculation, you will combinations of SQL syntax, hardware
find that the path from B→A is around configurations and software configu-
500,000/8,500, or ~59 times faster than rations—or predict the behavior of the
the speed of A→B. This explains why database SQL optimizer—to immediately
some SQL statements with a wrong driv- know what the best SQL syntax is for a
ing path can be tuned up to hundreds of given SQL statement.
times faster.
To control a join path, we cannot tell the
Many programmers may have learned internal database SQL optimizer which
from experience to use the small table path is the best one to select. Instead,
to drive a bigger table for a nested loop we add something to the syntax of the
join produces faster results. When a SQL SQL statement that causes an increase to
statement is simple and natural, it is likely the cost of the current join path selected
a programmer will write the SQL state- by the internal database SQL optimizer.
ment using the best driving path. But
10
A B
= A B
B A
11
A B
For Microsoft SQL Server and IBM DB2 By changing the syntax to A.key + 0
UDB, the following syntax will increase and B.key + 0, three of the six table join
the cost for a specific driving path. permutations have an increase in cost: C
→ B→A, A→C→B and B→A→C. This leaves
Example: a three-table join three remaining paths available for the
SQL database optimizer to consider:
How can we guide the Now let’s use a three-table join
A→B→C, B→C→A, and C→A→B. It will select
SQL statement to illustrate a more
database SQL optimizer complicated scenario. the path of our choice, A→B→C, only if the
estimated cost is the lowest cost; other-
to select a preferred For a three-table join SQL statement, the wise, the database SQL optimizer will opt
for some other path.
path by rewriting database SQL optimizer will consider all
the permutations, which is 3!=6. Assume
the SQL syntax? that B→A→C is the lowest cost path and With the lowering of the cost of today’s
therefore is the path selected by data- CPU and memory, the database SQL
base SQL optimizer. How can we guide optimizer designers are able to lower the
the database SQL optimizer to select cost of hash and sort merge joins, which
a preferred path by rewriting the SQL use more processing power and memory
syntax? If we want to guide the database than the nested loop join. This means
SQL optimizer to consider a path from that database SQL optimizer will more
A→B→C, we can try the syntax shown often select the hash or sort merge join
in Figure 13. instead of taking the risk to do a nested
loop join, especially when the table
size is small.
A B
Figure 13. Rewriting the SQL syntax to guide the database SQL optimizer to select a
preferred path.
12
VAR
A B
Example 1
Transform
Example 2
Transform
Remark
This illustration assumes that emp_id is defined as NOT NULL and it is indexed. -1E9
is the lowest possible value and +1E9 is the highest possible value that can be entered
into emp_id based on the length of the field.
13
For Oracle Enable index search for emp_dept
Transform
Transform
Transform
Transform
Remark
Since IBM DB2 UDB v8 and Microsoft SQL Server 2005 have stronger internal SQL rewrite abilities
in their latest versions, the coalesce (col,col) can be resolved by the database SQL optimizer during
parsing to a Case operation. Therefore, the index that you are trying to disable will remain in the
execution plan. A deeper nested coalesce (coalesce (col,col),col) can be used to overload the
parser and increase the specific cost weighting.
Figure 16. A transformation that can be used to enable any one of the indexes for a
SQL statement having multiple indexes that can be used to search a table.
For a SQL statement having multiple The other technique for disabling the index
indexes that can be used to search a is to use the COALESCE operation, which
Quest SQL Optimizer table, the transformation shown in Figure in this case, does nothing to the value in
also has rules for 16 can be used to enable any one of
the indexes.
the field. Because it must be performed for
each row in the table, it disables the index
different platforms and causes a full table scan or enables a
To disable the index on the numeric different index to be used.
in order to deal with emp_id field, zero was added to the
field. This disables the index since zero
the behavior of the must be added to emp_id for each row,
DEALING WITH THE BEHAVIOR
OF EACH PLATFORM’S
SQL optimizer for requiring a full table scan or enabling a SQL OPTIMIZER
different index to be used.
each database. Quest SQL Optimizer also has rules for
The same process is used for the char- different platforms in order to deal with
acter field of emp_dept where nothing, the behavior of the SQL optimizer for
represented by '' (single quotes with each database. In order to understand
no value), was concatenated to the the theory behind some of these trans-
field. This also disables the index since formations, you may need to have an
the concatenate operation must be in-depth understanding of database opti-
performed for each row, thereby requir- mization theories, the design approach
ing a full table scan or enabling a to optimization each database vendor
different index to be used. has incorporated into the database SQL
optimizer, and the platform-specific opti-
mizer functions.
14
Here is a puzzling transformation: The • The costing algorithm fails to take into
original SQL statement uses a range account the configuration of different
scan of the employee table with the machines’ I/O thru-put, CPU processing,
condition “emp_id > 123456.” Both IBM memory speed and other system resources.
DB2 UDB and Microsoft SQL Server have For Microsoft SQL Server, if you want
an intelligent algorithm that can preview to rectify the problem, you can use the
the value “123456” before the execu- INDEX hints to force the database SQL
tion plan is generated. Consequently, if optimizer to pick up an index. But for IBM
For the nested loop join
“emp_id>123456” returns a small subset
of records from the employee table, the
DB2 UDB, it is a little bit more difficult. case, the path plays
database SQL optimizer should gener- Let’s look at the transformations in an important role in
ate an execution plan that uses an Figure 17, which use a dummy opera-
index search. tion COALESCE (123456,123456) or add determining the speed
In contrast, if the SQL statement returns
+0 to the literal 123456. The purpose of of the SQL; for hash
these dummy operations is to hide the
almost all the records from the table, the value of 123456, so Microsoft SQL Server join or sort merge join
database SQL optimizer should generate or IBM DB2 UDB will not be able to see
an execution plan using a full table scan the value while parsing the SQL state-
cases, the join path, may
to save the time of retrieving extra index
pages. This works fine in most cases;
ment. Therefore, they will make a rough not be that significant.
estimation when they do not know the
however, there are several factors that actual value. Erring on the side of caution,
can cause the database SQL optimizer to the database SQL optimizer will normally
make a mistake. Three factors are: select the execution plan that uses an
• The statistics are not up to date. index search.
Example 1
Transform
Transform
Remark
Since IBM DB2 UDB and Microsoft SQL Server have stronger internal SQL rewrite abilities in
their latest versions, the coalesce (123,123) can be resolved by the database SQL optimizer
during parsing to a Case operation. Therefore, the index you are trying to disable will remain
in the execution plan. A deeper nested coalesce (coalesce(123,123),123) can be used to
overload the parser and increase the specific cost weighting.
15
Example for all platforms
Transform
Remark
This transformation is valid only if there are no group, set or user-defined stored functions
call in the IN sub-query.
In modern RDBMS SQL optimizers, the Upgrading the database SQL optimizer
IN sub-query shown in Figure 18 can is a risky exercise for database vendors.
normally be transformed to a join SQL No matter how good a new version of
statement, which means the join path the database SQL optimizer is, it is going
can be either from A_B or B_A. For the to have some negative impact. For exam-
nested loop join case, the path plays an ple, if a new version of the database SQL
important role in determining the speed optimizer can fix 50 percent of old SQL
of the SQL; for hash join or sort merge statements performance problems, but
join cases, the join path, may not be in the meantime it introduces 5 percent
that significant. of all new performance problems for
existing good SQL statements, mathe-
The transformation rule shown in Figure matically, it is 10 times better than the
18, which adds a GROUP BY clause, old version. It should be a good deal to
Oracle provides a full serves two purposes: commit to the upgrade. Most systems are
set of optimization • The first purpose is to force the
already running on an “adopted” status,
which means users have accepted what
hints to help users sub-query to be processed individually.
If the original execution plan is a nested
they have, they know which functions
rectify individual SQL loop join, after the transformation, the are running slow, the database tuner may
already have changed the system config-
execution plan will normally be changed
performance problems. to a hash or a sort merge join. uration to address the problems and
sometimes even the users’ daily oper-
• The additional GROUP BY function will ations are changed to accommodate
also trim down the result set from B key
those slow SQL processes.
(if B key is not unique) and the duplicate
records will be eliminated first. This will
If there are any changes after upgrad-
sometimes help to improve join speed.
ing to a new database version, I think you
OPTIMIZATION HINTS will agree that a 50 percent improvement
will not stop the users from complain-
What are optimization hints? ing about the 5 percent of new problems.
Most database vendors provide optimiza- So, that is why database vendors need
tion hints to enable the user to influence to provide optimization hints to let users
decisions made by the database SQL fix problems at the individual SQL state-
optimizer as to which execution plan ment level and not at the database
to choose. Oracle provides a full set of SQL optimizer global level. This trend is
optimization hints to help users rectify becoming more popular among database
individual SQL performance problems, vendors. Sybase Adaptive Server and
making it the most open of all the data- Microsoft SQL Server provide more plan
base platforms. This approach admits the forces (like Oracle optimization hints) in
database SQL optimizer cannot guaran- their new versions. IBM DB2 UDB does
tee every SQL will perform well. not provide any optimization hints, but
it does provide optimization classes to
16
control the intelligence levels of execu- will be used or how good the result will
tion plans generated by the database be if the hint is applied.
SQL optimizer. Unless the database
SQL optimizer can guarantee that each Quest SQL Optimizer’s approach
execution plan it generates is the best This is why Quest SQL Optimizer takes
execution plan for each unique data- a different approach and does not
base environment, we like the approach follow the knowledge-oriented SQL
that Oracle provides, which gives us the tuning approach. The SQL Transforma-
opportunity to help the database SQL tion Engine will try most of the possible
optimizer choose the best execution plan combinations for rewriting the SQL
with the optimization hints. syntax, combined with optimization hints,
to explore the potential of a database
How hints work with SQL optimizer.
SQL transformation
Optimization hints are used to guide QUEST SQL OPTIMIZER FORECAST
the database SQL optimizer to select
a specific method preferred by the
Is SQL optimization an It is actually quite often
unsolvable problem?
user to process the SQL statement. But that the database
sometimes the SQL statement’s syntax In computability theory, there is a famous
prevents the database SQL optimizer decision problem called the halting prob- SQL optimizer will not
from using the method specified by the lem, which can be informally stated as
follows: Given a description of a program
follow your instruction
user. In this case, the database SQL opti-
mizer will ignore the instruction given and its initial input, this determines due to the limitation
by the user. whether the program, when executing
the input, will ever halt (complete); the of the SQL syntax.
Let’s look at the examples in Figure 19. alternative is that it runs forever with-
out halting. In 1936, Alan Turing proved
In reviewing the execution plans, the that a general algorithm to solve the halt-
example in Figure 19 shows you that the ing problem for all possible inputs cannot
USE_MERGE hint does not cause the exist. It is said that the halting problem is
Oracle SQL optimizer to generate a sort undecidable over Turing machines.
merge join for this SQL statement. It is
actually quite often that the database Perhaps you find the halting problem is
SQL optimizer will not follow your instruc- similar to one of RDBMS SQL optimiza-
tion due to the limitation of the SQL tion problems. Actually, there are two
syntax. For complicated SQL statements, major problems that modern RDBMS SQL
the situation is even more complex as we optimizers encounter today.
may not be able to tell whether the hints
Figure 19.
17
SQL
Hints permutation
Figure 20. How optimization hints work with recursive SQL transformation
• The limited size of the plan space (the Accurate cost estimation
number of execution plans can be versus plan space
The SQL Transformation investigated during SQL optimization)—
Because the database SQL optimizer The goal of a good database SQL opti-
Engine will try most has to do real-time optimization, it is mizer is not only to provide accurate cost
estimation for SQL statements, but to
of the possible impossible for the database SQL optimizer
to do an exhaustive plan space search generate more internal execution steps
combinations for (search all possible execution plans
internally); otherwise, the optimization
to compose more execution plans. More
internal execution plans mean the data-
rewriting the SQL time will be much longer than the time base SQL optimizer has a larger plan
it takes to execute the SQL statement
space during SQL optimization.
syntax, combined even with a bad execution plan.
with optimization • The limited accuracy of the cost The following is an example to show you
estimation algorithm—After the the relationship between plan space
hints, to explore the database SQL optimizer has generated and cost estimation. Consider how you
all the internal SQL rewrites and their travel to your office and suppose you
potential of a database corresponding execution plans, the only have one route to get there. If the
SQL optimizer. database SQL optimizer uses the cost
estimation algorithm to choose the
only way you go to the office is jammed
due to weather or traffic conditions, you
theoretical best execution plan, the one
probably will not be able to get to your
with the lowest cost, to execute. We
office on time.
can use tables, indexes, histograms,
assumptions and other statistics to
Consequently, most people have multi-
estimate the cost of an execution plan. The
problem is lot to tell whether the SQL will ple routes (plan space) in mind. Every
halt; rather, we are facing a more difficult morning, based on weather and traffic
problem of determining how long a query conditions, they select the best route (cost
will run with a specific execution plan. estimation) to the office. The more routes
Database vendors have spent a lot of effort they have in mind, the higher the possi-
in this area, but the fact remains that we still bility they can overcome more complex
have to tune SQL statements ourselves. traffic and weather conditions.
18
The point is, with more possible execu- One possible solution to address the cost
tion plans, every morning they will and plan space problem is to build a SQL
spend more time thinking about which tuning agent with a query base statistics
path is the best way to go to their office. database that offloads the original SQL
As the number of routes increase, the optimizer from real-time optimization. The
chance they select a non-optimal path agent should be running during nonpeak
gets higher. hours to review all executed SQL state-
ments (or resource-intensive SQL). For
This problem is similar to what the data- each SQL statement, the agent should
base SQL optimizer faces. The accuracy generate more execution plans than
of the database SQL optimizer’s cost the database SQL optimizer generates,
estimation is opposite to the size of plan since the real-time SQL optimizer cannot
space that the database SQL optimizer spend much execution time during real-
generates. The bigger the plan space, time optimization. For each execution
the easier it is for the optimizer to select plan it generates, the statistics can be
a non-optimal execution plan. That is why collected by a test run or partial test run
Oracle’s SQL statement performance of the query. Of course, the database
always has room for improvement, since SQL optimizer still faces a lot of prob-
Oracle has a relative larger plan space. lems today that would have to be solved
by a SQL tuning agent. But the beauty
WHAT ABOUT A SELF- of a SQL tuning agent is that it has no
LEARNING SQL OPTIMIZER? response time limitation. Any complex
At least two database vendors are estimation or test run algorithm can be
trying to build self-learning SQL optimiz- built piece by piece in the agent.
ers. The idea is to use actual statistics
THE ROLE OF QUEST SQL
The bigger the plan
from executed SQL statements to rectify
the future cost estimation of the same OPTIMIZER IN THE FUTURE space, the easier it
or similar SQL statements. It seems
like a good idea, but you will find their
As long as the database execution plan is for the optimizer to
space is being enlarged and more SQL
self-learning SQL optimizer is either optimization controls are provided by select a non-optimal
turned off by default or built as an individ- database vendors, you will have more
ual tuning advisor. Of course, we cannot room to improve the performance of
execution plan.
say they will not provide a better and your SQL and to maximize the power
fully automatic solution in the future. But of your database. Quest SQL Optimizer
the fact is this technology is not mature will continue to play an important role
enough today to be turned on auto- by helping you optimize your SQL state-
matically. Furthermore, database SQL ments. Furthermore, database vendors
optimizers have a lot of problems pend- are becoming more aware of the limita-
ing that still need to be solved. They tions of their SQL optimizers' intelligence.
should not just focus on the error of cost New features in the database upgrades
estimation without taking care of the are normally coming out faster than inter-
small plan space problem. nal SQL optimizer upgrades.
19
without requiring a change to the source abstract plans are generated for poorly
code. It is a source-less SQL tuning tech- performing SQL. Once you are satis-
nique that is very important to package fied with a specific abstract plan, you can
users since they do not own the source save it with the SQL text into an Adaptive
code. For example, Oracle provides Server database. The next time the same
Stored Outlines and SQL Profile; Sybase SQL is received by the Sybase Adap-
Adaptive Server provides Abstract Plan; tive Server SQL optimizer, the stored
and Microsoft SQL Server provides Plan abstract plan will be used to generate
Guide in Microsoft SQL Server 2005. You the expected execution plan. The beauty
For Sybase Adaptive can see that the mainstream database of this approach is that users do not
vendors are going in the same direc- need to change their source code: the
Server, we provide tion to help users tune SQL without the abstract plan can be changed any time
abstract plan tuning, need to change the source code. But the to accommodate database configuration
problem is that those new features are changes or upgrades. Package providers
in which alternative difficult to use unless you have in-depth can keep one source to fit different data
knowledge of SQL optimization. I believe distributions for different size companies.
abstract plans are many people cannot accurately guide
generated for poorly the database SQL optimizer to generate Similar technology can be imple-
mented into the Oracle and Microsoft
a good execution plan for a complicated
performing SQL. SQL statement. SQL Server platforms in the near future.
It is a new generation of source-less
Since Quest SQL Optimizer is an exter- SQL tuning tools that enable you to
nal SQL rewriter that relies only on the deploy your tuning instruction for specific
feedback of the execution plan from the SQL statements over various database
database SQL optimizer, the Quest SQL environments.
Optimizer Engine can generate alterna-
tive syntax to influence the database SQL With Quest SQL Optimizer, you can
optimizer to pick up a better execution reduce risk, eliminate manual work and
plan for a SQL statement. For Sybase gain more time for other critical tasks.
Adaptive Server, we already provide Stop wasting hours on SQL tuning and
abstract plan tuning, in which alternative put Quest SQL Optimizer to work for
you today.
20
ABOUT QUEST
At Quest, our purpose is to solve complex problems with simple solutions. We accomplish this with a philosophy focused on great
products, great service and an overall goal of being simple to do business with. Our vision is to deliver technology that eliminates the
need to choose between efficiency and effectiveness, which means you and your organization can spend less time on IT administra-
tion and more time on business innovation.
This guide contains proprietary information protected by copyright. The software described in this guide is furnished under a soft-
ware license or nondisclosure agreement. This software may be used or copied only in accordance with the terms of the applicable
agreement. No part of this guide may be reproduced or transmitted in any form or by any means, electronic or mechanical, includ-
ing photocopying and recording for any purpose other than the purchaser’s personal use without the written permission of Quest
Software Inc.
The information in this document is provided in connection with Quest Software products. No license, express or implied, by estoppel
or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Quest Software prod-
ucts. EXCEPT AS SET FORTH IN THE TERMS AND CONDITIONS AS SPECIFIED IN THE LICENSE AGREEMENT FOR THIS PRODUCT,
QUEST SOFTWARE ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY
RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR
A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL QUEST SOFTWARE BE LIABLE FOR ANY DIRECT, INDI-
RECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR
LOSS OF PROFITS, BUSINESS INTERRUPTION OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE
THIS DOCUMENT, EVEN IF QUEST SOFTWARE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Quest Software
makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves
the right to make changes to specifications and product descriptions at any time without notice. Quest Software does not make any
commitment to update the information contained in this document.
Patents
Quest Software is proud of our advanced technology. Patents and pending patents may apply to this product. For the most current
information about applicable patents for this product, please visit our website at www.quest.com/legal
Trademarks
Quest, SQL Optimizer and the Quest logo are trademarks and registered trademarks of Quest Software Inc. For a complete list of
Quest marks, visit www.quest.com/legal/trademark-information.aspx. All other trademarks are property of their respective owners.
If you have any questions regarding your potential use of this material, contact:
Refer to our website (www.quest.com) for regional and international office information.
21
TechBrief-SQLOptimizer-Secrets-US-KS-36256