sql - TSQL - View vs Stored Procedure: Performance considerations when apply predicates -


suppose have view that's defined follows:

create view [dbo].[vdata_values]    select parentid, timestamp, value table1    union    select parentid, timestamp, value table2    union    select parentid, timestamp, value table3    union    select parentid, timestamp, value table4 

suppose write query against view follows:

   select parentid, timestamp, value    vdata_values    parentid in (...) , timestamp between '1/1/2013' , '3/31/2013 23:59' 

would expect query against view perform differently stored procedure same inner query view, same where clause @ each step. example:

create procedure [dbo].[getvalues] ( ... ) begin     select parentid, timestamp, value table1    parentid in (...) , timestamp between '1/1/2013' , '3/31/2013 23:59'    union    select parentid, timestamp, value table2    parentid in (...) , timestamp between '1/1/2013' , '3/31/2013 23:59'    union    select parentid, timestamp, value table3    parentid in (...) , timestamp between '1/1/2013' , '3/31/2013 23:59'    union    select parentid, timestamp, value table4    parentid in (...) , timestamp between '1/1/2013' , '3/31/2013 23:59'  end 

i'm trying conceptualize if/how these 2 processed/optimized differently. there performance gains "chunking" individual queries , individually applying predicate each?

thanks.

compare execution plans

below have same execution plans

  create view [dbo].[docsvsysint]   select sid    docsvsys    union    select sid    docsvint    select sid    [docsvsysint]    sid > 100000 , sid <  100010    select sid    docsvsys    sid > 100000 , sid <  100010   union    select sid    docsvint   sid > 100000 , sid <  100010    select sid      (   select sid    docsvsys    union    select sid    docsvint   )  comb   sid > 100000 , sid <  100010 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -