473,605 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help needed to improve the performance of the query

Hello,
I have the following setup and I would appreciate any help in improving
the performance of the query.

BigTable:
Column1 (indexed)
Column2 (indexed)
Column3 (no index)
Column4 (no index)
select
[time] =
CASE
when BT.Column3 = 'value1' then DateAdd(...)
when BT.Column3 in ('value2', 'value3') then DateAdd(...)
END,
Duration =
CASE
when BT.Column3 = 'value1' then DateDiff(...)
when BT.Column3 in ('value2', 'value3') then DateDiff(ss,
BT.OrigTime, (select TOP 1 X.OrigTime from BigTable X where X.Column1 >
BT.Column1 and X.Column3 <> 'value4' order by X.Column1 ))
END,

FROM
BigTable BT where BT.Column3 = 'value1' OR (BT.Column3 in ('value2',
'value3') and BT.Column4 <> (select X.Column4 from BigTable X where
X.Column1 = BT.Column1 and X.Column3 = 'Value1'))
Apart from the above mentioned, there are a few more columns which are
just a part of select statement and are not in any condition statments.

The BigTable has around 1 Mil records and the response time is very
poor, it takes around 3 mins to retrieve the records (which would be
around 500K)

With the Statistics ON,
I get the following:

Table 'BigTable'. Scan count 2, logical reads 44184, physical reads 0,
read-ahead reads 0.
Table 'WorkTable'. Scan count 541221, logical reads 4873218, physical
reads 0, read-ahead reads 0.

Is there any way to increase the performance, so that I can get the
result under 1 minute?
Any help would be appreciated.

P.S: I tried indexing the Column3, but no improvement.

Jul 23 '05 #1
1 1806
(rs*****@gmail. com) writes:
I have the following setup and I would appreciate any help in improving
the performance of the query.

BigTable:
Column1 (indexed)
Column2 (indexed)
Column3 (no index)
Column4 (no index)
select
[time] =
CASE
when BT.Column3 = 'value1' then DateAdd(...)
when BT.Column3 in ('value2', 'value3') then DateAdd(...)
END,
Duration =
CASE
when BT.Column3 = 'value1' then DateDiff(...)
when BT.Column3 in ('value2', 'value3') then DateDiff(ss,
BT.OrigTime, (select TOP 1 X.OrigTime from BigTable X where X.Column1 >
BT.Column1 and X.Column3 <> 'value4' order by X.Column1 ))
END,

FROM
BigTable BT where BT.Column3 = 'value1' OR (BT.Column3 in ('value2',
'value3') and BT.Column4 <> (select X.Column4 from BigTable X where
X.Column1 = BT.Column1 and X.Column3 = 'Value1'))


It is very difficult with this very abstract representation of the
query to say that much. What strikes my eyes are the two correlated
subqueries. If value2 and value3 are frequent, these subqueries are
likely to be invoked many times.

It is often a good idea to replace correlated subqueries with derived
tables that you join to. But I cannot say whether this is possible. To
suggest a rewrite of the query I would need:

o CREATE TABLE statments (possibly simplified) for the table.
o INSERT statements with sample data, enough to demonstrate all
variations.
o The expected output for the sample.

For the performance point of view it would also be useful to know
whether the indexes you have are clustered or not.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4295
by: Surendra | last post by:
I have a table that has fields GRP_CODE & END_DATE. For a given GRP_CODE and a given month of a year, there may be 1, 2 or 3 END_DATE values. For Example, GRP_CODE END_DATE AA 07/14/2003 AA 07/28/2003 BB 07/14/2003 BB 07/28/2003 AA 08/01/2003
1
6542
by: shilsum | last post by:
I would like to seek your expert opinions on the following problem of mine: I have a table to store employees Here is the partial structure of the table EMPID EMP_POS DATE MGMT
2
1582
by: g_chime | last post by:
I have a large table (~200 columns, ~10 million rows) and I am trying to query by two float rows, say f1 and f2: SELECT... FROM large_table WHERE f1 BETWEEN 10.82 AND 113.998 AND f2 BETWEEN -124.99 AND 23.5; The query is extremely slow; it takes hours.
3
3021
by: Randy Harris | last post by:
I've been trying to construct a Crosstab query (mess pasted below) that would output all rows, even if the Value (a count) is 0. No matter what I do, it only returns rows that have matching records. Is it possible to do this? I have a report based on the query that needs to show all of the products and activities, even if the EventID is 0. I'm grateful for any suggestions. TRANSFORM Count(TrainingCenterSummary_qry.EventID) AS...
0
1099
by: Tony Ciconte | last post by:
I am trying to get either the counts of or sum of data from a table with gift amounts to display within certain ranges (e.g., $1-$99, $100-$199, etc.) . The query is as follows: TRANSFORM Sum(tblGifts.GiftAmt) AS SELECT tblGifts.MtypeID, Sum(tblGifts.GiftAmt) AS FROM tblGifts GROUP BY tblGifts.MtypeID PIVOT Partition(Val(.),0,1000,100) In ("$1 - $99", "$100 - $199", "$200 - $299", "$300 - $399", "$400 - $ 499");
1
1332
by: Rommel the iCeMAn | last post by:
Hi Group, My apologies for the lengthy post, but here goes... I have the following tables: TABLE Vehicles ( nvarchar(5), nvarchar(20),
1
1024
by: chella | last post by:
Hi Experts, I have a problem in writing a sybase query for the following scenario, My table has the following data, id name 1 aa 2 bb 1 bb
3
1923
by: b4babu | last post by:
Hi, I've a table named PC as below: PC(code, model, speed, ram, hd, cd, price) I want to write a query to find the pairs of PC models having similar speeds and RAM. Also, in the result set, the pairs of PC's being compared should occur only once, i.e, if (i,j) is compared then (j,i) shouldn't be compared. Plz help me solve this query. Thanks, Babu
7
1326
by: raaman rai | last post by:
Hello everybody, well i have 3 tables created in my access db i.e tblClient, tblProject & tblPayment. The main table is tblClient where Client information is stored with ClientID as the Primary key. Now the other two tables are linked with Client Table using ClientID as the foreign key. Now the situation is that for each client there can be many projects and the payments can also be made in any numbers (times). So, now i need to have a joined...
6
1283
by: britania | last post by:
Im looking for some help by a MSSQL 2000 expert. I need to update dbo.prop_main with information from another table dbo.properties Basically where prop_propertyID = Prop_ID in both tables add the northings_COORD and eastings_COORD information from dbo.properties to the northings and eastings from dbo.prop_main Can anyone help me construct this?
0
7937
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8428
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8423
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8076
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6749
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5446
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3913
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2438
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 we have to send another system
1
1546
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.