473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Deadlock in View with Select Union - Creating A/S Dimension

I've got a view that creates a parent child relationship, this view is
used in Analysis Services to create a dimension in a datastore. This
query tends to deadlock after about 10 days of running smoothly. Only
way to fix it is to reboot the box, I can recycle the services for a
quick fix but that usually only works for the next 1-2 times I call the
view.

This view is used to create a breakdown of the bill-to locations from
Continent-Global Region-Country-Sub Region-State/Province- City-Zip
Code

Yes, I know that sounds crazy, but it was a requirement.

So why would I get a deadlock on a SELECT Query? Is there a way to set
the Isolation level to Repeatable Read for a view?

Here is the view code:

CREATE View dbo.vwBillTo
as
-- US ZipCode
Select 'Parent'=z.City+' ('+ ISNULL(RTRIM(z.State_shrt), '0') +
cast(IsNull(z.US_Region_wk,0) as varchar) + ')'
,z.Zipcode_WK as 'Child'
,z.ZipCode_WK as 'Child_ID'
From dbo.DIM_POSTAL_CODES_US z
inner join dbo.FACT_SALES f
on z.ZipCode_WK=f.Bill_To
Where z.US_Region_wk IS NOT NULL
Group by z.City,z.ZipCode_WK,US_Region_wk, z.State_shrt

Union
--City
Select 'Parent'=z.State_Long+' ('+cast(IsNull(z.US_Region_wk,0) as
varchar)+')'
,z.City as 'Child'
,z.City + ' ('+ ISNULL(RTRIM(z.State_shrt), '0') +
cast(IsNull(z.US_Region_wk,0) as varchar) + ')' as 'Child_ID'
From dbo.DIM_POSTAL_CODES_US z
Where z.US_Region_wk IS NOT NULL
Group by z.State_Long,z.City,z.State_shrt,z.US_Region_wk

Union

-- Canada ZipCode
Select 'Parent'=z.City+ ' ('+ ISNULL(RTRIM(z.province_shrt), '0') +
')'
,z.Zipcode_WK as 'Child'
,z.Zipcode_WK as 'Child_ID'
From dbo.DIM_POSTAL_CODES_CAN z
inner join dbo.FACT_SALES f
on z.ZipCode_WK=f.Bill_To
Group by z.Province_Long,z.ZipCode_WK, z.City, z.province_shrt

Union

--City
Select 'Parent'=z.Province_Long
,z.City as 'Child'
,z.City+ ' ('+ ISNULL(RTRIM(z.province_shrt), '0') + ')' as
'Child_ID'
From dbo.DIM_POSTAL_CODES_CAN z
inner join dbo.FACT_SALES f
on z.ZipCode_WK=f.Bill_To
Group by z.Province_Long,z.ZipCode_WK, z.City, z.province_shrt
Union

-- Canada Province
Select 'CANADA'
,Province_Long
,Province_Long
From dbo.DIM_POSTAL_CODES_CAN
Group by Province_Long

Union
-- Country
Select t.Region_NK
,c.Country_Name
,c.Country_Name
From dbo.DIM_COUNTRY c
Inner Join dbo.DIM_WORLD_REGION t
On c.Region_WK=t.Region_WK
Where c.Country_Name Is Not Null
Group by t.Region_NK, c.Country_Name

Union

-- SubRegion
Select c.Country_Name
,sr.US_Region_Name
,sr.US_Region_Name
From dbo.DIM_US_REGION sr
Inner Join dbo.DIM_COUNTRY c
On sr.Country_wk=c.Country_WK
Group by c.Country_Name, sr.US_Region_Name

Union
--Region
Select sr.US_Region_Name
,c.State_Long
,c.State_Long+' ('+cast(c.US_Region_wk as varchar)+')'
From dbo.DIM_US_REGION sr
Inner Join dbo.DIM_POSTAL_CODES_US c
On sr.US_Region_WK=c.US_Region_WK
Group by sr.US_Region_Name, c.State_Long,c.US_Region_wk

Union
-- Continent
Select Null
,Region_NK
,Region_NK
From dbo.DIM_WORLD_REGION

Where Region_NK Is Not Null

Jul 23 '05 #1
1 3317
(jt******@tycovalves.com) writes:
I've got a view that creates a parent child relationship, this view is
used in Analysis Services to create a dimension in a datastore. This
query tends to deadlock after about 10 days of running smoothly. Only
way to fix it is to reboot the box, I can recycle the services for a
quick fix but that usually only works for the next 1-2 times I call the
view.

This view is used to create a breakdown of the bill-to locations from
Continent-Global Region-Country-Sub Region-State/Province- City-Zip
Code

Yes, I know that sounds crazy, but it was a requirement.

So why would I get a deadlock on a SELECT Query? Is there a way to set
the Isolation level to Repeatable Read for a view?


You can always issue SET TRANSACTION ISOALATION LEVEL prior to running
the SELECT. Not sure that it would help though.

Indeed a deadlock on a single SELECT sounds weird. I know there are
cases where parallelism can lead to deadlock within a single query,
but that would be INSERT/UPDATE/DELETE.

But how do you know that is not interacting with any other query? Have
you enabled trace flag 1204 and checked the error log?
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Karen Bailey | last post by:
Hi, I am attempting to create a view that will rollup or group like, consecutive data. I have created a view using unions, but the statement is extremely slow. Here is example data Colour...
4
by: MD | last post by:
I am trying to create a dynamic SQL statement to create a view. I have a stored procedure, which based on the parameters passed calls different stored procedures. Each of this sub stored procedure...
2
by: jc | last post by:
Hi. A question I have is with regard to the use of views with SQL2000. If I have a view called "A_view" and used in the following manner; ---------------- SELECT ... FROM A_View WHERE .... ...
10
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I...
6
by: Eugene | last post by:
Summary: ---------- Updates against UNION ALL view does't do branch elimination, but rather reads all the branches (partitions). The case scenario(DB2 V8.1.4a ESE, AIX 5.2):...
6
by: _link98 | last post by:
Problem: getting SQL0181N for queries on nicknames to remote Union-All-View. Can't see what I'm doing wrong yet, maybe someone has seen this before. Environment: UDB ESE 8.1 + FIXPAK 9A, on...
104
by: Beowulf | last post by:
I have the view below and if I use vwRouteReference as the rowsource for a combo box in an MS Access form or run "SELECT * FROM vwRouteReference" in SQL Query Analyzer, the rows don't come through...
7
by: jason.langdale | last post by:
I have 3 tables I want to use in a view. Table A has field 1,2,3,4,5 and table B has field 1,2,3,4,5. I want to do a union on these. (I have done so successfully if I stop here) I also want to join...
5
by: Altman | last post by:
I have a customer using our program with SQL server and is occasionally getting a "Transaction (process ID xxxxx) was deadlocked on lock resources with another process and has been chosen as the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.