Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Computed Column is slowing down performance on a simple select statement Expand / Collapse
Author
Message
Posted Thursday, April 5, 2012 11:35 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:42 PM
Points: 10,193, Visits: 13,120
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

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
Post #1279048
Posted Thursday, April 5, 2012 11:54 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, May 8, 2012 3:54 PM
Points: 10, 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?
Post #1279055
Posted Thursday, April 5, 2012 12:01 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:42 PM
Points: 10,193, Visits: 13,120
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

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
Post #1279062
Posted Thursday, April 5, 2012 12:19 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, May 8, 2012 3:54 PM
Points: 10, Visits: 11
So, basically, that would cut my UDF calls in half. A good idea.
Post #1279071
Posted Thursday, April 5, 2012 12:28 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, May 8, 2012 3:54 PM
Points: 10, Visits: 11
Here is my execution plan:



  Post Attachments 
sshot-3.png (3 views, 52.41 KB)
Post #1279077
Posted Friday, April 6, 2012 9:52 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Yesterday @ 10:18 AM
Points: 85, Visits: 900
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='')





Post #1279555
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse