Forum
Merhaba aşağıda vereceğim sorgu 100+ cihaz tarafından çağrılıyor. bu sorgular çalıştığında cpu kullanımı %100 oluyor. bu sorguyu nasıl optimize edebilirim? yardım edebilir misiniz?
WITH KartlarCTE
AS (
/*** Öğrenciler /
SELECT Student.CardId AS KartNo ,
Student.HasDisability AS Engelli ,
0 AS Hgs ,
0 AS Yemekhane
FROM Student
WHERE Student.IsInactive = 0 AND Student.CardId IS NOT NULL -- indexlendi
/ İdariler /
UNION
SELECT Users.Card_ID AS KartNo ,
0 AS Engelli ,
0 AS Hgs ,
0 AS Yemekhane
FROM Users
WHERE Users.activity = 'Aktif' AND Users.Card_ID IS NOT NULL -- indexlendi
/ HGSler /
UNION
SELECT HgsEtiket.EtiketDegeri AS KartNo ,
0 AS Engelli ,
1 AS Hgs ,
0 AS Yemekhane
FROM HgsEtiket
WHERE HgsEtiket.Aktif = '1' AND HgsEtiket.EtiketDegeri IS NOT NULL -- indexlendi
/ Yemek Hakkı Olanlar ***/
UNION
SELECT CardID + '00'
+ CONVERT(VARCHAR(2), CAST(dbo.BinaryToDecimal(CAST([1] AS VARCHAR)
+ CAST([2] AS VARCHAR)
+ CAST([3] AS VARCHAR)
+ CAST([4] AS VARCHAR)
+ CAST([5] AS VARCHAR)
+ CAST([6] AS VARCHAR)
+ '00') AS BINARY(1)), 2)
+ '0000' AS KartNo ,
0 AS Engelli ,
0 AS Hgs ,
1 AS Yemekhane
FROM ( SELECT UserMenuOrder.CardID ,
dbo.UserMenuOrder.id ,
DATEPART(dw,
UserMenuOrder.[Date]) AS GUNNO
FROM dbo.UserMenuOrder
WHERE [Date] BETWEEN '2015-11-20' AND '2015-11-27'
) p PIVOT
( COUNT(id) FOR GUNNO IN ( [1], [2], [3], [4], [5], [6] ) ) AS pvt
)
SELECT --TOP 100
KartlarCTE.KartNo ,
Readers.IP_Address ,
Readers_Groups.Port
FROM KartlarCTE ,
Readers
JOIN Readers_Groups ON Readers_Groups.group_id = Readers.GroupId
WHERE ( Readers.Active = 1
AND Readers.Hgs = KartlarCTE.Hgs
AND Readers.EngelliGecisi = KartlarCTE.Engelli
AND Readers.Yemekhane = KartlarCTE.Yemekhane
AND Readers.IP_Address = '192.168.208.92'
AND Readers_Groups.Port = '7203'
)
AND KartlarCTE.KartNo NOT IN (
SELECT OkuyucuOfflineHafizasi.Card_ID
FROM OkuyucuOfflineHafizasi
WHERE OkuyucuOfflineHafizasi.Aktarildi = 0
AND OkuyucuOfflineHafizasi.IP_Address = Readers.IP_Address )
Merhaba,
Persformans açısından kullandığınız tablolarda ki indexleri de kontrol etmenizi öneririm.
İyi Çalışmalar.