July 4, 2014 at 7:08 am
Hi Experts,
We have got a query for fine tunning and it is using lot of CTE ,how can i check the execution plan of that?
CREATE VIEW Mercy
AS
with ADR
as
(
SELECT urpx.RoleID ,
urx.UserID
FROM [DBA].dbo.URPX WITH ( NOLOCK )
INNER JOIN [DBA].dbo.URX WITH ( NOLOCK ) ON urpx.RoleID = urx.RoleID
WHERE PermissionID = '1'
),
SDR
as
(
-- Collect the roles that a configured with Sales Team Create permission
-- This will include Sales Director , Suite Admin,
SELECT urpx.RoleID
FROM [DBA].dbo.URPX WITH ( NOLOCK )
INNER JOIN [DBA].dbo.URX WITH ( NOLOCK ) ON urpx.RoleID = urx.RoleID
LEFT OUTER JOIN ADR ON ADR.UserID = urx.UserID
WHERE ADR.RoleID IS NULL
AND PermissionID='2'
)
July 4, 2014 at 7:12 am
Write a typical select from the view, run it with Include Actual Execution Plan enabled.
There's nothing special about a CTE with it comes to exec plan. It's just a named subquery.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
July 4, 2014 at 7:20 am
Be careful with all of those WITH(NOLOCK) though. Unless you like dirty data.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
July 4, 2014 at 7:20 am
What you've shown of your view definition equates to this:
SELECT
urpx.RoleID
FROM [DBA].dbo.URPX
INNER JOIN [DBA].dbo.URX
ON urpx.RoleID = urx.RoleID
LEFT OUTER JOIN (
SELECT
urx.RoleID,
urx.UserID
FROM [DBA].dbo.URX
INNER JOIN [DBA].dbo.URPX
ON urpx.RoleID = urx.RoleID
WHERE PermissionID = '1'
) ADR ON ADR.UserID = urx.UserID
WHERE ADR.RoleID IS NULL
AND PermissionID = '2'
Since both tables are read twice, this can almost certainly be improved. Which table contains column [PermissionID]?
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
July 4, 2014 at 7:50 am
Thanks Gail & Koen
July 4, 2014 at 7:52 am
ChrisM@Work (7/4/2014)
What you've shown of your view definition equates to this:
SELECT
urpx.RoleID
FROM [DBA].dbo.URPX
INNER JOIN [DBA].dbo.URX
ON urpx.RoleID = urx.RoleID
LEFT OUTER JOIN (
SELECT
urx.RoleID,
urx.UserID
FROM [DBA].dbo.URX
INNER JOIN [DBA].dbo.URPX
ON urpx.RoleID = urx.RoleID
WHERE PermissionID = '1'
) ADR ON ADR.UserID = urx.UserID
WHERE ADR.RoleID IS NULL
AND PermissionID = '2'
Since both tables are read twice, this can almost certainly be improved. Which table contains column [PermissionID]?
Thanks a lot Chris. The column permission is in URPX table. The view actually calling 6 CTE all are select, i am a real noob in this and trying to learn.. Thanks a lot again for your help.
July 4, 2014 at 8:31 am
Can you post the whole view definition?
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
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply