-1

我正在使用以下查询在我的一个 java swing 应用程序中显示记录。此查询执行速度非常慢。有什么方法可以通过提高性能来获得结果

有什么办法可以在更小的时间间隔内完成任务。

select d.orderid,d.ordername,d.design,isnull(e.OrderQty,0) OrderQty
from 
(
select a.orderid,ordername,design
from filerorn a,ordersNew.dbo.orders b where a.orderid=b.orderid and sub_stage = 'G'
And a.id =@Id
)d
LEFT JOIN
(
select a.OrderId,a.Design,( case when b.ItemId is null 
then a.Qty else 1 end) -isnull(c.Qty,0) OrderQty from 
OrdersNew..ordersDesign a
left join
OrdersNew..OrdersBGTPDesign b
on a.OrderId=b.OrderId and  a.Design
COLLATE DATABASE_DEFAULT
=b.Design COLLATE DATABASE_DEFAULT and a.Sno=b.SNo
left join 
( select a.OrderId,Design,Qty from ExcludeDesign a
left join
dbo.ExcludeDesign_d b
on a.ID=b.ID

)c
on a.OrderId=c.OrderId and a.Design
COLLATE DATABASE_DEFAULT
=c.Design COLLATE DATABASE_DEFAULT and a.Sno=c.Sno

)e
ON d.OrderId=e.OrderId and d.Design COLLATE DATABASE_DEFAULT
=e.Design  COLLATE DATABASE_DEFAULT
and d.sno=e.Sno
and d.ItemId=e.ItemId 
order by d.ordername,d.design,d.sno,d.Itemid 
select d.orderid,d.ordername,d.design,isnull(e.OrderQty,0) OrderQty
from 
(
select a.orderid,ordername,design
from filerorn a,ordersNew.dbo.orders b where a.orderid=b.orderid and sub_stage = 'G'
And a.id =@Id
)d
LEFT JOIN
(
select a.OrderId,a.Design,( case when b.ItemId is null 
then a.Qty else 1 end) -isnull(c.Qty,0) OrderQty from 
OrdersNew..ordersDesign a
left join
OrdersNew..OrdersBGTPDesign b
on a.OrderId=b.OrderId and  a.Design
COLLATE DATABASE_DEFAULT
=b.Design COLLATE DATABASE_DEFAULT and a.Sno=b.SNo
left join 
( select a.OrderId,Design,Qty from ExcludeDesign a
left join
dbo.ExcludeDesign_d b
on a.ID=b.ID

)c
on a.OrderId=c.OrderId and a.Design
COLLATE DATABASE_DEFAULT
=c.Design COLLATE DATABASE_DEFAULT and a.Sno=c.Sno

)e
ON d.OrderId=e.OrderId and d.Design COLLATE DATABASE_DEFAULT
=e.Design  COLLATE DATABASE_DEFAULT
and d.sno=e.Sno
and d.ItemId=e.ItemId 
order by d.ordername,d.design,d.sno,d.Itemid 

orderdesign 和 orders 有数百万条记录

Edit

15 %

select a.orderid,ordername,design
from filerorn a,ordersNew.dbo.orders b where a.orderid=b.orderid and sub_stage = 'G'
And a.id =@Id

46%

select a.OrderId,a.Design,( case when b.ItemId is null 
then a.Qty else 1 end) -isnull(c.Qty,0) OrderQty from 
OrdersNew..ordersDesign a
left join
OrdersNew..OrdersBGTPDesign b
on a.OrderId=b.OrderId and  a.Design
4

1 回答 1

1

如何创建一个视图并弹出一些索引以使其更快地进行搜索。或者,如果您不喜欢查看视图,请在您的表上创建索引以加快搜索速度。

于 2012-11-28T09:15:25.383 回答