Emilia
Mazurkiewicz
Specjalista ds.
Wsparcia i
Utrzymania Systemów
Informatyc...
Temat: pomoc w optymalizacji zapytania MSSQL
Jak zapisać poniższe zapytanie w uproszczonej wersji, żeby działało optymalnie.SELECT o.id_testu, o.pub_int_od, p.tk AS stanowisko, p3.tu AS jednostka, ox.id_testu AS lk, ox1.id_testu AS wn, ox2.id_testu AS nd, o.jozus_wprow AS jozus_utw,
o.priorytet
FROM dbo.TEST AS o LEFT OUTER JOIN
dbo.POLA AS px ON px.id = o.id_testu AND px.id_definicji_pola = 143 LEFT OUTER JOIN
dbo.TEST AS ox ON ox.id_testu = px.id_testu AND ox.data_pub IS NOT NULL AND ox.pub_int_od < GETDATE() LEFT OUTER JOIN
dbo.POLA AS px1 ON px1.id = o.id_testu AND px1.id_definicji_pola = 138 LEFT OUTER JOIN
dbo.TEST AS ox1 ON ox1.id_testu = px1.id_testu AND ox1.data_pub IS NOT NULL AND ox1.pub_int_od < GETDATE() LEFT OUTER JOIN
dbo.POLA AS px2 ON px2.id = o.id_testu AND px2.id_definicji_pola = 147 LEFT OUTER JOIN
dbo.TEST AS ox2 ON ox2.id_testu = px2.id_testu AND ox2.data_pub IS NOT NULL AND ox2.pub_int_od < GETDATE() INNER JOIN
dbo.POLA AS p ON p.id_testu = o.id_testu AND p.id_definicji_pola = 129 INNER JOIN
dbo.POLA AS p3 ON p3.id_testu = o.id_testu AND p3.id_definicji_pola = 127
WHERE (ox1.pub_int_do > GETDATE()) AND (o.id_typu_testu = 8) AND (o.czy_gotowe = 1) AND (o.data_apr IS NOT NULL) AND (o.data_superapr IS NOT NULL) AND
(o.data_pub IS NOT NULL) AND (o.pub_int_od < GETDATE()) OR
(o.id_typu_testu = 8) AND (o.czy_gotowe = 1) AND (o.data_apr IS NOT NULL) AND (o.data_superapr IS NOT NULL) AND (o.data_pub IS NOT NULL) AND
(o.pub_int_od < GETDATE()) AND (ox1.data_pub IS NULL) OR
(ox1.pub_int_do < GETDATE()) AND (o.id_typu_testu = 8) AND (o.czy_gotowe = 1) AND (o.data_apr IS NOT NULL) AND (o.data_superapr IS NOT NULL) AND
(o.data_pub IS NOT NULL) AND (o.pub_int_od < GETDATE()) AND (ox2.pub_int_do > GETDATE()) AND (ox2.data_pub IS NOT NULL)