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

Issue while creating indexed view after joining two non related tables Expand / Collapse
Author
Message
Posted Friday, July 5, 2013 4:00 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 16, 2013 11:06 PM
Points: 4, Visits: 15
I am trying an create the indexed view after joining two non related tables. Please correct me if my approach is wrong and add your thoughts for the issue I had mentioned below.


Syntax used for creating view

CREATE VIEW MyViewName
WITH SCHEMABINDING
AS

select field1, field 2 from tableOne (not the exact query)

FULL OUTER JOIN

select field1, field2 from tableTwo (not the exact query)

Syntax used for creating index on view

CREATE UNIQUE CLUSTERED INDEX ClusteredIndexTest
ON dbo.MyViewName(field1,field2)


Issue occurred while trying to create index
Msg 10109
Cannot create index on view "db.dbo.MyViewName" because it references derived table "tableOne" (defined by SELECT statement in FROM clause). Consider removing the reference to the derived table or not indexing the view.
Post #1470649
Posted Friday, July 5, 2013 4:25 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 6:31 AM
Points: 1,191, Visits: 9,882
Indexed views have some stringent requirements on what kind of view definition they can be created on. Derived tables are not allowed.

Have a look here for a complete list of what's not allowed:

http://msdn.microsoft.com/en-us/library/ms191432.aspx#Restrictions
Post #1470652
Posted Friday, July 5, 2013 4:41 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 1:33 PM
Points: 2,980, Visits: 3,013
Hi,

OUTER JOINs are not supported in Indexed views because rows can logically disappear under some update operations in the base tables.

Regards
IgorMi





Igor Micev,
SQL Server developer at Seavus
www.seavus.com
Post #1470657
Posted Friday, July 5, 2013 6:39 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 16, 2013 11:06 PM
Points: 4, Visits: 15
Thanks for the reply.

Is there any way to tackle my scenario mentioned here.?
I need to combine (UNION) two non related derived tables and create an indexed view on top of that. Since UNION operation is not allowed under indexed views, I had tried to join then using OUTER JOIN. (I need data from both the non related derived tables unconditionally)

Please advice.
Post #1470701
Posted Friday, July 5, 2013 6:57 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:09 AM
Points: 6,750, Visits: 13,896
shyam00 (7/5/2013)
Thanks for the reply.

Is there any way to tackle my scenario mentioned here.?
I need to combine (UNION) two non related derived tables and create an indexed view on top of that. Since UNION operation is not allowed under indexed views, I had tried to join then using OUTER JOIN. (I need data from both the non related derived tables unconditionally)

Please advice.


You're experiencing difficulty in creating an indexed view. Ok, so backtrack for a moment. View indexing is a performance measure. Somewhere, you're attempting to use these two tables, JOINed or UNIONed or whatever, in another query. Can you show an example of such a query, and if possible an actual execution plan? In the event that the indexed view you would ideally like to see is impossible to create, there may well be alternative means of accelerating the queries that the view would by used by.


“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1470718
Posted Friday, July 5, 2013 12:57 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 1:33 PM
Points: 2,980, Visits: 3,013
shyam00 (7/5/2013)
Thanks for the reply.

Is there any way to tackle my scenario mentioned here.?
I need to combine (UNION) two non related derived tables and create an indexed view on top of that. Since UNION operation is not allowed under indexed views, I had tried to join then using OUTER JOIN. (I need data from both the non related derived tables unconditionally)

Please advice.


Hi,

Having an indexed view is almost same as having a table. As you have troubles creating it, why don't you think for another alternative?
- You can investigate on improving the performance of the queries using those selects you want to put in a view.
- You can create a separate table and add some work around to fill it appropriately.

Regards,
IgorMi




Igor Micev,
SQL Server developer at Seavus
www.seavus.com
Post #1470842
Posted Friday, July 5, 2013 1:19 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, September 24, 2014 1:24 PM
Points: 805, Visits: 722
shyam00 (7/5/2013)
Thanks for the reply.

Is there any way to tackle my scenario mentioned here.?
I need to combine (UNION) two non related derived tables and create an indexed view on top of that. Since UNION operation is not allowed under indexed views, I had tried to join then using OUTER JOIN. (I need data from both the non related derived tables unconditionally)

Please advice.


And the advice is: start from the beginning. That is, why do you need this view? Why do you need it to be indexed?


Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Post #1470856
Posted Sunday, July 7, 2013 8:57 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 16, 2013 11:06 PM
Points: 4, Visits: 15
Currently I am building a search(filter) dash board application which is querying the underlying tables (OLTP) in MS SQL server 2008.
There are around 10 tables I need to query for getting the consolidated search results based on the filter condition. Most of the tables can be joined together, but there are some un-related tables as well.

There is performance trade off if I query each of these table and join them directly since number of concurrent users using this application will be more than 1000. Also some of the tables contain more than million records. That's why I didn't tried to use a stored procedure.

Based on this I though of using an Indexed view which contain all the fields required by search filter. And this indexed view getting refreshed using some trigger. Is there any other approach I can use in this scenario?
Post #1470974
Posted Sunday, July 7, 2013 1:55 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, September 24, 2014 1:24 PM
Points: 805, Visits: 722
Since the description you give is on a fairly high-level, it is difficult to give exact advice, but, no, from what you say I don't think indexed views is what you need.

To say more, we would need to see the tables (or preferrably some simplified layout of them) and how they are related. It sounds a little funny that you would search 10 entirely unrelated tables, so I assume that there is some form of relation between them.

What I can say is that indexing common search terms helps a log.


Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Post #1470988
Posted Sunday, July 7, 2013 10:41 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 16, 2013 11:06 PM
Points: 4, Visits: 15
Out of those ten tables 9 are related. Only one table is non related one. I will give a sample layout soon.
Post #1471032
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse