Home All Groups Group Topic Archive Search About

Indexed view appears slower



Author
17 Nov 2006 5:58 PM
thejamie
Placing an indexed view into a query appears to slow the query down.  There
is a cross database reference to a table which has its own indexes.  Creating
an indexed view similar to the table minus a field or two and substituting
the view for the table seems to slow the query down.  This may be logical and
if so, an answer may help me understand how to better speed up a query.

Example:

Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.ixview a
on a.x=b.x

slower than

Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.table2 a
on a.x=b.x
--
Regards,
Jamie

Author
17 Nov 2006 7:50 PM
John Bell
Hi

Which edition are you using? Enterprise  Edition will use Indexed views
without additional hints but other editions need the NOEXPAND hint to use
them. If you don't want to use an Indexed View in Enterprise Edition use the
EXPAND VIEWS hint. Check out your query execution plan to see what is being
used.

John

Show quoteHide quote
"thejamie" wrote:

> Placing an indexed view into a query appears to slow the query down.  There
> is a cross database reference to a table which has its own indexes.  Creating
> an indexed view similar to the table minus a field or two and substituting
> the view for the table seems to slow the query down.  This may be logical and
> if so, an answer may help me understand how to better speed up a query.
>
> Example:
>
> Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.ixview a
> on a.x=b.x
>
> slower than
>
> Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.table2 a
> on a.x=b.x
> --
> Regards,
> Jamie
Are all your drivers up to date? click for free checkup

Author
20 Nov 2006 2:13 PM
thejamie
We are using the STANDARD edition.
--
Regards,
Jamie


Show quoteHide quote
"John Bell" wrote:

> Hi
>
> Which edition are you using? Enterprise  Edition will use Indexed views
> without additional hints but other editions need the NOEXPAND hint to use
> them. If you don't want to use an Indexed View in Enterprise Edition use the
> EXPAND VIEWS hint. Check out your query execution plan to see what is being
> used.
>
> John
>
> "thejamie" wrote:
>
> > Placing an indexed view into a query appears to slow the query down.  There
> > is a cross database reference to a table which has its own indexes.  Creating
> > an indexed view similar to the table minus a field or two and substituting
> > the view for the table seems to slow the query down.  This may be logical and
> > if so, an answer may help me understand how to better speed up a query.
> >
> > Example:
> >
> > Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.ixview a
> > on a.x=b.x
> >
> > slower than
> >
> > Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.table2 a
> > on a.x=b.x
> > --
> > Regards,
> > Jamie
Author
20 Nov 2006 2:23 PM
John Bell
Hi

You will need to use a hint so the index is not expanded.

John

Show quoteHide quote
"thejamie" wrote:

> We are using the STANDARD edition.
> --
> Regards,
> Jamie
>
>
> "John Bell" wrote:
>
> > Hi
> >
> > Which edition are you using? Enterprise  Edition will use Indexed views
> > without additional hints but other editions need the NOEXPAND hint to use
> > them. If you don't want to use an Indexed View in Enterprise Edition use the
> > EXPAND VIEWS hint. Check out your query execution plan to see what is being
> > used.
> >
> > John
> >
> > "thejamie" wrote:
> >
> > > Placing an indexed view into a query appears to slow the query down.  There
> > > is a cross database reference to a table which has its own indexes.  Creating
> > > an indexed view similar to the table minus a field or two and substituting
> > > the view for the table seems to slow the query down.  This may be logical and
> > > if so, an answer may help me understand how to better speed up a query.
> > >
> > > Example:
> > >
> > > Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.ixview a
> > > on a.x=b.x
> > >
> > > slower than
> > >
> > > Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.table2 a
> > > on a.x=b.x
> > > --
> > > Regards,
> > > Jamie
Author
20 Nov 2006 2:27 PM
John Bell
Hi

I am not sure what has happened to the other post...

You will need to use the NOEXPAND hint to make sure the indexed view is used.

John

Show quoteHide quote
"thejamie" wrote:

