次のクエリを使用して、Java Swing アプリケーションの 1 つでレコードを表示しています。このクエリの実行は非常に遅いです。パフォーマンスを向上させて結果を得る方法はありますか
より短い時間間隔でタスクを達成する方法はありますか?
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