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 12345»»»

Computed Columns Expand / Collapse
Author
Message
Posted Tuesday, July 20, 2010 9:52 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, April 11, 2014 8:16 AM
Points: 434, Visits: 202
Comments posted to this topic are about the item Computed Columns
Post #956061
Posted Tuesday, July 20, 2010 10:08 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, June 16, 2014 9:38 AM
Points: 2,163, Visits: 2,189
This is a nice question but I have to disagree with your answer. Actually just one part of it: "Will definitely use more resources." which I can't believe is true. I looked at your links and I didn't see anything that stated that they will always use more resources. With that statement it means that there can never be a case where they use less resources, which I can come up with an example where they would. If you had said they will use more CPU resources, maybe, but not always... In this case I think it is like Paul Randal says: "It depends!"

* Right off the bat a non-persisted computed column uses less storage space/time than a persisted computed column.
* If a column can be calculated from other columns in the table, but is rarely used by not actually storing it you could save the CPU of calculating it, the I/O and space of storing it, as well as the I/O of reading it each time the record it relates to is read.
* If you have very slow storage it might be faster to have the CPU calculate it every time it is used instead of storing and reading it.
* I'm not sure but I assume since it is calculated on use it wouldn't be stored in the buffer pool, so non-persisted computed columns probably use less RAM.
Post #956068
Posted Tuesday, July 20, 2010 11:53 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, December 15, 2013 9:40 PM
Points: 160, Visits: 68
i agree on the '"Will definitely use more resources." being a dodgy part of the question.

which resources are we talking about? it will most likely save developer resources as the calc is done once, probably save maintenance resources as its easy to fix.

if the calculation is a+b will that use more resources that including a+b in a view?
Post #956110
Posted Wednesday, July 21, 2010 12:08 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 11:33 PM
Points: 361, Visits: 510
Now this doesn't hold true:
Will definately use more resources.

I am very pleased that UMG developer made a thorough explanation in the previous comment as it was exactly my thought but I couldn't had written it on my phone.
And to add some value to it I think other than being more precise with the resources option you could have thrown in an option relating to indexes or inserts (w/ or wo/ instead of triggers), language dependent functions...
I myself have written a calendar table w/ one physical date column, one computed persisted integer column and a whole bunch of non-persisted columns calculated from the date column.
It


Hrvoje Piasevoli
Post #956116
Posted Wednesday, July 21, 2010 12:25 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, June 16, 2014 9:38 AM
Points: 2,163, Visits: 2,189
The other thing that comes to mind is that is an incomplete statement. It doesn't say what it will use more resources than.

* Using a persisted computed column instead: It depends.
* Calculating in a view instead: probably not.
* Calculating in an SP instead: probably not.
* Calculating in the client app instead: probably not. (It may even use less as the client may only need the computed column so there would be less network traffic if the computed column was smaller than the components that make it up.)

What else could it be compared to?
Post #956119
Posted Wednesday, July 21, 2010 12:28 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, June 16, 2014 9:38 AM
Points: 2,163, Visits: 2,189
hrvoje.piasevoli (7/21/2010)
I myself have written a calendar table w/ one physical date column, one computed persisted integer column and a whole bunch of non-persisted columns calculated from the date column.
It


I'm curious did you test and find that using non-persisted columns was faster than pre-calculating and storing all the permutations that you needed? (I guess it would probably depend on the storage system speed and a number of other variables.)
Post #956122
Posted Wednesday, July 21, 2010 12:31 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 11:33 PM
Points: 361, Visits: 510
...And off it goes posted unfinished (sorry about that).
I think it might be a good idea to have a peer-review of ones Q and A before submitting a QoD to avoid frustration we've all whitnessed when people encounter inprecise or ambiguous answers.
I personaly don't mind having some points not awarded, but find that questionable QoDs yield more contention in quality of the discussion that follows.

Regards,
Hrvoje


Hrvoje Piasevoli
Post #956125
Posted Wednesday, July 21, 2010 12:57 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 11:33 PM
Points: 361, Visits: 510
I'm curious did you test and find that using non-persisted columns was faster than pre-calculating and storing all the permutations that you needed? (I guess it would probably depend on the storage system speed and a number of other variables.)

I find the aproach more manageable than using an SP and cleaner from the design point of view. And I can always make some other column persisted by a simple alter statement. (well not realy - has to be deterministic which is not the case with all columns). It is used primarily in warehouse solutions and therefore performance was never really an issue as it is loaded in an SSAS cube and persisted there. It also has a neat effect of being culture and language aware out of the box.


Hrvoje Piasevoli
Post #956133
Posted Wednesday, July 21, 2010 1:19 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Sunday, August 17, 2014 2:48 PM
Points: 3,352, Visits: 1,481
A good question, apart from the ambiguity surrounding the resources question. Since it's calculated at runtime, it doesn't use any disk resources, and I can't see how having a select statement along the lines of SELECT a + b AS C, <other_columns> FROM <table> would use less resources than SELECT C, <other_columns> FROM <table> when C is a computed column from a + b.

Obviously, if you're using scalar UDF's in non-persisted computed columns, there's a pretty good chance you'll be hit by performance problems somewhere down the line - as I've just discovered on one of our systems, so perhaps that was it?

Duncan
Post #956145
Posted Wednesday, July 21, 2010 4:39 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 3:00 AM
Points: 3,905, Visits: 5,078
overall a good question, just the bit about resource usage that appears incomplete,

Stating "Will definately use more resources" is the same as asking how long a piece of string is. Lack of equable context renders it vague.


____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
Post #956231
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse