Thursday 15 July 2010

stored procedures - Strange execution time for summary query -


I'm performing a part of the query I'm performing here:

  SELECT SUM (ParentTable .field 1), (Select children. Field 1) Children join cerebral inner table on Grand Childton children table.id = Grand ChildTable. KidsTableIndInner join each other on the Grand ChildTable Table.There is another TibialID = other tab.ede where for children. Parents Balik ID = PainterTable.Id and other TABLE.Tip = 1), ---- Where are some of the parents called   

Relationships:

  Parenting - & gt; ChildrenTable = 1-to-many childrenTable - & gt; Grand ChildTable = 1-to-many Grand ChildTable - & gt; Other Tall = 1-to-1   

I am executing this query three times, only changing the type of condition, and here are the results:

Recorded Number Status Total Execution Time (MS) Type = 1: 973 Type = 2: 78810 Type = 3: 648318

If I only execute Internal login query, the records recorded here are:

  SELECT p.Type, Join INNER from CycleActivities from COUNT (*), Add cap on CycleActivityProducts ca.Id = CAP.CycleActivityId Add add p. Cap.ProductId = PIID Group by P Type Type ---- ----------- 1 55152 2 13401 4 102730   

So, why do Query with type = 1 condition is executed very quickly with query type = 2, although this is a 4x big resultset query (type is tint)?

The way your query is written, for SQL Server, for each line of output, Instructions have been given to execute sub-queries with JOIN .

If I understand what you want correctly (updates):

 with  as the cte_parent (choose ID, SUM (ParentTable.Field1), Parent_Sum by ID by ParentTable Group), Join asylum INNER as child (Sext Id, SUM (ChildrenTable.Field1) from ChildRum, GrandChildren posted on children. Tables.Id = GrandChildrenTable.ChildrenTableId INNER in another Join GrandChildrenTable.AnotherTableId = AnotherTable.Id where another Table.Type = 1 and ID by some_conditions group) Select Cte_parent.id, parent_um, parent_ct to Child Cyr Join child_cte at parent_cte.id/baby_cte.id    

No comments:

Post a Comment