Solved

SARG Update Statement

Posted on 2006-11-07
6
346 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

840 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