SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Issue while creating indexed view after joining two non related tables


Issue while creating indexed view after joining two non related tables

Author
Message
shyam00
shyam00
SSC Rookie
SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)

Group: General Forum Members
Points: 34 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.
HowardW
HowardW
SSCertifiable
SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)

Group: General Forum Members
Points: 6671 Visits: 9892
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
Igor Micev
Igor Micev
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10637 Visits: 5157
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,
My blog: www.igormicev.com
shyam00
shyam00
SSC Rookie
SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)

Group: General Forum Members
Points: 34 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.
ChrisM@Work
ChrisM@Work
SSC-Forever
SSC-Forever (43K reputation)SSC-Forever (43K reputation)SSC-Forever (43K reputation)SSC-Forever (43K reputation)SSC-Forever (43K reputation)SSC-Forever (43K reputation)SSC-Forever (43K reputation)SSC-Forever (43K reputation)

Group: General Forum Members
Points: 43145 Visits: 20015
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
Igor Micev
Igor Micev
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10637 Visits: 5157
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,
My blog: www.igormicev.com
Erland Sommarskog
Erland Sommarskog
SSCertifiable
SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)

Group: General Forum Members
Points: 5524 Visits: 875
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
shyam00
shyam00
SSC Rookie
SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)

Group: General Forum Members
Points: 34 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?
Erland Sommarskog
Erland Sommarskog
SSCertifiable
SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)

Group: General Forum Members
Points: 5524 Visits: 875
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
shyam00
shyam00
SSC Rookie
SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)

Group: General Forum Members
Points: 34 Visits: 15
Out of those ten tables 9 are related. Only one table is non related one. I will give a sample layout soon.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search