question

wasp avatar image
wasp asked

Partitioned views and locking

We are using partitioned views, and they work fine if we consider the partition elimination goal: if we run a query in a partitioned view specifying a clause on the column we choose as the discriminator, we can see from the actual execution plan that only the table related to the specified discriminator value is hit. But we incur in locking problems if there are concurrent INSERT or UPDATE statements, even if those ones are NOT hitting the table selected by the discriminator. Analyzing the locks I can see that, even if the execution plan shows that only the right one table is read, IS locks are still put on ALL the tables in the partitioned view, and of course if someone else has already put an X locks on one of those the whole query running on the partitioned view gets locked on that one, even if the table with an X upon is not read at all. Is this a limitation of partitioned view in general, or there is a way to avoid it while sticking with partitioned views? We created the partitioned view and the related things following the Sql Books Online recommendations. Thanks Wasp [query plan][1] [view and constraint def][2] [1]: /storage/temp/264-sqlplan.txt [2]: /storage/temp/265-view_constraint.txt
partitioning
sqlplan.txt (12.0 KiB)
6 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Cyborg avatar image Cyborg commented ·
Can you post the execution plan here?
0 Likes 0 ·
wasp avatar image wasp commented ·
I could, but not sure what's the best way to post a query plan here, the text output from SET STATISTICS PROFILE does not seem much readable to me, and the xml in .sqplan is quite big... which one? or are there more options? not really a dba... :)
0 Likes 0 ·
Cyborg avatar image Cyborg commented ·
Estimated Execution Plan, right click, save the execution plan and attach here.
0 Likes 0 ·
wasp avatar image wasp commented ·
Ok, done, thx
0 Likes 0 ·
Usman Butt avatar image Usman Butt commented ·
Can you please post the VIEW definition and the CHECK constraint definition on the discriminator column?
0 Likes 0 ·
Show more comments

1 Answer

·
Cyborg avatar image
Cyborg answered
Thanks for the Execution plan, here are my quick thoughts - You said that you have a partitioned view, but the query is not referring the view, its getting the records from **HEAP**, consider creating a clustered index on the table MKOnlineSeries_Value. Doing this will improve performance of other SELECT queries that access this table. - Consider creating non-clustered index on MKOnlineSeries_Value(Catalog) column with included columns as columns from your SELECT list. - If you are in Enterprise edition SQL Server is clever enough to refer the indexed views if it thinks its easy to get the data from the indexed view rather than the defined tables in the query, note this can happen even if the indexed views are not used in your querey.
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

wasp avatar image wasp commented ·
Thanks for your answer. Not sure I follow you when you say that the query is not referring the partitioned view, the query (which is a sample) is "select top 200 * from SeriesValues where Catalog = 'MKON'", and SeriesValues is the partitioned view, which is a union of 4 tables, among them MKonline_SeriesValue... Unluckily, no Enterprise Edition...
0 Likes 0 ·
Cyborg avatar image Cyborg commented ·
I thought your tables are partitioned( http://msdn.microsoft.com/en-us/library/ms345146(v=sql.90).aspx), this is only available in Enterprise edition. I guess you are doing a horizontal partitioning. So its enough to create the recommended index.
0 Likes 0 ·
wasp avatar image wasp commented ·
Yep, horizontal partitioning, we cannot do table partitioning. I'll check the indices, thx.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.