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

Persisted vs Non-persisted Computed columns Expand / Collapse
Author
Message
Posted Thursday, October 7, 2010 6:42 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Sunday, October 19, 2014 10:29 AM
Points: 1,880, Visits: 3,460
Did I ever say that this hint was never to be used? For reporting purposes where the possibility of reading dirty data does not affect the quality of the report then go ahead and use it. I've done it myself many times. What I mentioned in my previous post was misuse due to poor programming.
Post #1000380
Posted Thursday, October 7, 2010 6:58 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, October 7, 2014 2:36 PM
Points: 2,818, Visits: 2,565
Good question.....lots of reading first thing in the AM.
Post #1000403
Posted Thursday, October 7, 2010 7:11 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, July 29, 2014 8:47 AM
Points: 2,296, Visits: 1,427
Nice question
I am much afraid by seeing the question
post this type questions
Post #1000433
Posted Thursday, October 7, 2010 7:14 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 7:16 AM
Points: 2,917, Visits: 2,531
Hugo
Mostly queries that report aggregated data for an audience that doesn't care about the exact number, but only wants an indication. If the numbers my query produces will be rounded to the nearest million dollars anyway, I can live with a result that might be a couple of thousand dollars off.

Completely agree, which is why we unfortunately use it everywhere. Our environment is very large and growing. We literally have several thousand users hitting against the OLTP databases making hourly decisions. Unfortunately we are unable to replicate all of the necessary data to other locations for them to review though it is moved to a warehouse daily which is used primarily for trending as well as market basket and many other things. Reports are happening at the same time as OLTP. I appologize if you felt that I was picking, but I just wanted to get you to expand upon your answer. Thank you.

Nils
Did I ever say that this hint was never to be used? For reporting purposes where the possibility of reading dirty data does not affect the quality of the report then go ahead and use it. I've done it myself many times. What I mentioned in my previous post was misuse due to poor programming.

Unfortunately, your initial posting read very definite and you posted the 2 reasons that you felt were the the use of locking hints. If I misread, I am sorry - but how many others?


Steve Jimmo
Sr DBA
“If we ever forget that we are One Nation Under God, then we will be a Nation gone under." - Ronald Reagan
Post #1000440
Posted Thursday, October 7, 2010 7:29 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Sunday, October 19, 2014 10:29 AM
Points: 1,880, Visits: 3,460
Ok, I can see that my comment about using NOLOCK to fix concurrency issues could be explained a bit better, and that there are legitimate reasons to use it, for example in reporting scenarios.

But I cannot see where I completely condemn the use of NOLOCK. I mentioned that one of our vendors use in in ALL SELECT statements, and most of them has nothing to do with reporting functionality. They are plain SELECTS that returns just a few rows, but because the client app is poorly programmed (as I tried to explain) the have "fixed" it with NOLOCK.
Post #1000459
Posted Thursday, October 7, 2010 7:47 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 3:13 PM
Points: 13,085, Visits: 12,551
Nils Gustav Stråbø (10/7/2010)

You won't believe how many people that actually use NOLOCK or READ_UNCOMMITTED to "fix" concurrency and locking problems. One of our vendors use NOLOCK in every(!) SELECT statement in a system we have purchased from them. They have never bothered to explain the reason for doing it, but my guess, after doing some investigation, is that it is caused by two things:

- Lots of missing indexes, which results in excessive scans
- Bad programming, because when I save data in the front-end, SQL Profiler showed that before the transaction for the update statement was committed, another connection from my pc was opened trying to read the updated row(s).


I worked as a consultant on a system for a major health insurance company and they had the nolock hint on every single query in their system. Keeping in mind that this is the system that pays disbursements both from "paper" claims and real time debit cards our balances were always out of whack because we would authorize payment when there was not enough money due to dirty reads. I can't tell you how many times I suggested that they should find better ways of dealing of locked tables.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1000486
Posted Thursday, October 7, 2010 11:25 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 11:01 AM
Points: 703, Visits: 327
http://msdn.microsoft.com/en-us/library/ms189292.aspx#BKMK_persisted
'You can create an index on a computed column that is defined with a deterministic, but imprecise, expression if the column is marked PERSISTED'

--If I wanted to find all those who received a work permit on a give day, this query works but shows a table scan.
SELECT [DOWorkPermit] FROM [Employee_2] WHERE [DOWorkPermit] = '12/31/1993';

--Add an index on the persisted, computed column:
CREATE NONCLUSTERED INDEX IX_WorkPermit ON [Employee_2] ([DOWorkPermit]);
GO

--The query still shows a table scan because DOBirth is in the output list and is needed to find the computed DOWorkPermit day:
SELECT [DOWorkPermit] FROM [Employee_2] WHERE [DOWorkPermit] = '12/31/1993';

-- drop and recreate the index including the DOBirth column
DROP INDEX IX_WorkPermit ON [Employee_2];
GO
CREATE NONCLUSTERED INDEX IX_WorkPermit ON [Employee_2] ([DOWorkPermit]) INCLUDE ([DOBirth]);
GO

--an index scan is now used
SELECT [DOWorkPermit] FROM [Employee_2] WHERE [DOWorkPermit] = '12/31/1993'

My question is, couldn't an index seek be done on the persisted, indexed value rather than having to compute it while doing a scan? Is it because there's only 1 record in the table or am I missing or misinterpreting something...
Post #1000738
Posted Wednesday, October 20, 2010 8:50 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, October 17, 2014 2:43 PM
Points: 216, Visits: 119
Nice question, I appreciate the intent of the question as I see it, 'Persisted does not mean permanent.'
Post #1007792
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse