Solved

SARG Update Statement

Posted on 2006-11-07
6
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
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 documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

617 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