473,511 Members | 12,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need guidelines - Query Optimization

308 Contributor
Hi,

One I get the query plan for a particular query..

Can anybody provide me the guidelines for how to proceed for optimization ?

Thanks!
Aug 15 '09 #1
1 1775
Delerna
1,134 Recognized Expert Top Contributor
Probably the best guideline I can give you is to write two different queries in query analyser that achieve the same result. Simple queries at first.

Then you will be able to see the execution plan for both at the same time and query analyser will caompare both and tell you whether one is better than the other. From there you can study the execution plans and you will see why one is better over the other. Over time you will learn what to look for.


an example of 2 queries with identical resuls

Expand|Select|Wrap|Line Numbers
  1. --This one is bad
  2. Select InitiatorID,
  3.           (select UserName from tblUsers where InitiatiorID=ID) as Initiator,
  4.           TopicID,
  5.           PostedComment,
  6.           PosterID,
  7.           (select UserName from tblUsers where PosterID=ID) as Poster,
  8. From tblPosts
  9.  
  10. --This one should be better (especially if tblUsers has a lot of records in it)
  11. Select InitiatorID,
  12.           b.UserName as Initiator,
  13.           TopicID,
  14.           PostedComment,
  15.           PosterID,
  16.           c.UserName as Poster,
  17. From tblPosts a
  18. join tblUsers b on a.InitiatiorID=b.ID
  19. join tblUsers c on a.PosterID=c.ID
  20.  
Put two queries something like those into the same query analyser window
and open "show query plan" and you should see a comparison of the two.
Aug 16 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1692
by: ensnare | last post by:
This query is running REAL slow ... like 1.2 secs ... any ideas on how I could optimize it? Perhaps my indexes are incorrect? $this->query = "SELECT m.username as username, e.title as title,...
5
4396
by: AC Slater | last post by:
Whats the simplest way to change a single stored procedures query optimization level? In UDB8 that is. /F
1
3101
by: Sean C. | last post by:
Helpful folks, I have recently migrated our test server, which runs Win NT 4, from V7.2 FP11 to V8.1.3. Just about everything works wondefully, except I am having major problems getting the...
2
5114
by: Eugene | last post by:
I am trying to set query optimization class in a simple SQL UDF like this: CREATE FUNCTION udftest ( in_item_id INT ) SPECIFIC udftest MODIFIES SQL DATA RETURNS TABLE( location_id INT,...
12
6154
by: WantedToBeDBA | last post by:
Hi all, db2 => create table emp(empno int not null primary key, \ db2 (cont.) => sex char(1) not null constraint s_check check \ db2 (cont.) => (sex in ('m','f')) \ db2 (cont.) => not enforced...
11
2117
by: 73blazer | last post by:
We are migrating a customer from Version 7.1 FP3, to Version 8.2 (8.1 FP8). For the most part, things are faster, but there is one query that is much much slower, and it is a query that is used all...
6
9919
by: UnixSlaxer | last post by:
Hello, Running a query for the first time on DB2 takes a fixed amount of time. But when query is executed for the second time, the amount of time is usually less since the query is (most...
4
3762
by: Bernard Dhooghe | last post by:
To retrieve data from a query where multiple rows can be returned, a cursor can be used. Different programming interface exist for cursors: embedded SQL, CLI, SQL PL, SQLJ, JDBC. I we look at...
0
9949
ADezii
by: ADezii | last post by:
One frequently asked question at TheScripts is "Should I use a Stored Query or an SQL Statement in those situations that require a Query (RecordSets, RecordSources, Append, Delete, Update Operations,...
0
7356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
449
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.