Click here to Skip to main content
15,867,686 members
Articles / Artificial Intelligence
Article

SQL Optimizer for Visual Studio: Automatically make your queries faster using this extension from Quest Software

7 Nov 20064 min read 43.4K   13   9
Learn how changing the way you write queries can make them run faster. This article will describe the automated approach to optimizing SQL. DBA's have been doing it for years, now it's available for developers.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

Image 1This is a showcase review for our sponsors at CodeProject. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers.

Introduction

Optimizing SQL statements during development can save much in time and money by ensuring your application will run at peak performance without over-burdening the database. This article will describe how Visual Studio developers can tackle SQL Server performance issues without requiring the skill of a DBA.

Visual Studio Developer vs. SQL Server DBA

A simple fact that too often gets lost during development is that SQL statements can be optimized. Concepts like execution plans, logical reads, CPU time etc, can seem confusing and are left to the SQL Server DBA. So an application doesn't get SQL performance tuned until it is moved from development to production. DBAs are keenly aware of the cost of performance tuning applications SQL when it is in production. However, they've also recognized that in the past developers didn't have the deep knowledge required to performance tune SQL.

SQL Server Queries

You know how to write SELECT, INSERT, UPDATE, and DELETE statements. But did you know there could be literally thousands of ways to write a SQL statement and produce the exact same results? When you issue a query to SQL Server, it will process the statement before executing it. It will look for primary keys, indexes, sorts, and a variety of other factors. Taking these factors into account along with other statistics, SQL Server will produce an execution plan. The plan determines how the server will go about gathering the records your SQL is asking for. Variations in how a SQL statement is written will cause SQL Server to create a different execution plan. A different execution plan causes SQL Server to change how it gathers up your records. Each of these variations performs at different levels, some are slow and some are fast. Finding the fastest way to write a SQL statement is the key to peak performance in a database application. A tool like SQL Optimizer for Visual Studio from Quest Software understands every detail of an execution plan and related statistics and uses this information to optimize your SQL statements.

How it works

The original query is examined to see which transformation can be applied to it. A simple transformation that you may have considered in the past is whether to use IN, EXISTS, or chained ORs in a where clause. The SQL Optimizer engine knows dozens of such transforms, all varying in complexity. After applying the transforms it looks at the resultant statements, again examining them to see which transforms can be applied.

Image 2Image 3

Figure 1.Transforming SQL to produces many rewrites.

After only a few iterations of this process, it yields many different ways of writing the same SQL statement. Using a mathematical model based on set theory, each rewrite of the original statement is guaranteed to be semantically equivalent. In other words, they all produce the same records when executed. Finally, using an artificial intelligence "Feedback-Searching" engine, SQL Optimizer for Visual Studio arrives at the best way to write your SQL statement. The result is optimized SQL.

Optimizing SQL right inside of Visual Studio

SQL Optimizer for Visual Studio extends Visual Studio to allow any developer to take advantage of this process, to painlessly optimize their SQL statements.

Once SQL Optimizer is installed, right click on any Solution or Project node to find all the SQL in your application. All of the source code associated with your application will be scanned for SQL statements.

Image 4

Figure 2. Finding all the SQL in a Solution/Project.

Each SQL statement will be added to the SQL Explorer. You can see what statements were optimized and the date they were last optimized. The SQL Explorer also classifies your SQL statements so you can tell at a glance which statements are simple, complex, or even potentially problematic.

Image 5

Figure 3. SQL Explorer in Visual Studio manages SQL in your project

A right click form the SQL Explorer will start the automatic optimization of any or all of the statements in the explorer. Upon completion you can review a report comparing the before and after versions of the statement showing just how much of a performance gain you made.

Image 6

Figure 4. Review performance improvements after SQL is optimized.

Conclusion

Whether your SQL is embedded in VB.Net or in stored procedures, SQL Optimizer for Visual Studio can automate the optimization process. SQL Optimizer for Visual Studio supports SQL Server 2000 and 2005, Visual Studio 2003 & 2005.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalquery became slower Pin
woudwijk25-Jan-07 2:02
woudwijk25-Jan-07 2:02 
QuestionWhy Multiple Inheritance is Not Possible In VB.Net or in Java? Pin
amargujrathi200618-Dec-06 17:55
amargujrathi200618-Dec-06 17:55 
AnswerRe: Why Multiple Inheritance is Not Possible In VB.Net or in Java? Pin
jacknpoe30-Jan-07 1:26
jacknpoe30-Jan-07 1:26 
QuestionAny tool for SQL server 2000? Pin
Aravind Kumar K15-Nov-06 16:50
Aravind Kumar K15-Nov-06 16:50 
Hi,

I am using SQL Server 2000 and I have complex queries which are taking a very long time to execute. Do you have / know products which can optimize SQL queries for Sql 2000 ?

Thanks,
Aravind

Aravind.
AnswerRe: Any tool for SQL server 2000? Pin
Daniel Wood16-Nov-06 12:33
Daniel Wood16-Nov-06 12:33 
GeneralNo support for XML Pin
Eric Frog14-Nov-06 22:32
Eric Frog14-Nov-06 22:32 
GeneralRe: No support for XML Pin
Daniel Wood16-Nov-06 12:36
Daniel Wood16-Nov-06 12:36 
GeneralProblem with time format Pin
rrosenthal13-Nov-06 22:25
rrosenthal13-Nov-06 22:25 
QuestionRe: Problem with time format Pin
Daniel Wood16-Nov-06 12:47
Daniel Wood16-Nov-06 12:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.