TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ahmed elbarbary
637
1.6k
281.9k
why this query is very slow when add these 4 lines ?
Mar 18 2020 8:52 PM
the query is very slow i test it take too much time i realized that problem on these lines
COUNT
(
CASE
WHEN
ISNULL
(FI.FamilyLevel,0)= 0
AND
PF.IntroductionDate
IS
NULL
THEN
p.PartID
END
) Count_No_InTroudctionNULLForeCast ,
COUNT
(
CASE
WHEN
ISNULL
(FI.FamilyLevel,0)= 0
AND
PF.IntroductionDate
IS
not
NULL
THEN
p.PartID
END
) Count_No_InTroudctionNotNULLForeCast ,
COUNT
(
CASE
WHEN
ISNULL
(FI.FamilyLevel,0)= 0
AND
PF.IntroductionDate
IS
not
NULL
AND
isnull
(PF.Comment,
''
)
LIKE
'%appro%'
THEN
PF.PartID
END
) Count_No_InTroudctionNotNULLAPPForeCast ,
COUNT
(
CASE
WHEN
ISNULL
(FI.FamilyLevel,0)= 0
AND
PF.IntroductionDate
IS
not
NULL
AND
isnull
(PF.Comment,
''
)
NOT
LIKE
'%appro%'
THEN
PF.PartID
END
) Count_No_InTroudctionNotNULLNoAPPForeCast
because all query take one 50 minutes
when i remove lines above query take 7 minutes
so how to solve this issue as block blow
SELECT
F.CompanyID ,
COUNT
(
CASE
WHEN
FI.FamilyLevel= 1
THEN
p.PartID
END
) Count_Yes_InForeCast ,
COUNT
(
CASE
WHEN
ISNULL
(FI.FamilyLevel,0)= 0
THEN
p.PartID
END
) Count_No_InForeCast ,
--------------- block have problem
COUNT
(
CASE
WHEN
ISNULL
(FI.FamilyLevel,0)= 0
AND
PF.IntroductionDate
IS
NULL
THEN
p.PartID
END
) Count_No_InTroudctionNULLForeCast ,
COUNT
(
CASE
WHEN
ISNULL
(FI.FamilyLevel,0)= 0
AND
PF.IntroductionDate
IS
not
NULL
THEN
p.PartID
END
) Count_No_InTroudctionNotNULLForeCast ,
COUNT
(
CASE
WHEN
ISNULL
(FI.FamilyLevel,0)= 0
AND
PF.IntroductionDate
IS
not
NULL
AND
isnull
(PF.Comment,
''
)
LIKE
'%appro%'
THEN
PF.PartID
END
) Count_No_InTroudctionNotNULLAPPForeCast ,
COUNT
(
CASE
WHEN
ISNULL
(FI.FamilyLevel,0)= 0
AND
PF.IntroductionDate
IS
not
NULL
AND
isnull
(PF.Comment,
''
)
NOT
LIKE
'%appro%'
THEN
PF.PartID
END
) Count_No_InTroudctionNotNULLNoAPPForeCast ,
--------------- end
COUNT
(
DISTINCT
CASE
WHEN
FI.FamilyLevel= 1
THEN
FI.FamilyID
END
) CountFamily_Yes_InForeCast ,
COUNT
(
DISTINCT
CASE
WHEN
ISNULL
(FI.FamilyLevel,0)= 0
THEN
FI.FamilyID
END
) CountFamily_No_InForeCast
into
#ForecastTotal
FROM
Parts.FamilyIntroductionDate FI
WITH
(NoLock)
INNER
JOIN
parts.Nop_PartsFamily F
ON
F.PartFamilyID =fi.FamilyID
INNER
JOIN
parts.Nop_Part P
WITH
(NoLock)
ON
p.PartsFamilyID=f.PartFamilyID
LEFT
OUTER
JOIN
parts.PartsForecast PF
WITH
(NoLock)
ON
pf.PartID=p.PartID
GROUP
BY
F.CompanyID
execution plan as below
https://www.brentozar.com/pastetheplan/?id=Hyss6rlLL
Reply
Answers (
4
)
Having problem connecting to database
xml to SQL table