sql server - Indexed view usability -


i have indexed view:

create view ptv.vw_mokiniai_2  schemabinding     select      t1.year_name,     t2.person_id,     t2.year,     t2.person_position,     count_big(*) [aggregated number]   table1 t1    inner join table2 t2      on t1.year = t2.year   group t1.year_name,     t2.person_id,     t2.year,     t2.person_position 

with unique clustered index on columns

t1.year_name, t2.person_id, t2.year, t2.person_position 

i need query optimizer use indexed view on query

select      t1.year_name,      count_big(distinct t3.person_id) [persons_per_year] table1 t1 inner join (             select                t2.person_id,               t2.year,               t2.person_position             table2 t2              group t2.person_id, t2.year, t2.person_position             ) t3      on t1.year = t3.year group t1.year_name 

the query must derived table, because cognos generates query , not want edit multidimensional model. have idea how done? maybe way optimize query remove derived table(means have edit multidimensional model)? suggestions (view editing , final query editing) appreciated.

the example below uses indexed view in test. if doesn't work in environment, perhaps there difference not evident in code posted.

create table dbo.table1     (       year varchar(10)     , year_name varchar(10)     );  create table dbo.table2     (       year varchar(10)     , person_id varchar(10)     , person_position varchar(10)     ); go  create view dbo.vw_mokiniai_2 schemabinding     select  t2.person_id           , t2.year           , t2.person_position           , count_big(*) [aggregated number]        dbo.table2 t2     group t2.person_id           , t2.year           , t2.person_position go create unique clustered index cdx on vw_mokiniai_2(year, person_id, person_position) go  select      t1.year_name,      count_big(distinct t3.person_id) [persons_per_year] table1 t1 inner join (             select                t2.person_id,               t2.year,               t2.person_position             table2 t2              group t2.person_id, t2.year, t2.person_position             ) t3      on t1.year = t3.year group t1.year_name go 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -