Following this thread; I am trying to find the best execution plan to remain fully recalculable & benefit from caching with fast indexing for calculated columns. If I nest views I can index the first view (great) but any subsequent views thereafter loose the ability to index child-views as an indexed view cannot be created when a view is included in the select statement; amongst many other restrictions with an indexed view (not good).
I am trying to avoid already calculated results. So use a persistent UDF - then I have to feed many unnecessary variables to View_2, obfuscating the math & I'm also concerned what happens with persisted results. I don't know if they are cleared from memory in SQL Server/ what happens as the continuous build of endless results would then be slower to retrieve than a non-indexed lot of nested views (with un-indexed memory pointers; forcing full-scan's just to get a single result). Older versions of SQL Server using a scalar function is also bad because it stops the execution plan benefitting from parallelism. I don't know if Ver-22 is completely ridded of this?
The Problem
Also worried that many calc's benefit in storage space but increased cost on CPU for determining. I can reduce this by using Temp Tables I think with stored procedures to limit what is shown in a view & build a temporary view with indexes on launching the application I guess would be the way to do it.
Just found MSN's Guide On Query Processing Architecture which I hope bears fruit. Have researched inexing, B-Trees, row & batch execution...
Seems a very basic thing that many would have done before - What is the best route for calculation when you need to reference that calculation in many other places?
I am trying to avoid already calculated results. So use a persistent UDF - then I have to feed many unnecessary variables to View_2, obfuscating the math & I'm also concerned what happens with persisted results. I don't know if they are cleared from memory in SQL Server/ what happens as the continuous build of endless results would then be slower to retrieve than a non-indexed lot of nested views (with un-indexed memory pointers; forcing full-scan's just to get a single result). Older versions of SQL Server using a scalar function is also bad because it stops the execution plan benefitting from parallelism. I don't know if Ver-22 is completely ridded of this?
The Problem
- Tbl1 contains info to deduce calc1 calculated result; which is deterministic & other views feed off this calc. My plan was to have a view with this calculation & join the calc'd view column (in the view) to the original table with indexes in the view & table to maximise speed. Allows for automatic recalculation (opposed to a calc'd column in the table itself). BUT the problem arises in subsequent child-views which are dependant on this calc'd column in the view; see View_2:
- View_2 - uses calc1's result & new info in Tbl2 to deduce calc2, also deterministic. There will be many feeding off calc1 & calc2 so not all of them will be deterministic.
Also worried that many calc's benefit in storage space but increased cost on CPU for determining. I can reduce this by using Temp Tables I think with stored procedures to limit what is shown in a view & build a temporary view with indexes on launching the application I guess would be the way to do it.
Just found MSN's Guide On Query Processing Architecture which I hope bears fruit. Have researched inexing, B-Trees, row & batch execution...
Seems a very basic thing that many would have done before - What is the best route for calculation when you need to reference that calculation in many other places?
Last edited: