Solved

Optimize view

Posted on 2011-03-23
6
492 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Suggested Solutions

Title # Comments Views Activity
Live Storage Vmotion VMs with shared VMDK 10 55
SqlServer no dupes 25 34
sql server tables from access 18 17
VB.NET 2008 - SQL Timeout 9 23
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

786 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