Full Outer Joins Slowing Down QueryIs there a way to prevent Scalar UDFs in computed columns from inhibiting...

Are ETF trackers fundamentally better than individual stocks?

Who is flying the vertibirds?

Time travel from stationary position?

Can I use USB data pins as power source

Define, (actually define) the "stability" and "energy" of a compound

How to explain that I do not want to visit a country due to personal safety concern?

How to deal with taxi scam when on vacation?

Why doesn't the EU now just force the UK to choose between referendum and no-deal?

how to write formula in word in latex

Provisioning profile doesn't include the application-identifier and keychain-access-groups entitlements

Why do Australian milk farmers need to protest supermarkets' milk price?

Is it normal that my co-workers at a fitness company criticize my food choices?

Error in Twin Prime Conjecture

PTIJ: Who should I vote for? (21st Knesset Edition)

If the DM rolls initiative once for a group of monsters, how do end-of-turn effects work?

Did Ender ever learn that he killed Stilson and/or Bonzo?

How do I hide Chekhov's Gun?

Min function accepting varying number of arguments in C++17

Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?

Are there verbs that are neither telic, or atelic?

Why would a flight no longer considered airworthy be redirected like this?

Credit cards used everywhere in Singapore or Malaysia?

Is it possible to upcast ritual spells?

What do Xenomorphs eat in the Alien series?



Full Outer Joins Slowing Down Query


Is there a way to prevent Scalar UDFs in computed columns from inhibiting parallelism?Why is this Full Outer Join not working?Index not making execution faster, and in some cases is slowing down the query. Why is it so?Full outer joins, coalescing, indexes and viewsWhy is FORCE JOIN option slowing down query and forcing execution plan to sort prior to joining tables?Adding columns from joined table slows down query incrediblyIdeas how to make this query faster?Row estimates always too lowOrganizing SQL joins for readabilitywhy is this left join faster than an inner join?SQL Outer Join while conditioning on an extra column













1















I am relatively new to SQL, so I apologize if I ask some basic questions.



Our database is setup on Azure, we have automatic indexes turned on. The query I have takes about 6 seconds and gets 2217 rows. As far as I have been able to figure out is that it is my Full Outer Joins that are slowing down my query. I am fine if I can just get it down to 2~3 seconds.



Here is my query:



SELECT j.JobId, j.OrderId, j.OrderType, j.ShopName, j.ShipDate, j.CompletionDate, j.InstallDate, j.DayPriority,
j.ShipDateConfirmed, j.IsAddon, j.CashOnDelivery, ds.ShopLabel, ds.DesignSetId, dsp.DesignSetProcessId, dsp.DueDate AS DesignSetProcessDueDate,
dsp.DatetimeStarted, dsp.DatetimeComplete, dsp.BatchNumber, p.Name AS ProcessName, p.ProcessId, p.ZoneId, X.CabinetCount
FROM Jobs j
JOIN DesignSets ds ON j.JobId = ds.JobId
FULL OUTER JOIN Schedule.DesignSetProcessesWithDueDates dsp ON ds.DesignSetId = dsp.DesignSetId
FULL OUTER JOIN Schedule.Processes p ON dsp.ProcessId = p.ProcessId
OUTER APPLY(Select SUM(pr.Quantity * pr.DeliveryCnt) AS CabinetCount FROM Products pr WHERE ds.DesignSetId = pr.DesignSetId AND
(dsp.BatchNumber = pr.BatchNumber OR dsp.DesignSetId IS NULL)) AS X
WHERE j.Status >= 60 AND j.Status <= 70
ORDER BY j.CompletionDate, j.DayPriority DESC, j.ShopName, j.OrderId, ds.ShopLabel, p.SortOrder, dsp.BatchNumber


This query gets a master view of the jobs and the processes within the job. All the information that I am getting is needed and all the rows are to.



Is there anything that I can use as a substitute for the Full Outer Joins?



If I can just get one of them to go faster I think the query would work better.