> We are using the STANDARD edition.
> --
> Regards,
> Jamie
>
>
> "John Bell" wrote:
>
> > Hi
> >
> > Which edition are you using? Enterprise  Edition will use Indexed views
> > without additional hints but other editions need the NOEXPAND hint to use
> > them. If you don't want to use an Indexed View in Enterprise Edition use the
> > EXPAND VIEWS hint. Check out your query execution plan to see what is being
> > used.
> >
> > John
> >
> > "thejamie" wrote:
> >
> > > Placing an indexed view into a query appears to slow the query down.  There
> > > is a cross database reference to a table which has its own indexes.  Creating
> > > an indexed view similar to the table minus a field or two and substituting
> > > the view for the table seems to slow the query down.  This may be logical and
> > > if so, an answer may help me understand how to better speed up a query.
> > >
> > > Example:
> > >
> > > Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.ixview a
> > > on a.x=b.x
> > >
> > > slower than
> > >
> > > Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.table2 a
> > > on a.x=b.x
> > > --
> > > Regards,
> > > Jamie
Author
20 Nov 2006 7:02 PM
thejamie
Such as: (???)
Create View IndxVw WITH SCHEMABINDING as
Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.ixview a
on a.x=b.x where dattimestmp between '01-01-05' and '12-31-05'

Assume INDXVW_MYNDX is the clustered Index

Then to use the view
SET NOEXPAND ON
SELECT * FROM IndxVW (INDXVW_MYNDX) WHERE monthname like 'Feb%'
SET NOEXPAND OFF

Or do I have the concept wrong?

--
Regards,
Jamie


Show quoteHide quote
"John Bell" wrote:

> Hi
>
> I am not sure what has happened to the other post...
>
> You will need to use the NOEXPAND hint to make sure the indexed view is used.
>
> John
>
> "thejamie" wrote:
>
> > We are using the STANDARD edition.
> > --
> > Regards,
> > Jamie
> >
> >
> > "John Bell" wrote:
> >
> > > Hi
> > >
> > > Which edition are you using? Enterprise  Edition will use Indexed views
> > > without additional hints but other editions need the NOEXPAND hint to use
> > > them. If you don't want to use an Indexed View in Enterprise Edition use the
> > > EXPAND VIEWS hint. Check out your query execution plan to see what is being
> > > used.
> > >
> > > John
> > >
> > > "thejamie" wrote:
> > >
> > > > Placing an indexed view into a query appears to slow the query down.  There
> > > > is a cross database reference to a table which has its own indexes.  Creating
> > > > an indexed view similar to the table minus a field or two and substituting
> > > > the view for the table seems to slow the query down.  This may be logical and
> > > > if so, an answer may help me understand how to better speed up a query.
> > > >
> > > > Example:
> > > >
> > > > Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.ixview a
> > > > on a.x=b.x
> > > >
> > > > slower than
> > > >
> > > > Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.table2 a
> > > > on a.x=b.x
> > > > --
> > > > Regards,
> > > > Jamie
Author
21 Nov 2006 8:30 AM
John Bell
Hi

NOEXPAND is a hint

SELECT * FROM IndxVW WITH (NOEXPAND) WHERE monthname like 'Feb%'
or
SELECT * FROM IndxVW WITH (NOEXPAND,INDEX(1)) WHERE monthname like 'Feb%'

EXPAND VIEWS is an option

SELECT * FROM IndxVW WHERE monthname like 'Feb%' OPTION (EXPAND VIEWS)

See books online for more.

John

Show quoteHide quote
"thejamie" wrote:

> Such as: (???)
> Create View IndxVw WITH SCHEMABINDING as
> Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.ixview a
> on a.x=b.x where dattimestmp between '01-01-05' and '12-31-05'
>
> Assume INDXVW_MYNDX is the clustered Index
>
> Then to use the view
> SET NOEXPAND ON
> SELECT * FROM IndxVW (INDXVW_MYNDX) WHERE monthname like 'Feb%'
> SET NOEXPAND OFF
>
> Or do I have the concept wrong?
>
> --
> Regards,
> Jamie
>
>
> "John Bell" wrote:
>
> > Hi
> >
> > I am not sure what has happened to the other post...
> >
> > You will need to use the NOEXPAND hint to make sure the indexed view is used.
> >
> > John
> >
> > "thejamie" wrote:
> >
> > > We are using the STANDARD edition.
> > > --
> > > Regards,
> > > Jamie
> > >
> > >
> > > "John Bell" wrote:
> > >
> > > > Hi
> > > >
> > > > Which edition are you using? Enterprise  Edition will use Indexed views
> > > > without additional hints but other editions need the NOEXPAND hint to use
> > > > them. If you don't want to use an Indexed View in Enterprise Edition use the
> > > > EXPAND VIEWS hint. Check out your query execution plan to see what is being
> > > > used.
> > > >
> > > > John
> > > >
> > > > "thejamie" wrote:
> > > >
> > > > > Placing an indexed view into a query appears to slow the query down.  There
> > > > > is a cross database reference to a table which has its own indexes.  Creating
> > > > > an indexed view similar to the table minus a field or two and substituting
> > > > > the view for the table seems to slow the query down.  This may be logical and
> > > > > if so, an answer may help me understand how to better speed up a query.
> > > > >
> > > > > Example:
> > > > >
> > > > > Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.ixview a
> > > > > on a.x=b.x
> > > > >
> > > > > slower than
> > > > >
> > > > > Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.table2 a
> > > > > on a.x=b.x
> > > > > --
> > > > > Regards,
> > > > > Jamie
Author
28 Nov 2006 7:01 PM
thejamie
John,

If I understand correctly, an indexed view can be used as a way of obtaining
a subset of data from a very large table.  When I create an indexed view
against a table, it causes values that are written to this table to fail.  
When the inserted value affects the where condition - example: view contains
values in table where flag = 0 - and a new value is inserted which contains
the value with a flag of zero - thus forcing the index to try to rebuild
itself.  In the rebuild on such a large table, it prevents the value from
being written to the table.  

All the attempts made by me to create an indexed view have resulted in a
catastrophic failure on the database system.   These failures make me doubt
what value exists in an indexed view.   So far, they do not seem to be
faster, they cause the database optimization routines to fail, they cause
production to go down... I'd truly like to see a solid example of when an
indexed view makes sense.  It would make sense that they work but..., under
what circumstances?  


--
Regards,
Jamie


Show quoteHide quote
"John Bell" wrote:

> Hi
>
> NOEXPAND is a hint
>
> SELECT * FROM IndxVW WITH (NOEXPAND) WHERE monthname like 'Feb%'
> or
> SELECT * FROM IndxVW WITH (NOEXPAND,INDEX(1)) WHERE monthname like 'Feb%'
>
> EXPAND VIEWS is an option
>
> SELECT * FROM IndxVW WHERE monthname like 'Feb%' OPTION (EXPAND VIEWS)
>
> See books online for more.
>
> John
>
> "thejamie" wrote:
>
> > Such as: (???)
> > Create View IndxVw WITH SCHEMABINDING as
> > Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.ixview a
> > on a.x=b.x where dattimestmp between '01-01-05' and '12-31-05'
> >
> > Assume INDXVW_MYNDX is the clustered Index
> >
> > Then to use the view
> > SET NOEXPAND ON
> > SELECT * FROM IndxVW (INDXVW_MYNDX) WHERE monthname like 'Feb%'
> > SET NOEXPAND OFF
> >
> > Or do I have the concept wrong?
> >
> > --
> > Regards,
> > Jamie
> >
> >
> > "John Bell" wrote:
> >
> > > Hi
> > >
> > > I am not sure what has happened to the other post...
> > >
> > > You will need to use the NOEXPAND hint to make sure the indexed view is used.
> > >
> > > John
> > >
> > > "thejamie" wrote:
> > >
> > > > We are using the STANDARD edition.
> > > > --
> > > > Regards,
> > > > Jamie
> > > >
> > > >
> > > > "John Bell" wrote:
> > > >
> > > > > Hi
> > > > >
> > > > > Which edition are you using? Enterprise  Edition will use Indexed views
> > > > > without additional hints but other editions need the NOEXPAND hint to use
> > > > > them. If you don't want to use an Indexed View in Enterprise Edition use the
> > > > > EXPAND VIEWS hint. Check out your query execution plan to see what is being
> > > > > used.
> > > > >
> > > > > John
> > > > >
> > > > > "thejamie" wrote:
> > > > >
> > > > > > Placing an indexed view into a query appears to slow the query down.  There
> > > > > > is a cross database reference to a table which has its own indexes.  Creating
> > > > > > an indexed view similar to the table minus a field or two and substituting
> > > > > > the view for the table seems to slow the query down.  This may be logical and
> > > > > > if so, an answer may help me understand how to better speed up a query.
> > > > > >
> > > > > > Example:
> > > > > >
> > > > > > Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.ixview a
> > > > > > on a.x=b.x
> > > > > >
> > > > > > slower than
> > > > > >
> > > > > > Select b.x,b.y, a.z from table1 b left outer join diffdb.dbo.table2 a
> > > > > > on a.x=b.x
> > > > > > --
> > > > > > Regards,
> > > > > > Jamie

Bookmark and Share