Solved

Optimize view

Posted on 2011-03-23
6
504 Views
Last Modified: 2012-05-11
Hello,

Is it possible to optimize this view ?
CREATE VIEW [livelink].[WebNodes] AS SELECT a.OwnerID,a.DataID,a.ParentID, a.UserID,a.GroupID,
a.UPermissions,a.GPermissions,a.WPermissions,a.SPermissions,a.PermID, a.Name,a.DataType,a.SubType,
a.DComment,a.DCategory,a.CreateDate,a.ModifyDate,a.ExAtt1, a.Reserved,a.ReservedBy,a.ReservedDate,a.Ordering,
a.ChildCount,a.VersionNum, a.AssignedTo,a.Status,a.Priority,a.GIF,a.Catalog, b.FileName,b.FileType,b.DataSize,
b.ResSize,b.MimeType, c.Name OwnerName,a.OriginDataID, a.Major, a.Position FROM DTree
a LEFT OUTER JOIN DVersData b ON (a.DataID=b.DocID and (a.Major = b.Version
or (a.Major IS NULL and a.VersionNum=b.Version))), KUAF c WHERE a.CreatedBy=c.ID and b.VerType is NULL
GO


Thanks
bibi
0
Comment
Question by:bibi92
  • 4
6 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 35198461
It looks like intentionally or not you have a CROSS JOIN:
KUAF is not joined to anything.

If that is the case than use the correct syntax by losing the , and changing it to CROSS JOIN KUAF c
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 35198498
See below for the same VIEW in a readable format and using the correct syntax:

Make sure the CROSS JOIN is required.
CREATE VIEW [livelink].[WebNodes]
AS
SELECT  a.OwnerID,
        a.DataID,
        a.ParentID,
        a.UserID,
        a.GroupID,
        a.UPermissions,
        a.GPermissions,
        a.WPermissions,
        a.SPermissions,
        a.PermID,
        a.Name,
        a.DataType,
        a.SubType,
        a.DComment,
        a.DCategory,
        a.CreateDate,
        a.ModifyDate,
        a.ExAtt1,
        a.Reserved,
        a.ReservedBy,
        a.ReservedDate,
        a.Ordering,
        a.ChildCount,
        a.VersionNum,
        a.AssignedTo,
        a.Status,
        a.Priority,
        a.GIF,
        a.Catalog,
        b.FileName,
        b.FileType,
        b.DataSize,
        b.ResSize,
        b.MimeType,
        c.Name OwnerName,
        a.OriginDataID,
        a.Major,
        a.Position
FROM    DTree a
        LEFT OUTER JOIN DVersData b ON a.DataID = b.DocID 
			    AND (a.Major = b.Version OR (a.Major IS NULL AND a.VersionNum = b.Version))
        CROSS JOIN KUAF c
WHERE   a.CreatedBy = c.ID
        AND b.VerType IS NULL

Open in new window

0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 35198533
Oops my mistake I see where you are relating KUAF, but do it this way:
CREATE VIEW [livelink].[WebNodes]
AS
SELECT  a.OwnerID,
        a.DataID,
        a.ParentID,
        a.UserID,
        a.GroupID,
        a.UPermissions,
        a.GPermissions,
        a.WPermissions,
        a.SPermissions,
        a.PermID,
        a.Name,
        a.DataType,
        a.SubType,
        a.DComment,
        a.DCategory,
        a.CreateDate,
        a.ModifyDate,
        a.ExAtt1,
        a.Reserved,
        a.ReservedBy,
        a.ReservedDate,
        a.Ordering,
        a.ChildCount,
        a.VersionNum,
        a.AssignedTo,
        a.Status,
        a.Priority,
        a.GIF,
        a.Catalog,
        b.FileName,
        b.FileType,
        b.DataSize,
        b.ResSize,
        b.MimeType,
        c.Name OwnerName,
        a.OriginDataID,
        a.Major,
        a.Position
FROM    DTree a
        LEFT OUTER JOIN DVersData b ON a.DataID = b.DocID 
			    AND (a.Major = b.Version OR (a.Major IS NULL AND a.VersionNum = b.Version))
        INNER JOIN KUAF c ON a.CreatedBy = c.ID
WHERE   b.VerType IS NULL

Open in new window

0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 39

Expert Comment

by:lcohan
ID: 35202443
Why not the INNER JOIN first?

CREATE VIEW [livelink].[WebNodes] AS
SELECT a.OwnerID,a.DataID,a.ParentID, a.UserID,a.GroupID, a.UPermissions,a.GPermissions,a.WPermissions,
            a.SPermissions,a.PermID, a.Name,a.DataType,a.SubType,a.DComment,a.DCategory,a.CreateDate,a.ModifyDate,
            a.ExAtt1, a.Reserved,a.ReservedBy,a.ReservedDate,a.Ordering, a.ChildCount,a.VersionNum, a.AssignedTo,
            a.[Status],a.Priority,a.GIF,a.[Catalog], b.[FileName],b.FileType,b.DataSize,b.ResSize,b.MimeType,
            c.Name OwnerName,a.OriginDataID, a.Major, a.Position
FROM DTree a
      INNER JOIN KUAF c ON a.CreatedBy=c.ID
      LEFT OUTER JOIN DVersData b ON (a.DataID=b.DocID and (a.Major = b.Version or (a.Major IS NULL and a.VersionNum=b.Version))) and b.VerType is NULL
GO
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 35203525
>>Why not the INNER JOIN first?<<
Because it does not make any difference in performance?
0
 

Author Closing Comment

by:bibi92
ID: 35205839
Thanks
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question