A
Adam Goetz
Ok, got a SQL timeout occuring in the field that we cannot reproduce in the
development environment. Development system run time for this query is
sub-second. App is .NET 2, C#, using the
SqlConnection/SqlCommand/SqlDataReader classes. As stated below, the query
runs fine inside Query Analyzer at the client site.
select top 50 sum(orderedquantity) as qty, Pickingdetail.itemnumber,
description, count(distinct Pickingorder.ordernumber) as orders from
Pickingorder
inner join Pickingdetail on PickingOrder.Site = PickingDetail.Site AND
Pickingorder.ordernumber=Pickingdetail.ordernumber
inner join item on Pickingdetail.itemnumber=Item.itemnumber where (wave is
null or wave = '') and status=0
and PickingOrder.SITE = 'WH' and SUBSTRING(PickingOrder.OrderNumber, 1, 1) =
'a' and Pickingorder.ordernumber
in (select Pickingorder.ordernumber from Pickingorder inner join
Pickingdetail on
Pickingorder.ordernumber=Pickingdetail.ordernumber where (wave is null or
wave = '') and status=0
and PickingOrder.SITE = 'WH' and SUBSTRING(PickingOrder.OrderNumber, 1, 1) =
'a' group by Pickingorder.ordernumber having count(*)=1)
group by Pickingdetail.itemnumber, description order by count(distinct
Pickingorder.ordernumber) desc
As background,
there are approximately 100,000 rows in the Pickingorder table, 150,000 rows
in the Pickingdetail table and 25,000 rows in the Item table
the application is not run from the same machine as the DB server
When the query is run using SQL query analyzer it completes in less than 2
seconds in the field (so same query, but not inside the app where it
timesout).
The filters, status=0 and (wave is null or wave = '') both reduce the number
of rows returned by over 99%
The same query but without the sub-select - "and Pickingorder.ordernumber in
(select Pickingorder.ordernumber from Pickingorder inner join Pickingdetail
on
Pickingorder.ordernumber=Pickingdetail.ordernumber where (wave is null or
wave = '') and status=0 and PickingOrder.SITE = 'WH' and
SUBSTRING(PickingOrder.OrderNumber, 1, 1) = 'a' group by
Pickingorder.ordernumber having count(*)=1)" - runs in less than a second
in the same Windows app
development environment. Development system run time for this query is
sub-second. App is .NET 2, C#, using the
SqlConnection/SqlCommand/SqlDataReader classes. As stated below, the query
runs fine inside Query Analyzer at the client site.
select top 50 sum(orderedquantity) as qty, Pickingdetail.itemnumber,
description, count(distinct Pickingorder.ordernumber) as orders from
Pickingorder
inner join Pickingdetail on PickingOrder.Site = PickingDetail.Site AND
Pickingorder.ordernumber=Pickingdetail.ordernumber
inner join item on Pickingdetail.itemnumber=Item.itemnumber where (wave is
null or wave = '') and status=0
and PickingOrder.SITE = 'WH' and SUBSTRING(PickingOrder.OrderNumber, 1, 1) =
'a' and Pickingorder.ordernumber
in (select Pickingorder.ordernumber from Pickingorder inner join
Pickingdetail on
Pickingorder.ordernumber=Pickingdetail.ordernumber where (wave is null or
wave = '') and status=0
and PickingOrder.SITE = 'WH' and SUBSTRING(PickingOrder.OrderNumber, 1, 1) =
'a' group by Pickingorder.ordernumber having count(*)=1)
group by Pickingdetail.itemnumber, description order by count(distinct
Pickingorder.ordernumber) desc
As background,
there are approximately 100,000 rows in the Pickingorder table, 150,000 rows
in the Pickingdetail table and 25,000 rows in the Item table
the application is not run from the same machine as the DB server
When the query is run using SQL query analyzer it completes in less than 2
seconds in the field (so same query, but not inside the app where it
timesout).
The filters, status=0 and (wave is null or wave = '') both reduce the number
of rows returned by over 99%
The same query but without the sub-select - "and Pickingorder.ordernumber in
(select Pickingorder.ordernumber from Pickingorder inner join Pickingdetail
on
Pickingorder.ordernumber=Pickingdetail.ordernumber where (wave is null or
wave = '') and status=0 and PickingOrder.SITE = 'WH' and
SUBSTRING(PickingOrder.OrderNumber, 1, 1) = 'a' group by
Pickingorder.ordernumber having count(*)=1)" - runs in less than a second
in the same Windows app