Solved

SARG Update Statement

Posted on 2006-11-07
6
344 Views
Last Modified: 2012-06-27
Hi I have run profiler filtering on all queries taking longer than 10 seconds. The Update statement below the update takes around 80 seconds. Is there anyway I can Sarg the update statement and make it run quicker. Currently it's doing and Index Scan on the temptable which contains 2000 rows and doing an index seek on the
tblHighlights table. Optimiser is joining the two tables together by doing a nested loop.
As I understand to make the sql optimizer use the indexes efficiently you should not use functions on columns in the WHERE clause. How can I get around this if i need to check the existense of empty string and NULL. Furthermore the tDescription column is a text field.
Help would be appreciated.
Thanks




UPDATE TR              
 SET TR.Filled = 1              
 FROM TH              
 INNER JOIN #Test  TR ON TR.K_EL_ID = TH.iExhibitorID AND TR.K_EV_ID = TH.iEventID              
 WHERE              
   (ISNULL(CAST(tDescription AS VarChar),'') <> ''              
  OR   ISNULL(vcImage,'') <> '')              
0
Comment
Question by:anwarmir
  • 3
  • 2
6 Comments
 
LVL 28

Expert Comment

by:imran_fast
ID: 17889099
Do you have index on TR.K_EL_ID  ?

0
 
LVL 28

Assisted Solution

by:imran_fast
imran_fast earned 250 total points
ID: 17889109
Create this index and they try


Create index IX_TR on TR (K_EL_ID,K_EV_ID)
0
 
LVL 28

Expert Comment

by:imran_fast
ID: 17889123
also if possible try to create index on this #test table

Create index IX_test on #Test   (iExhibitorID ,iEventID  )
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 11

Accepted Solution

by:
regbes earned 250 total points
ID: 17889139
Hi anwarmir,
make sure you need the cast it does not look needed to me

try this

UPDATE TR              
 SET TR.Filled = 1              
 FROM TH              
 INNER JOIN #Test  TR ON TR.K_EL_ID = TH.iExhibitorID AND TR.K_EV_ID = TH.iEventID              
 WHERE          
(tDescription is null and tDescription <> '')
or
(vcImage is null and vcImage <> '')

or these 2 may run faster than the one




UPDATE TR              
 SET TR.Filled = 1              
 FROM TH              
 INNER JOIN #Test  TR ON TR.K_EL_ID = TH.iExhibitorID AND TR.K_EV_ID = TH.iEventID              
 WHERE          

(vcImage is null and vcImage <> '')

UPDATE TR              
 SET TR.Filled = 1              
 FROM TH              
 INNER JOIN #Test  TR ON TR.K_EL_ID = TH.iExhibitorID AND TR.K_EV_ID = TH.iEventID              
 WHERE          
(tDescription is null and tDescription <> '')



HTH

R.
0
 

Author Comment

by:anwarmir
ID: 17889557
Thanks, I'll try these tips out.

>>make sure you need the cast it does not look needed to me

I need the cast to convert to varchar to check for empty string as this not allowd on a text field
0
 
LVL 11

Expert Comment

by:regbes
ID: 17889769
anwarmir,
>  need the cast to convert to varchar to check for empty string as this
> not allowd on a text field

consider enabling full text indexing this may help performance when using this field

does the field hold more than 8000 chars ? if nor consider changing it to varchar(AnticipatedMaxLength)

if you are on 2005 consider changing the field to varchar(max)


0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now