SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Computed Column is slowing down performance on a simple select statement


Computed Column is slowing down performance on a simple select statement

Author
Message
Jack Corbett
  Jack Corbett
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18316 Visits: 14889
crackedcornjimmy (4/5/2012)
I mentioned in the question that I am using SQL 2000. Unfortunately, PERSISTED is not available in SQL 2000. It wasn't introduced until 2005+.


Sorry I missed that you mentioned 2000 and were in a 2000 forum. I see so few posts for 2000 I always assume 2005+.

I just noticed that you are decoding and then re-encoding the data in the column. Why are you doing both? If it is already Encoded you shouldn't need to do anything.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
crackedcornjimmy
crackedcornjimmy
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 11
Yes. Let's say the data is already encoded, due to some recent application changes to how it is inserted into the database.

Now, the value passed into the stored procedure is always encoded. But, we don't want to encode the encoded data again because it wouldn't match the encoded passed in parameter. Thus, we decode the assumed encoded data in the database (if it is already decoded (about 97% of our data is unencoded) decoding has no effect) giving it a true plain text foundation, then re-encode it so that it matches the encoded parameter passed in.

Is that clear enough?
Jack Corbett
  Jack Corbett
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18316 Visits: 14889
I thought that might be the reason, but it still is causing performance issues. Every row in the table has to go through both functions before any filtering can be applied.

How is the HTML encoded data used? You might even be better off storing a second decoded column then decode the parameter passed in to compare against the decoded column. I think this would allow for better use of any indexes.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
crackedcornjimmy
crackedcornjimmy
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 11
So, basically, that would cut my UDF calls in half. A good idea.
crackedcornjimmy
crackedcornjimmy
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 11
Here is my execution plan:
Attachments
sshot-3.png (8 views, 52.00 KB)
Davio
Davio
SSC Journeyman
SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)

Group: General Forum Members
Points: 87 Visits: 1202
Try running the query as a UNION ALL instead and see if your query plan is any better. While it shouldn't make a difference when you upgrade to SQL 2008, SQL 2000 was not always so good parsing OR conditions.

DECLARE @LName --HTML encoded last name as input parameter from user

SELECT * FROM
(SELECT LNameComputedColumn
FROM SomeView xtra
WHERE @LName <> '' AND xtra.LNameComputedColumn=@LName
UNION ALL
SELECT LNameComputedColumn
FROM SomeView xtra
WHERE @Lname='')



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search