Solved

SQL Query ...

Posted on 2011-02-28
9
279 Views
Last Modified: 2012-08-13
Can someone help me make this query more efficient?

It appears to choke up quite a bit the more it is used...
WITH  CategoryTree
		AS (SELECT  r.catID, r.catName, 0 Level, r.parentID,
					CAST(r.catName AS NVarChar(Max)) AS "Path"
			FROM    vwSelectPartCategory r
			WHERE   r.parentID = 0
			
			UNION ALL
			
			SELECT  c.catID, c.catName, p.Level + 1 AS Level, c.parentID,
					CAST((p.path + ',' + c.catName) AS NVarChar(Max)) AS "Path"
			FROM    vwSelectPartCategory c
					INNER JOIN CategoryTree p
					  ON p.catID = c.parentID
		   )
		   
	SELECT [Path]
	FROM    CategoryTree
	Where 1 = 1
	And (@CatID Is Null Or catID = @CatID)
	Order By [Path]

Open in new window


p.s.   It's used to pull a breadcrumb style navigation from a shopping cart db
0
Comment
Question by:kevp75
9 Comments
 
LVL 15

Assisted Solution

by:derekkromm
derekkromm earned 400 total points
ID: 35000474
First thing I would do is check your indexing.

Execute the query with an Execution Plan (ctrl+m prior to executing), and check for table scans and/or index scans. Your goal is to change these to Index Seeks by creating the correct indexes on the underlying tables.

If you can provide more information, like table structures and existing indexes, etc., it'll be easier to help.

The code itself looks clean - T-SQL just isn't meant to be used for processor-intensive processing like this (although its something you have to do from time-to-time)
0
 
LVL 6

Expert Comment

by:LCSandman8301
ID: 35000501
do you have an index on the table vwSelectPartCategory.parentid, that includes catid and catname? or the underlying table that the view is built upon. do you have a copy of the execution plan? so we can see where the bottlenecks may be occuring?
0
 
LVL 13

Assisted Solution

by:dwkor
dwkor earned 100 total points
ID: 35000516
Get rid of (@CatId is null) or (CatID = @CatID). SQL Server would use scan regardless of @CatId value.  There are some service packs (different for every version 2005/2008/R2) that can alter this behavior with recompile option although it's not consistent and you should not rely on it.

And of course, make sure that indexes are correct.
if @CatId is null
begin
	;WITH  CategoryTree
	AS (
		SELECT  r.catID, r.catName, 0 Level, r.parentID,
				CAST(r.catName AS NVarChar(Max)) AS "Path"
		FROM    vwSelectPartCategory r
		WHERE   r.parentID = 0
				
		UNION ALL
				
		SELECT  c.catID, c.catName, p.Level + 1 AS Level, c.parentID,
				CAST((p.path + ',' + c.catName) AS NVarChar(Max)) AS "Path"
		FROM    vwSelectPartCategory c INNER JOIN CategoryTree p ON 
			p.catID = c.parentID
	)
	SELECT [Path]
	FROM    CategoryTree
	Order By [Path]
end
else begin
	;WITH  CategoryTree
	AS (
		SELECT  r.catID, r.catName, 0 Level, r.parentID,
				CAST(r.catName AS NVarChar(Max)) AS "Path"
		FROM    vwSelectPartCategory r
		WHERE   r.parentID = 0 and r.CatId = @CatId
				
		UNION ALL
				
		SELECT  c.catID, c.catName, p.Level + 1 AS Level, c.parentID,
				CAST((p.path + ',' + c.catName) AS NVarChar(Max)) AS "Path"
		FROM    vwSelectPartCategory c INNER JOIN CategoryTree p ON 
			p.catID = c.parentID
	)
	SELECT [Path]
	FROM    CategoryTree
	Order By [Path]
end

Open in new window

0
 
LVL 25

Author Comment