If you have any suggestion to how I can speed up the rest of my query I am willing to give it a shot.



EDIT



Here is the link to paste the plan: https://www.brentozar.com/pastetheplan/?id=SytXw1dum



UPDATE



Turns out one of the columns from a view was slowing everything down, so I got rid of dsp.DueDate AS DesignSetProcessDueDate and now it runs in less than a second. I was able to find out how that view was getting the information and put it right into my query.










share|improve this question
















bumped to the homepage by Community 9 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • I put my execution plan in there. If you need any more information just let me know. Thank you for responding.

    – DalTron
    Sep 12 '18 at 21:16






  • 1





    The graphical plan is not enough. use brentozar.com/pastetheplan/instructions

    – SQLRaptor
    Sep 12 '18 at 22:16











  • Thank you for the clarification, I have posted the link through pastetheplan.com and I have added a link to go view that.

    – DalTron
    Sep 13 '18 at 13:35











  • Are plans improved if you replace the two FULL joins with LEFT ones?

    – ypercubeᵀᴹ
    Sep 13 '18 at 13:48













  • No, they aren't. If I just do a join the speed is improved, but I also loose some rows. Though I didn't lose any rows when I did a LEFT join, so I guess it's not the Full Outer Join that is the problem

    – DalTron
    Sep 13 '18 at 14:09
















1















I am relatively new to SQL, so I apologize if I ask some basic questions.



Our database is setup on Azure, we have automatic indexes turned on. The query I have takes about 6 seconds and gets 2217 rows. As far as I have been able to figure out is that it is my Full Outer Joins that are slowing down my query. I am fine if I can just get it down to 2~3 seconds.



Here is my query:



SELECT j.JobId, j.OrderId, j.OrderType, j.ShopName, j.ShipDate, j.CompletionDate, j.InstallDate, j.DayPriority,
j.ShipDateConfirmed, j.IsAddon, j.CashOnDelivery, ds.ShopLabel, ds.DesignSetId, dsp.DesignSetProcessId, dsp.DueDate AS DesignSetProcessDueDate,
dsp.DatetimeStarted, dsp.DatetimeComplete, dsp.BatchNumber, p.Name AS ProcessName, p.ProcessId, p.ZoneId, X.CabinetCount
FROM Jobs j
JOIN DesignSets ds ON j.JobId = ds.JobId
FULL OUTER JOIN Schedule.DesignSetProcessesWithDueDates dsp ON ds.DesignSetId = dsp.DesignSetId
FULL OUTER JOIN Schedule.Processes p ON dsp.ProcessId = p.ProcessId
OUTER APPLY(Select SUM(pr.Quantity * pr.DeliveryCnt) AS CabinetCount FROM Products pr WHERE ds.DesignSetId = pr.DesignSetId AND
(dsp.BatchNumber = pr.BatchNumber OR dsp.DesignSetId IS NULL)) AS X
WHERE j.Status >= 60 AND j.Status <= 70
ORDER BY j.CompletionDate, j.DayPriority DESC, j.ShopName, j.OrderId, ds.ShopLabel, p.SortOrder, dsp.BatchNumber


This query gets a master view of the jobs and the processes within the job. All the information that I am getting is needed and all the rows are to.



Is there anything that I can use as a substitute for the Full Outer Joins?



If I can just get one of them to go faster I think the query would work better.



If you have any suggestion to how I can speed up the rest of my query I am willing to give it a shot.



EDIT



Here is the link to paste the plan: https://www.brentozar.com/pastetheplan/?id=SytXw1dum



UPDATE



Turns out one of the columns from a view was slowing everything down, so I got rid of dsp.DueDate AS DesignSetProcessDueDate and now it runs in less than a second. I was able to find out how that view was getting the information and put it right into my query.










share|improve this question
















bumped to the homepage by Community 9 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • I put my execution plan in there. If you need any more information just let me know. Thank you for responding.

    – DalTron
    Sep 12 '18 at 21:16






  • 1





    The graphical plan is not enough. use brentozar.com/pastetheplan/instructions

    – SQLRaptor
    Sep 12 '18 at 22:16











  • Thank you for the clarification, I have posted the link through pastetheplan.com and I have added a link to go view that.

    – DalTron
    Sep 13 '18 at 13:35











  • Are plans improved if you replace the two FULL joins with LEFT ones?

    – ypercubeᵀᴹ
    Sep 13 '18 at 13:48













  • No, they aren't. If I just do a join the speed is improved, but I also loose some rows. Though I didn't lose any rows when I did a LEFT join, so I guess it's not the Full Outer Join that is the problem

    – DalTron
    Sep 13 '18 at 14:09














1












1








1


2






I am relatively new to SQL, so I apologize if I ask some basic questions.



Our database is setup on Azure, we have automatic indexes turned on. The query I have takes about 6 seconds and gets 2217 rows. As far as I have been able to figure out is that it is my Full Outer Joins that are slowing down my query. I am fine if I can just get it down to 2~3 seconds.



Here is my query:



SELECT j.JobId, j.OrderId, j.OrderType, j.ShopName, j.ShipDate, j.CompletionDate, j.InstallDate, j.DayPriority,
j.ShipDateConfirmed, j.IsAddon, j.CashOnDelivery, ds.ShopLabel, ds.DesignSetId, dsp.DesignSetProcessId, dsp.DueDate AS DesignSetProcessDueDate,
dsp.DatetimeStarted, dsp.DatetimeComplete, dsp.BatchNumber, p.Name AS ProcessName, p.ProcessId, p.ZoneId, X.CabinetCount
FROM Jobs j
JOIN DesignSets ds ON j.JobId = ds.JobId
FULL OUTER JOIN Schedule.DesignSetProcessesWithDueDates dsp ON ds.DesignSetId = dsp.DesignSetId
FULL OUTER JOIN Schedule.Processes p ON dsp.ProcessId = p.ProcessId
OUTER APPLY(Select SUM(pr.Quantity * pr.DeliveryCnt) AS CabinetCount FROM Products pr WHERE ds.DesignSetId = pr.DesignSetId AND
(dsp.BatchNumber = pr.BatchNumber OR dsp.DesignSetId IS NULL)) AS X
WHERE j.Status >= 60 AND j.Status <= 70
ORDER BY j.CompletionDate, j.DayPriority DESC, j.ShopName, j.OrderId, ds.ShopLabel, p.SortOrder, dsp.BatchNumber


This query gets a master view of the jobs and the processes within the job. All the information that I am getting is needed and all the rows are to.



Is there anything that I can use as a substitute for the Full Outer Joins?



If I can just get one of them to go faster I think the query would work better.



If you have any suggestion to how I can speed up the rest of my query I am willing to give it a shot.



EDIT



Here is the link to paste the plan: https://www.brentozar.com/pastetheplan/?id=SytXw1dum



UPDATE



Turns out one of the columns from a view was slowing everything down, so I got rid of dsp.DueDate AS DesignSetProcessDueDate and now it runs in less than a second. I was able to find out how that view was getting the information and put it right into my query.










share|improve this question
















I am relatively new to SQL, so I apologize if I ask some basic questions.



Our database is setup on Azure, we have automatic indexes turned on. The query I have takes about 6 seconds and gets 2217 rows. As far as I have been able to figure out is that it is my Full Outer Joins that are slowing down my query. I am fine if I can just get it down to 2~3 seconds.



Here is my query:



SELECT j.JobId, j.OrderId, j.OrderType, j.ShopName, j.ShipDate, j.CompletionDate, j.InstallDate, j.DayPriority,
j.ShipDateConfirmed, j.IsAddon, j.CashOnDelivery, ds.ShopLabel, ds.DesignSetId, dsp.DesignSetProcessId, dsp.DueDate AS DesignSetProcessDueDate,
dsp.DatetimeStarted, dsp.DatetimeComplete, dsp.BatchNumber, p.Name AS ProcessName, p.ProcessId, p.ZoneId, X.CabinetCount
FROM Jobs j
JOIN DesignSets ds ON j.JobId = ds.JobId
FULL OUTER JOIN Schedule.DesignSetProcessesWithDueDates dsp ON ds.DesignSetId = dsp.DesignSetId
FULL OUTER JOIN Schedule.Processes p ON dsp.ProcessId = p.ProcessId
OUTER APPLY(Select SUM(pr.Quantity * pr.DeliveryCnt) AS CabinetCount FROM Products pr WHERE ds.DesignSetId = pr.DesignSetId AND
(dsp.BatchNumber = pr.BatchNumber OR dsp.DesignSetId IS NULL)) AS X
WHERE j.Status >= 60 AND j.Status <= 70
ORDER BY j.CompletionDate, j.DayPriority DESC, j.ShopName, j.OrderId, ds.ShopLabel, p.SortOrder, dsp.BatchNumber


This query gets a master view of the jobs and the processes within the job. All the information that I am getting is needed and all the rows are to.



Is there anything that I can use as a substitute for the Full Outer Joins?



If I can just get one of them to go faster I think the query would work better.



If you have any suggestion to how I can speed up the rest of my query I am willing to give it a shot.



EDIT



Here is the link to paste the plan: https://www.brentozar.com/pastetheplan/?id=SytXw1dum



UPDATE



Turns out one of the columns from a view was slowing everything down, so I got rid of dsp.DueDate AS DesignSetProcessDueDate and now it runs in less than a second. I was able to find out how that view was getting the information and put it right into my query.







sql-server join azure-sql-database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 19 '18 at 15:27







DalTron

















asked Sep 12 '18 at 19:50









DalTronDalTron

4114




4114





bumped to the homepage by Community 9 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 9 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • I put my execution plan in there. If you need any more information just let me know. Thank you for responding.

    – DalTron
    Sep 12 '18 at 21:16






  • 1





    The graphical plan is not enough. use brentozar.com/pastetheplan/instructions

    – SQLRaptor
    Sep 12 '18 at 22:16











  • Thank you for the clarification, I have posted the link through pastetheplan.com and I have added a link to go view that.

    – DalTron
    Sep 13 '18 at 13:35











  • Are plans improved if you replace the two FULL joins with LEFT ones?

    – ypercubeᵀᴹ
    Sep 13 '18 at 13:48













  • No, they aren't. If I just do a join the speed is improved, but I also loose some rows. Though I didn't lose any rows when I did a LEFT join, so I guess it's not the Full Outer Join that is the problem

    – DalTron
    Sep 13 '18 at 14:09



















  • I put my execution plan in there. If you need any more information just let me know. Thank you for responding.

    – DalTron
    Sep 12 '18 at 21:16






  • 1





    The graphical plan is not enough. use brentozar.com/pastetheplan/instructions

    – SQLRaptor
    Sep 12 '18 at 22:16











  • Thank you for the clarification, I have posted the link through pastetheplan.com and I have added a link to go view that.

    – DalTron
    Sep 13 '18 at 13:35











  • Are plans improved if you replace the two FULL joins with LEFT ones?

    – ypercubeᵀᴹ
    Sep 13 '18 at 13:48













  • No, they aren't. If I just do a join the speed is improved, but I also loose some rows. Though I didn't lose any rows when I did a LEFT join, so I guess it's not the Full Outer Join that is the problem

    – DalTron
    Sep 13 '18 at 14:09

















I put my execution plan in there. If you need any more information just let me know. Thank you for responding.

– DalTron
Sep 12 '18 at 21:16





I put my execution plan in there. If you need any more information just let me know. Thank you for responding.

– DalTron
Sep 12 '18 at 21:16




1




1





The graphical plan is not enough. use brentozar.com/pastetheplan/instructions

– SQLRaptor
Sep 12 '18 at 22:16





The graphical plan is not enough. use brentozar.com/pastetheplan/instructions

– SQLRaptor
Sep 12 '18 at 22:16













Thank you for the clarification, I have posted the link through pastetheplan.com and I have added a link to go view that.

– DalTron
Sep 13 '18 at 13:35





Thank you for the clarification, I have posted the link through pastetheplan.com and I have added a link to go view that.

– DalTron
Sep 13 '18 at 13:35













Are plans improved if you replace the two FULL joins with LEFT ones?

– ypercubeᵀᴹ
Sep 13 '18 at 13:48







Are plans improved if you replace the two FULL joins with LEFT ones?

– ypercubeᵀᴹ
Sep 13 '18 at 13:48















No, they aren't. If I just do a join the speed is improved, but I also loose some rows. Though I didn't lose any rows when I did a LEFT join, so I guess it's not the Full Outer Join that is the problem

– DalTron
Sep 13 '18 at 14:09





No, they aren't. If I just do a join the speed is improved, but I also loose some rows. Though I didn't lose any rows when I did a LEFT join, so I guess it's not the Full Outer Join that is the problem

– DalTron
Sep 13 '18 at 14:09










1 Answer
1






active

oldest

votes


















0














updating answer to Use LEFT JOINS..



SELECT j.JobId
, j.OrderId
, j.OrderType
, j.ShopName
, j.ShipDate
, j.CompletionDate
, j.InstallDate
, j.DayPriority
, j.ShipDateConfirmed
, j.IsAddon
, j.CashOnDelivery
, ds.ShopLabel
, ds.DesignSetId
, dsp.DesignSetProcessId
, dsp.DueDate AS DesignSetProcessDueDate
, dsp.DatetimeStarted
, dsp.DatetimeComplete
, dsp.BatchNumber
, p.Name AS ProcessName
, p.ProcessId
, p.ZoneId
, (
SELECT SUM(pr.Quantity * pr.DeliveryCnt) AS CabinetCount
FROM Products pr
WHERE ds.DesignSetId = pr.DesignSetId
AND (
dsp.BatchNumber = pr.BatchNumber
-- OR dsp.DesignSetId IS NULL Note : Since dsp.DesignSetId = ds.DesignSetId this condition can be omitted. uncomment it if necessary.
)
) AS CabinetCount
FROM Jobs j
JOIN DesignSets ds
ON j.JobId = ds.JobId
LEFT OUTER JOIN Schedule.DesignSetProcessesWithDueDates dsp
ON ds.DesignSetId = dsp.DesignSetId
LEFT OUTER JOIN Schedule.Processes p
ON dsp.ProcessId = p.ProcessId
WHERE j.Status >= 60
AND j.Status <= 70
ORDER BY j.CompletionDate
, j.DayPriority DESC
, j.ShopName
, j.OrderId
, ds.ShopLabel
, p.SortOrder
, dsp.BatchNumber;





share|improve this answer


























  • Thanks for your answer, but unfortunately even if I remove the Outer Apply and the CabinetCount from my entire query it doesn't speed the query up at all.

    – DalTron
    Sep 13 '18 at 15:16











  • Next step would be to replace FULL OUTER JOIN with LEFT OUTER JOINS as mentioned in other comments. Since the DesignSets table is being joined with with jobs table only those records from DesignSets will qualify which have jobsid. Hence converting FULL Outer to Left should produce same result set

    – Unkush
    Sep 13 '18 at 15:48













  • replacing FULL OUTER JOIN with LEFT OUTER JOINS doesn't speed the query up. I think I need to do something like what @SEarle1986 suggested, but I am waiting for a coworker to get some time, so we can look at it.

    – DalTron
    Sep 13 '18 at 16:07











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f217427%2ffull-outer-joins-slowing-down-query%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














updating answer to Use LEFT JOINS..



SELECT j.JobId
, j.OrderId
, j.OrderType
, j.ShopName
, j.ShipDate
, j.CompletionDate
, j.InstallDate
, j.DayPriority
, j.ShipDateConfirmed
, j.IsAddon
, j.CashOnDelivery
, ds.ShopLabel
, ds.DesignSetId
, dsp.DesignSetProcessId
, dsp.DueDate AS DesignSetProcessDueDate
, dsp.DatetimeStarted
, dsp.DatetimeComplete
, dsp.BatchNumber
, p.Name AS ProcessName
, p.ProcessId
, p.ZoneId
, (
SELECT SUM(pr.Quantity * pr.DeliveryCnt) AS CabinetCount
FROM Products pr
WHERE ds.DesignSetId = pr.DesignSetId
AND (
dsp.BatchNumber = pr.BatchNumber
-- OR dsp.DesignSetId IS NULL Note : Since dsp.DesignSetId = ds.DesignSetId this condition can be omitted. uncomment it if necessary.
)
) AS CabinetCount
FROM Jobs j
JOIN DesignSets ds
ON j.JobId = ds.JobId
LEFT OUTER JOIN Schedule.DesignSetProcessesWithDueDates dsp
ON ds.DesignSetId = dsp.DesignSetId
LEFT OUTER JOIN Schedule.Processes p
ON dsp.ProcessId = p.ProcessId
WHERE j.Status >= 60
AND j.Status <= 70
ORDER BY j.CompletionDate
, j.DayPriority DESC
, j.ShopName
, j.OrderId
, ds.ShopLabel
, p.SortOrder
, dsp.BatchNumber;





share|improve this answer


























  • Thanks for your answer, but unfortunately even if I remove the Outer Apply and the CabinetCount from my entire query it doesn't speed the query up at all.

    – DalTron
    Sep 13 '18 at 15:16











  • Next step would be to replace FULL OUTER JOIN with LEFT OUTER JOINS as mentioned in other comments. Since the DesignSets table is being joined with with jobs table only those records from DesignSets will qualify which have jobsid. Hence converting FULL Outer to Left should produce same result set

    – Unkush
    Sep 13 '18 at 15:48













  • replacing FULL OUTER JOIN with LEFT OUTER JOINS doesn't speed the query up. I think I need to do something like what @SEarle1986 suggested, but I am waiting for a coworker to get some time, so we can look at it.

    – DalTron
    Sep 13 '18 at 16:07
















0














updating answer to Use LEFT JOINS..



SELECT j.JobId
, j.OrderId
, j.OrderType
, j.ShopName
, j.ShipDate
, j.CompletionDate
, j.InstallDate
, j.DayPriority
, j.ShipDateConfirmed
, j.IsAddon
, j.CashOnDelivery
, ds.ShopLabel
, ds.DesignSetId
, dsp.DesignSetProcessId
, dsp.DueDate AS DesignSetProcessDueDate
, dsp.DatetimeStarted
, dsp.DatetimeComplete
, dsp.BatchNumber
, p.Name AS ProcessName
, p.ProcessId
, p.ZoneId
, (
SELECT SUM(pr.Quantity * pr.DeliveryCnt) AS CabinetCount
FROM Products pr
WHERE ds.DesignSetId = pr.DesignSetId
AND (
dsp.BatchNumber = pr.BatchNumber
-- OR dsp.DesignSetId IS NULL Note : Since dsp.DesignSetId = ds.DesignSetId this condition can be omitted. uncomment it if necessary.
)
) AS CabinetCount
FROM Jobs j
JOIN DesignSets ds
ON j.JobId = ds.JobId
LEFT OUTER JOIN Schedule.DesignSetProcessesWithDueDates dsp
ON ds.DesignSetId = dsp.DesignSetId
LEFT OUTER JOIN Schedule.Processes p
ON dsp.ProcessId = p.ProcessId
WHERE j.Status >= 60
AND j.Status <= 70
ORDER BY j.CompletionDate
, j.DayPriority DESC
, j.ShopName
, j.OrderId
, ds.ShopLabel
, p.SortOrder
, dsp.BatchNumber;





share|improve this answer


























  • Thanks for your answer, but unfortunately even if I remove the Outer Apply and the CabinetCount from my entire query it doesn't speed the query up at all.

    – DalTron
    Sep 13 '18 at 15:16











  • Next step would be to replace FULL OUTER JOIN with LEFT OUTER JOINS as mentioned in other comments. Since the DesignSets table is being joined with with jobs table only those records from DesignSets will qualify which have jobsid. Hence converting FULL Outer to Left should produce same result set

    – Unkush
    Sep 13 '18 at 15:48













  • replacing FULL OUTER JOIN with LEFT OUTER JOINS doesn't speed the query up. I think I need to do something like what @SEarle1986 suggested, but I am waiting for a coworker to get some time, so we can look at it.

    – DalTron
    Sep 13 '18 at 16:07














0












0








0







updating answer to Use LEFT JOINS..



SELECT j.JobId
, j.OrderId
, j.OrderType
, j.ShopName
, j.ShipDate
, j.CompletionDate
, j.InstallDate
, j.DayPriority
, j.ShipDateConfirmed
, j.IsAddon
, j.CashOnDelivery
, ds.ShopLabel
, ds.DesignSetId
, dsp.DesignSetProcessId
, dsp.DueDate AS DesignSetProcessDueDate
, dsp.DatetimeStarted
, dsp.DatetimeComplete
, dsp.BatchNumber
, p.Name AS ProcessName
, p.ProcessId
, p.ZoneId
, (
SELECT SUM(pr.Quantity * pr.DeliveryCnt) AS CabinetCount
FROM Products pr
WHERE ds.DesignSetId = pr.DesignSetId
AND (
dsp.BatchNumber = pr.BatchNumber
-- OR dsp.DesignSetId IS NULL Note : Since dsp.DesignSetId = ds.DesignSetId this condition can be omitted. uncomment it if necessary.
)
) AS CabinetCount
FROM Jobs j
JOIN DesignSets ds
ON j.JobId = ds.JobId
LEFT OUTER JOIN Schedule.DesignSetProcessesWithDueDates dsp
ON ds.DesignSetId = dsp.DesignSetId
LEFT OUTER JOIN Schedule.Processes p
ON dsp.ProcessId = p.ProcessId
WHERE j.Status >= 60
AND j.Status <= 70
ORDER BY j.CompletionDate
, j.DayPriority DESC
, j.ShopName
, j.OrderId
, ds.ShopLabel
, p.SortOrder
, dsp.BatchNumber;





share|improve this answer















updating answer to Use LEFT JOINS..



SELECT j.JobId
, j.OrderId
, j.OrderType
, j.ShopName
, j.ShipDate
, j.CompletionDate
, j.InstallDate
, j.DayPriority
, j.ShipDateConfirmed
, j.IsAddon
, j.CashOnDelivery
, ds.ShopLabel
, ds.DesignSetId
, dsp.DesignSetProcessId
, dsp.DueDate AS DesignSetProcessDueDate
, dsp.DatetimeStarted
, dsp.DatetimeComplete
, dsp.BatchNumber
, p.Name AS ProcessName
, p.ProcessId
, p.ZoneId
, (
SELECT SUM(pr.Quantity * pr.DeliveryCnt) AS CabinetCount
FROM Products pr
WHERE ds.DesignSetId = pr.DesignSetId
AND (
dsp.BatchNumber = pr.BatchNumber
-- OR dsp.DesignSetId IS NULL Note : Since dsp.DesignSetId = ds.DesignSetId this condition can be omitted. uncomment it if necessary.
)
) AS CabinetCount
FROM Jobs j
JOIN DesignSets ds
ON j.JobId = ds.JobId
LEFT OUTER JOIN Schedule.DesignSetProcessesWithDueDates dsp
ON ds.DesignSetId = dsp.DesignSetId
LEFT OUTER JOIN Schedule.Processes p
ON dsp.ProcessId = p.ProcessId
WHERE j.Status >= 60
AND j.Status <= 70
ORDER BY j.CompletionDate
, j.DayPriority DESC
, j.ShopName
, j.OrderId
, ds.ShopLabel
, p.SortOrder
, dsp.BatchNumber;






share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 13 '18 at 15:54

























answered Sep 13 '18 at 14:57









UnkushUnkush

1104




1104













  • Thanks for your answer, but unfortunately even if I remove the Outer Apply and the CabinetCount from my entire query it doesn't speed the query up at all.

    – DalTron
    Sep 13 '18 at 15:16











  • Next step would be to replace FULL OUTER JOIN with LEFT OUTER JOINS as mentioned in other comments. Since the DesignSets table is being joined with with jobs table only those records from DesignSets will qualify which have jobsid. Hence converting FULL Outer to Left should produce same result set

    – Unkush
    Sep 13 '18 at 15:48













  • replacing FULL OUTER JOIN with LEFT OUTER JOINS doesn't speed the query up. I think I need to do something like what @SEarle1986 suggested, but I am waiting for a coworker to get some time, so we can look at it.

    – DalTron
    Sep 13 '18 at 16:07



















  • Thanks for your answer, but unfortunately even if I remove the Outer Apply and the CabinetCount from my entire query it doesn't speed the query up at all.

    – DalTron
    Sep 13 '18 at 15:16











  • Next step would be to replace FULL OUTER JOIN with LEFT OUTER JOINS as mentioned in other comments. Since the DesignSets table is being joined with with jobs table only those records from DesignSets will qualify which have jobsid. Hence converting FULL Outer to Left should produce same result set

    – Unkush
    Sep 13 '18 at 15:48













  • replacing FULL OUTER JOIN with LEFT OUTER JOINS doesn't speed the query up. I think I need to do something like what @SEarle1986 suggested, but I am waiting for a coworker to get some time, so we can look at it.

    – DalTron
    Sep 13 '18 at 16:07

















Thanks for your answer, but unfortunately even if I remove the Outer Apply and the CabinetCount from my entire query it doesn't speed the query up at all.

– DalTron
Sep 13 '18 at 15:16





Thanks for your answer, but unfortunately even if I remove the Outer Apply and the CabinetCount from my entire query it doesn't speed the query up at all.

– DalTron
Sep 13 '18 at 15:16













Next step would be to replace FULL OUTER JOIN with LEFT OUTER JOINS as mentioned in other comments. Since the DesignSets table is being joined with with jobs table only those records from DesignSets will qualify which have jobsid. Hence converting FULL Outer to Left should produce same result set

– Unkush
Sep 13 '18 at 15:48







Next step would be to replace FULL OUTER JOIN with LEFT OUTER JOINS as mentioned in other comments. Since the DesignSets table is being joined with with jobs table only those records from DesignSets will qualify which have jobsid. Hence converting FULL Outer to Left should produce same result set

– Unkush
Sep 13 '18 at 15:48















replacing FULL OUTER JOIN with LEFT OUTER JOINS doesn't speed the query up. I think I need to do something like what @SEarle1986 suggested, but I am waiting for a coworker to get some time, so we can look at it.

– DalTron
Sep 13 '18 at 16:07





replacing FULL OUTER JOIN with LEFT OUTER JOINS doesn't speed the query up. I think I need to do something like what @SEarle1986 suggested, but I am waiting for a coworker to get some time, so we can look at it.

– DalTron
Sep 13 '18 at 16:07


















draft saved

draft discarded




















































Thanks for contributing an answer to Database Administrators Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f217427%2ffull-outer-joins-slowing-down-query%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Anexo:Material bélico de la Fuerza Aérea de Chile Índice Aeronaves Defensa...

Always On Availability groups resolving state after failover - Remote harden of transaction...

update json value to null Announcing the arrival of Valued Associate #679: Cesar Manara ...