Solved

Optimize view

Posted on 2011-03-23
6
472 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now