by:kevp75
ID: 35000751
execution plan XML
<?xml version="1.0" encoding="utf-16"?>
<ShowPlanXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.1" Build="10.50.1600.1" xmlns="http://schemas.microsoft.com/sqlserver/2004/07/showplan">
  <BatchSequence>
    <Batch>
      <Statements>
        <StmtSimple StatementCompId="1" StatementEstRows="14.8103" StatementId="1" StatementOptmLevel="FULL" StatementOptmEarlyAbortReason="GoodEnoughPlanFound" StatementSubTreeCost="0.07163" StatementText="	Declare @CatID		Int&#xD;&#xA;	&#xD;&#xA;	WITH  CategoryTree&#xD;&#xA;		AS (SELECT  r.catID, r.catName, 0 Level, r.parentID,&#xD;&#xA;					CAST(r.catName AS NVarChar(Max)) AS &quot;Path&quot;&#xD;&#xA;			FROM    vwSelectPartCategory r&#xD;&#xA;			WHERE   r.parentID = 0&#xD;&#xA;			&#xD;&#xA;			UNION ALL&#xD;&#xA;			&#xD;&#xA;			SELECT  c.catID, c.catName, p.Level + 1 AS Level, c.parentID,&#xD;&#xA;					CAST((p.path + ',' + c.catName) AS NVarChar(Max)) AS &quot;Path&quot;&#xD;&#xA;			FROM    vwSelectPartCategory c&#xD;&#xA;					INNER JOIN CategoryTree p&#xD;&#xA;					  ON p.catID = c.parentID&#xD;&#xA;		   )&#xD;&#xA;		   &#xD;&#xA;	SELECT [Path]&#xD;&#xA;	FROM    CategoryTree&#xD;&#xA;	Where 1 = 1&#xD;&#xA;	And (@CatID Is Null Or catID = @CatID)&#xD;&#xA;	Order By [Path]" StatementType="SELECT" QueryHash="0x4EE4ECCD2F342CC8" QueryPlanHash="0xD15B4032C04F63DA">
          <StatementSetOptions ANSI_NULLS="true" ANSI_PADDING="true" ANSI_WARNINGS="true" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="true" NUMERIC_ROUNDABORT="false" QUOTED_IDENTIFIER="true" />
          <QueryPlan CachedPlanSize="32" CompileTime="15" CompileCPU="15" CompileMemory="312">
            <RelOp AvgRowSize="4023" EstimateCPU="0.000193863" EstimateIO="0.0112613" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="14.8103" LogicalOp="Sort" NodeId="0" Parallel="false" PhysicalOp="Sort" EstimatedTotalSubtreeCost="0.07163">
              <OutputList>
                <ColumnReference Column="Recr1019" />
              </OutputList>
              <MemoryFractions Input="1" Output="1" />
              <Sort Distinct="false">
                <OrderBy>
                  <OrderByColumn Ascending="true">
                    <ColumnReference Column="Recr1019" />
                  </OrderByColumn>
                </OrderBy>
                <RelOp AvgRowSize="4023" EstimateCPU="1.63453E-05" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="14.8103" LogicalOp="Filter" NodeId="1" Parallel="false" PhysicalOp="Filter" EstimatedTotalSubtreeCost="0.0601749">
                  <OutputList>
                    <ColumnReference Column="Recr1019" />
                  </OutputList>
                  <Filter StartupExpression="false">
                    <RelOp AvgRowSize="4027" EstimateCPU="1.20186E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="24.0372" LogicalOp="Lazy Spool" NodeId="2" Parallel="false" PhysicalOp="Index Spool" EstimatedTotalSubtreeCost="0.0601586">
                      <OutputList>
                        <ColumnReference Column="Expr1024" />
                        <ColumnReference Column="Recr1015" />
                        <ColumnReference Column="Recr1016" />
                        <ColumnReference Column="Recr1017" />
                        <ColumnReference Column="Recr1018" />
                        <ColumnReference Column="Recr1019" />
                      </OutputList>
                      <Spool Stack="true">
                        <RelOp AvgRowSize="4027" EstimateCPU="2.40372E-08" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="24.0372" LogicalOp="Concatenation" NodeId="3" Parallel="false" PhysicalOp="Concatenation" EstimatedTotalSubtreeCost="0.0591774">
                          <OutputList>
                            <ColumnReference Column="Expr1024" />
                            <ColumnReference Column="Recr1015" />
                            <ColumnReference Column="Recr1016" />
                            <ColumnReference Column="Recr1017" />
                            <ColumnReference Column="Recr1018" />
                            <ColumnReference Column="Recr1019" />
                          </OutputList>
                          <Concat>
                            <DefinedValues>
                              <DefinedValue>
                                <ColumnReference Column="Expr1024" />
                                <ColumnReference Column="Expr1021" />
                                <ColumnReference Column="Expr1023" />
                              </DefinedValue>
                              <DefinedValue>
                                <ColumnReference Column="Recr1015" />
                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catID" />
                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catID" />
                              </DefinedValue>
                              <DefinedValue>
                                <ColumnReference Column="Recr1016" />
                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catName" />
                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catName" />
                              </DefinedValue>
                              <DefinedValue>
                                <ColumnReference Column="Recr1017" />
                                <ColumnReference Column="Expr1003" />
                                <ColumnReference Column="Expr1013" />
                              </DefinedValue>
                              <DefinedValue>
                                <ColumnReference Column="Recr1018" />
                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="parentID" />
                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="parentID" />
                              </DefinedValue>
                              <DefinedValue>
                                <ColumnReference Column="Recr1019" />
                                <ColumnReference Column="Expr1004" />
                                <ColumnReference Column="Expr1014" />
                              </DefinedValue>
                            </DefinedValues>
                            <RelOp AvgRowSize="4027" EstimateCPU="2.40372E-07" EstimateIO="0" EstimateRebinds="24.0372" EstimateRewinds="0" EstimateRows="1" LogicalOp="Compute Scalar" NodeId="4" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="2.40372E-07">
                              <OutputList>
                                <ColumnReference Column="Expr1021" />
                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catID" />
                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catName" />
                                <ColumnReference Column="Expr1003" />
                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="parentID" />
                                <ColumnReference Column="Expr1004" />
                              </OutputList>
                              <ComputeScalar>
                                <DefinedValues>
                                  <DefinedValue>
                                    <ColumnReference Column="Expr1021" />
                                    <ScalarOperator ScalarString="(0)">
                                      <Const ConstValue="(0)" />
                                    </ScalarOperator>
                                  </DefinedValue>
                                </DefinedValues>
                                <RelOp AvgRowSize="8049" EstimateCPU="2.1E-06" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="21" LogicalOp="Compute Scalar" NodeId="5" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.0183175">
                                  <OutputList>
                                    <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catID" />
                                    <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="parentID" />
                                    <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catName" />
                                    <ColumnReference Column="Expr1003" />
                                    <ColumnReference Column="Expr1004" />
                                  </OutputList>
                                  <ComputeScalar>
                                    <DefinedValues>
                                      <DefinedValue>
                                        <ColumnReference Column="Expr1003" />
                                        <ScalarOperator ScalarString="(0)">
                                          <Const ConstValue="(0)" />
                                        </ScalarOperator>
                                      </DefinedValue>
                                    </DefinedValues>
                                    <RelOp AvgRowSize="8045" EstimateCPU="5.71E-05" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="21" LogicalOp="Compute Scalar" NodeId="6" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.0180413">
                                      <OutputList>
                                        <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catID" />
                                        <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="parentID" />
                                        <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catName" />
                                        <ColumnReference Column="Expr1004" />
                                      </OutputList>
                                      <ComputeScalar>
                                        <DefinedValues>
                                          <DefinedValue>
                                            <ColumnReference Column="Expr1004" />
                                            <ScalarOperator ScalarString="CONVERT(nvarchar(max),[Staging.Turbo-Kits.com].[dbo].[TblPartCategories].[catName],0)">
                                              <Convert DataType="nvarchar(max)" Length="2147483647" Style="0" Implicit="false">
                                                <ScalarOperator>
                                                  <Identifier>
                                                    <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catName" />
                                                  </Identifier>
                                                </ScalarOperator>
                                              </Convert>
                                            </ScalarOperator>
                                          </DefinedValue>
                                        </DefinedValues>
                                        <RelOp AvgRowSize="4031" EstimateCPU="0.0007851" EstimateIO="0.0171991" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="21" LogicalOp="Clustered Index Scan" NodeId="7" Parallel="false" PhysicalOp="Clustered Index Scan" EstimatedTotalSubtreeCost="0.0179842" TableCardinality="571">
                                          <OutputList>
                                            <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catID" />
                                            <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="parentID" />
                                            <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catName" />
                                          </OutputList>
                                          <IndexScan Ordered="false" ForcedIndex="false" NoExpandHint="false">
                                            <DefinedValues>
                                              <DefinedValue>
                                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catID" />
                                              </DefinedValue>
                                              <DefinedValue>
                                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="parentID" />
                                              </DefinedValue>
                                              <DefinedValue>
                                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catName" />
                                              </DefinedValue>
                                            </DefinedValues>
                                            <Object Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Index="[PK_TblPartCategories]" TableReferenceId="1" IndexKind="Clustered" />
                                            <Predicate>
                                              <ScalarOperator ScalarString="[Staging.Turbo-Kits.com].[dbo].[TblPartCategories].[parentID]=(0)">
                                                <Compare CompareOp="EQ">
                                                  <ScalarOperator>
                                                    <Identifier>
                                                      <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="parentID" />
                                                    </Identifier>
                                                  </ScalarOperator>
                                                  <ScalarOperator>
                                                    <Const ConstValue="(0)" />
                                                  </ScalarOperator>
                                                </Compare>
                                              </ScalarOperator>
                                            </Predicate>
                                          </IndexScan>
                                        </RelOp>
                                      </ComputeScalar>
                                    </RelOp>
                                  </ComputeScalar>
                                </RelOp>
                              </ComputeScalar>
                            </RelOp>
                            <RelOp AvgRowSize="4027" EstimateCPU="2.01913E-06" EstimateIO="0" EstimateRebinds="24.0372" EstimateRewinds="0" EstimateRows="1.14463" LogicalOp="Assert" NodeId="17" Parallel="false" PhysicalOp="Assert" EstimatedTotalSubtreeCost="0.04086">
                              <OutputList>
                                <ColumnReference Column="Expr1023" />
                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catID" />
                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catName" />
                                <ColumnReference Column="Expr1013" />
                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="parentID" />
                                <ColumnReference Column="Expr1014" />
                              </OutputList>
                              <Assert StartupExpression="false">
                                <RelOp AvgRowSize="4027" EstimateCPU="2.01913E-06" EstimateIO="0" EstimateRebinds="24.0372" EstimateRewinds="0" EstimateRows="1.14463" LogicalOp="Inner Join" NodeId="18" Parallel="false" PhysicalOp="Nested Loops" EstimatedTotalSubtreeCost="0.04086">
                                  <OutputList>
                                    <ColumnReference Column="Expr1023" />
                                    <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catID" />
                                    <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catName" />
                                    <ColumnReference Column="Expr1013" />
                                    <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="parentID" />
                                    <ColumnReference Column="Expr1014" />
                                  </OutputList>
                                  <NestedLoops Optimized="false">
                                    <OuterReferences>
                                      <ColumnReference Column="Expr1023" />
                                      <ColumnReference Column="Recr1008" />
                                      <ColumnReference Column="Recr1009" />
                                      <ColumnReference Column="Recr1010" />
                                      <ColumnReference Column="Recr1011" />
                                      <ColumnReference Column="Recr1012" />
                                    </OuterReferences>
                                    <RelOp AvgRowSize="4027" EstimateCPU="2.40372E-07" EstimateIO="0" EstimateRebinds="24.0372" EstimateRewinds="0" EstimateRows="1" LogicalOp="Compute Scalar" NodeId="19" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="2.40372E-07">
                                      <OutputList>
                                        <ColumnReference Column="Expr1023" />
                                        <ColumnReference Column="Recr1008" />
                                        <ColumnReference Column="Recr1009" />
                                        <ColumnReference Column="Recr1010" />
                                        <ColumnReference Column="Recr1011" />
                                        <ColumnReference Column="Recr1012" />
                                      </OutputList>
                                      <ComputeScalar>
                                        <DefinedValues>
                                          <DefinedValue>
                                            <ColumnReference Column="Expr1023" />
                                            <ScalarOperator ScalarString="[Expr1022]+(1)">
                                              <Arithmetic Operation="ADD">
                                                <ScalarOperator>
                                                  <Identifier>
                                                    <ColumnReference Column="Expr1022" />
                                                  </Identifier>
                                                </ScalarOperator>
                                                <ScalarOperator>
                                                  <Const ConstValue="(1)" />
                                                </ScalarOperator>
                                              </Arithmetic>
                                            </ScalarOperator>
                                          </DefinedValue>
                                        </DefinedValues>
                                        <RelOp AvgRowSize="4027" EstimateCPU="2.40372E-07" EstimateIO="0" EstimateRebinds="24.0372" EstimateRewinds="0" EstimateRows="1" LogicalOp="Lazy Spool" NodeId="20" Parallel="false" PhysicalOp="Table Spool" EstimatedTotalSubtreeCost="2.40372E-07">
                                          <OutputList>
                                            <ColumnReference Column="Expr1022" />
                                            <ColumnReference Column="Recr1008" />
                                            <ColumnReference Column="Recr1009" />
                                            <ColumnReference Column="Recr1010" />
                                            <ColumnReference Column="Recr1011" />
                                            <ColumnReference Column="Recr1012" />
                                          </OutputList>
                                          <Spool Stack="true" PrimaryNodeId="2" />
                                        </RelOp>
                                      </ComputeScalar>
                                    </RelOp>
                                    <RelOp AvgRowSize="8049" EstimateCPU="3.03723E-07" EstimateIO="0" EstimateRebinds="23.0372" EstimateRewinds="0" EstimateRows="3.03723" LogicalOp="Compute Scalar" NodeId="24" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.0408577">
                                      <OutputList>
                                        <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catID" />
                                        <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="parentID" />
                                        <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catName" />
                                        <ColumnReference Column="Expr1013" />
                                        <ColumnReference Column="Expr1014" />
                                      </OutputList>
                                      <ComputeScalar>
                                        <DefinedValues>
                                          <DefinedValue>
                                            <ColumnReference Column="Expr1013" />
                                            <ScalarOperator ScalarString="[Recr1010]+(1)">
                                              <Arithmetic Operation="ADD">
                                                <ScalarOperator>
                                                  <Identifier>
                                                    <ColumnReference Column="Recr1010" />
                                                  </Identifier>
                                                </ScalarOperator>
                                                <ScalarOperator>
                                                  <Const ConstValue="(1)" />
                                                </ScalarOperator>
                                              </Arithmetic>
                                            </ScalarOperator>
                                          </DefinedValue>
                                          <DefinedValue>
                                            <ColumnReference Column="Expr1014" />
                                            <ScalarOperator ScalarString="([Recr1012]+N',')+[Staging.Turbo-Kits.com].[dbo].[TblPartCategories].[catName]">
                                              <Arithmetic Operation="ADD">
                                                <ScalarOperator>
                                                  <Arithmetic Operation="ADD">
                                                    <ScalarOperator>
                                                      <Identifier>
                                                        <ColumnReference Column="Recr1012" />
                                                      </Identifier>
                                                    </ScalarOperator>
                                                    <ScalarOperator>
                                                      <Const ConstValue="N','" />
                                                    </ScalarOperator>
                                                  </Arithmetic>
                                                </ScalarOperator>
                                                <ScalarOperator>
                                                  <Identifier>
                                                    <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catName" />
                                                  </Identifier>
                                                </ScalarOperator>
                                              </Arithmetic>
                                            </ScalarOperator>
                                          </DefinedValue>
                                        </DefinedValues>
                                        <RelOp AvgRowSize="4031" EstimateCPU="0.0007066" EstimateIO="0.0172776" EstimateRebinds="0" EstimateRewinds="23.0372" EstimateRows="3.03723" LogicalOp="Clustered Index Scan" NodeId="25" Parallel="false" PhysicalOp="Clustered Index Scan" EstimatedTotalSubtreeCost="0.0342623" TableCardinality="571">
                                          <OutputList>
                                            <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catID" />
                                            <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="parentID" />
                                            <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catName" />
                                          </OutputList>
                                          <IndexScan Ordered="false" ForcedIndex="false" NoExpandHint="false">
                                            <DefinedValues>
                                              <DefinedValue>
                                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catID" />
                                              </DefinedValue>
                                              <DefinedValue>
                                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="parentID" />
                                              </DefinedValue>
                                              <DefinedValue>
                                                <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="catName" />
                                              </DefinedValue>
                                            </DefinedValues>
                                            <Object Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Index="[PK_TblPartCategories]" TableReferenceId="2" IndexKind="Clustered" />
                                            <Predicate>
                                              <ScalarOperator ScalarString="[Staging.Turbo-Kits.com].[dbo].[TblPartCategories].[parentID]=[Recr1008]">
                                                <Compare CompareOp="EQ">
                                                  <ScalarOperator>
                                                    <Identifier>
                                                      <ColumnReference Database="[Staging.Turbo-Kits.com]" Schema="[dbo]" Table="[TblPartCategories]" Column="parentID" />
                                                    </Identifier>
                                                  </ScalarOperator>
                                                  <ScalarOperator>
                                                    <Identifier>
                                                      <ColumnReference Column="Recr1008" />
                                                    </Identifier>
                                                  </ScalarOperator>
                                                </Compare>
                                              </ScalarOperator>
                                            </Predicate>
                                          </IndexScan>
                                        </RelOp>
                                      </ComputeScalar>
                                    </RelOp>
                                  </NestedLoops>
                                </RelOp>
                                <Predicate>
                                  <ScalarOperator ScalarString="CASE WHEN [Expr1023]&gt;(100) THEN (0) ELSE NULL END">
                                    <IF>
                                      <Condition>
                                        <ScalarOperator>
                                          <Compare CompareOp="GT">
                                            <ScalarOperator>
                                              <Identifier>
                                                <ColumnReference Column="Expr1023" />
                                              </Identifier>
                                            </ScalarOperator>
                                            <ScalarOperator>
                                              <Const ConstValue="(100)" />
                                            </ScalarOperator>
                                          </Compare>
                                        </ScalarOperator>
                                      </Condition>
                                      <Then>
                                        <ScalarOperator>
                                          <Const ConstValue="(0)" />
                                        </ScalarOperator>
                                      </Then>
                                      <Else>
                                        <ScalarOperator>
                                          <Const ConstValue="NULL" />
                                        </ScalarOperator>
                                      </Else>
                                    </IF>
                                  </ScalarOperator>
                                </Predicate>
                              </Assert>
                            </RelOp>
                          </Concat>
                        </RelOp>
                      </Spool>
                    </RelOp>
                    <Predicate>
                      <ScalarOperator ScalarString="[@CatID] IS NULL OR [Recr1015]=[@CatID]">
                        <Logical Operation="OR">
                          <ScalarOperator>
                            <Identifier>
                              <ColumnReference Column="ConstExpr1020">
                                <ScalarOperator>
                                  <Compare CompareOp="IS">
                                    <ScalarOperator>
                                      <Identifier>
                                        <ColumnReference Column="@CatID" />
                                      </Identifier>
                                    </ScalarOperator>
                                    <ScalarOperator>
                                      <Const ConstValue="NULL" />
                                    </ScalarOperator>
                                  </Compare>
                                </ScalarOperator>
                              </ColumnReference>
                            </Identifier>
                          </ScalarOperator>
                          <ScalarOperator>
                            <Compare CompareOp="EQ">
                              <ScalarOperator>
                                <Identifier>
                                  <ColumnReference Column="Recr1015" />
                                </Identifier>
                              </ScalarOperator>
                              <ScalarOperator>
                                <Identifier>
                                  <ColumnReference Column="@CatID" />
                                </Identifier>
                              </ScalarOperator>
                            </Compare>
                          </ScalarOperator>
                        </Logical>
                      </ScalarOperator>
                    </Predicate>
                  </Filter>
                </RelOp>
              </Sort>
            </RelOp>
          </QueryPlan>
        </StmtSimple>
      </Statements>
    </Batch>
  </BatchSequence>
</ShowPlanXML>

Open in new window

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 25

Author Comment

by:kevp75
ID: 35000793
@LCSandman8  yes, but it only includes catName

table structure

CREATE VIEW [dbo].[vwSelectPartCategory]  WITH SCHEMABINDING

AS
Select catID, parentID, catName, catDescription, catAdded, catMetaKeywords, catMetaTitle, catMetaDesc, catShowInNav
From dbo.TblPartCategories;

GO

Open in new window

0
 
LVL 15

Accepted Solution

by:
derekkromm earned 400 total points
ID: 35000813
Try adding this index:

create nonclustered index ix_TblPartCategories_Path on dbo.TblPartCategories (
catID)
include (
parentID, catName)
0
 
LVL 25

Author Comment

by:kevp75
ID: 35000819
believe me, i wouldn't do it like this unless I had to, but boss man said "this is what I want"
0
 
LVL 15

Expert Comment

by:derekkromm
ID: 35000825
we've all been there :)
0
 
LVL 25

Author Comment

by:kevp75
ID: 35000982
LOL...  ok.  Index created...let's see how that goes
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

920 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

16 Experts available now in Live!

Get 1:1 Help Now