sql server - Why is this SQL statement hanging when group by, sum, or where clause is included? -
i have sql statement:
select t3.item1, t3.item2, sum(t1.moneys) table t1 inner join table t2 on t1.key = t2.key inner join table t3 on t1.key2 = t3.key2 t2.type = 'thistype' , t3.type2 = 'thistype' group t3.item1, t3.item2
if remove group by
, sum
, or where
clause runs fine - if add of hangs forever... ideas... on sql server management studio 2008 r2
thanks
further testing
so created view:
select t3.item1, t3.item2, t1.moneys, t2.type, t3.type2 table t1 inner join table t2 on t1.key = t2.key inner join table t3 on t1.key2 = t3.key2
and can select top 1000 view fine , see type want @ in data, when add 'where type2 = 'thistype'' hangs again...
your joining 3 tables millions of records, normal take bit run.
to answer question statistics, indices utilize retrieve records faster tables. without accurate or date statistics, indices can slow queries down.
http://blogs.technet.com/b/rob/archive/2008/05/16/sql-server-statistics.aspx
Comments
Post a Comment