Does it make a difference to performance if you join tables in a chain VS joining to a central table?












0















In a real scenario, there may be more tables, each having many columns.



Here is a greatly simplified example. If I join my tables like this:



enter image description here



Would there be any difference if I joined the tables like this:



enter image description here



I could test it for one particular case, but that wouldn't tell me if there is NEVER a difference, or if it depends on the exact query/data in each table.



My instinct tells me that it shouldn't make a difference, and the execution plan would be identical either way, but I would like someone to confirm that if possible.










share|improve this question


















  • 1





    There's really no way to answer this without examples of real schema and data. These are completely different queries, though. As it is in your example, it won't be long / take a ton of data in each table before each yields very different results.

    – squillman
    Nov 28 '18 at 15:07








  • 2





    DO NOT make design decisions for performance. You make design decisions to best model the data. Those two designs you posted are vastly different. You are going down the path of premature optimization which is the root of all evil.

    – Sean Lange
    Nov 28 '18 at 15:08











  • @SeanLange I'm sorry, I should have made it clear that the layout is only a view. The tables already exist. The design is already in place. The same ID's happen to exist in the tables and can be linked in the views in either configuration. So it's not really designing for performance. I am merely curious as to which approach would be preferred, or if it would make no actual difference.

    – Gravitate
    Nov 28 '18 at 15:34











  • Then why not create both queries and look at the execution plan. I would strongly advise you to NOT use the view designer. It does some really interesting things.

    – Sean Lange
    Nov 28 '18 at 15:35











  • @SeanLange Yes, as I say in the question, I could do that, however, that wouldn't tell me if it ALWAYS resulted in the same execution plan. Just because it happened to result in the same execution plan in my one test case, it doesn't mean that there aren't many cases where it would be different. I understand what you mean about the query designer, however, I thought it would be useful as an illustration.

    – Gravitate
    Nov 28 '18 at 15:40
















0















In a real scenario, there may be more tables, each having many columns.



Here is a greatly simplified example. If I join my tables like this:



enter image description here



Would there be any difference if I joined the tables like this:



enter image description here



I could test it for one particular case, but that wouldn't tell me if there is NEVER a difference, or if it depends on the exact query/data in each table.



My instinct tells me that it shouldn't make a difference, and the execution plan would be identical either way, but I would like someone to confirm that if possible.










share|improve this question


















  • 1





    There's really no way to answer this without examples of real schema and data. These are completely different queries, though. As it is in your example, it won't be long / take a ton of data in each table before each yields very different results.

    – squillman
    Nov 28 '18 at 15:07








  • 2





    DO NOT make design decisions for performance. You make design decisions to best model the data. Those two designs you posted are vastly different. You are going down the path of premature optimization which is the root of all evil.

    – Sean Lange
    Nov 28 '18 at 15:08











  • @SeanLange I'm sorry, I should have made it clear that the layout is only a view. The tables already exist. The design is already in place. The same ID's happen to exist in the tables and can be linked in the views in either configuration. So it's not really designing for performance. I am merely curious as to which approach would be preferred, or if it would make no actual difference.

    – Gravitate
    Nov 28 '18 at 15:34











  • Then why not create both queries and look at the execution plan. I would strongly advise you to NOT use the view designer. It does some really interesting things.

    – Sean Lange
    Nov 28 '18 at 15:35











  • @SeanLange Yes, as I say in the question, I could do that, however, that wouldn't tell me if it ALWAYS resulted in the same execution plan. Just because it happened to result in the same execution plan in my one test case, it doesn't mean that there aren't many cases where it would be different. I understand what you mean about the query designer, however, I thought it would be useful as an illustration.

    – Gravitate
    Nov 28 '18 at 15:40














0












0








0








In a real scenario, there may be more tables, each having many columns.



Here is a greatly simplified example. If I join my tables like this:



enter image description here



Would there be any difference if I joined the tables like this:



enter image description here



I could test it for one particular case, but that wouldn't tell me if there is NEVER a difference, or if it depends on the exact query/data in each table.



My instinct tells me that it shouldn't make a difference, and the execution plan would be identical either way, but I would like someone to confirm that if possible.










share|improve this question














In a real scenario, there may be more tables, each having many columns.



Here is a greatly simplified example. If I join my tables like this:



enter image description here



Would there be any difference if I joined the tables like this:



enter image description here



I could test it for one particular case, but that wouldn't tell me if there is NEVER a difference, or if it depends on the exact query/data in each table.



My instinct tells me that it shouldn't make a difference, and the execution plan would be identical either way, but I would like someone to confirm that if possible.







sql-server join






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 28 '18 at 15:02









GravitateGravitate

1,3921326




1,3921326








  • 1





    There's really no way to answer this without examples of real schema and data. These are completely different queries, though. As it is in your example, it won't be long / take a ton of data in each table before each yields very different results.

    – squillman
    Nov 28 '18 at 15:07








  • 2





    DO NOT make design decisions for performance. You make design decisions to best model the data. Those two designs you posted are vastly different. You are going down the path of premature optimization which is the root of all evil.

    – Sean Lange
    Nov 28 '18 at 15:08











  • @SeanLange I'm sorry, I should have made it clear that the layout is only a view. The tables already exist. The design is already in place. The same ID's happen to exist in the tables and can be linked in the views in either configuration. So it's not really designing for performance. I am merely curious as to which approach would be preferred, or if it would make no actual difference.

    – Gravitate
    Nov 28 '18 at 15:34











  • Then why not create both queries and look at the execution plan. I would strongly advise you to NOT use the view designer. It does some really interesting things.

    – Sean Lange
    Nov 28 '18 at 15:35











  • @SeanLange Yes, as I say in the question, I could do that, however, that wouldn't tell me if it ALWAYS resulted in the same execution plan. Just because it happened to result in the same execution plan in my one test case, it doesn't mean that there aren't many cases where it would be different. I understand what you mean about the query designer, however, I thought it would be useful as an illustration.

    – Gravitate
    Nov 28 '18 at 15:40














  • 1





    There's really no way to answer this without examples of real schema and data. These are completely different queries, though. As it is in your example, it won't be long / take a ton of data in each table before each yields very different results.

    – squillman
    Nov 28 '18 at 15:07








  • 2





    DO NOT make design decisions for performance. You make design decisions to best model the data. Those two designs you posted are vastly different. You are going down the path of premature optimization which is the root of all evil.

    – Sean Lange
    Nov 28 '18 at 15:08











  • @SeanLange I'm sorry, I should have made it clear that the layout is only a view. The tables already exist. The design is already in place. The same ID's happen to exist in the tables and can be linked in the views in either configuration. So it's not really designing for performance. I am merely curious as to which approach would be preferred, or if it would make no actual difference.

    – Gravitate
    Nov 28 '18 at 15:34











  • Then why not create both queries and look at the execution plan. I would strongly advise you to NOT use the view designer. It does some really interesting things.

    – Sean Lange
    Nov 28 '18 at 15:35











  • @SeanLange Yes, as I say in the question, I could do that, however, that wouldn't tell me if it ALWAYS resulted in the same execution plan. Just because it happened to result in the same execution plan in my one test case, it doesn't mean that there aren't many cases where it would be different. I understand what you mean about the query designer, however, I thought it would be useful as an illustration.

    – Gravitate
    Nov 28 '18 at 15:40








1




1





There's really no way to answer this without examples of real schema and data. These are completely different queries, though. As it is in your example, it won't be long / take a ton of data in each table before each yields very different results.

– squillman
Nov 28 '18 at 15:07







There's really no way to answer this without examples of real schema and data. These are completely different queries, though. As it is in your example, it won't be long / take a ton of data in each table before each yields very different results.

– squillman
Nov 28 '18 at 15:07






2




2





DO NOT make design decisions for performance. You make design decisions to best model the data. Those two designs you posted are vastly different. You are going down the path of premature optimization which is the root of all evil.

– Sean Lange
Nov 28 '18 at 15:08





DO NOT make design decisions for performance. You make design decisions to best model the data. Those two designs you posted are vastly different. You are going down the path of premature optimization which is the root of all evil.

– Sean Lange
Nov 28 '18 at 15:08













@SeanLange I'm sorry, I should have made it clear that the layout is only a view. The tables already exist. The design is already in place. The same ID's happen to exist in the tables and can be linked in the views in either configuration. So it's not really designing for performance. I am merely curious as to which approach would be preferred, or if it would make no actual difference.

– Gravitate
Nov 28 '18 at 15:34





@SeanLange I'm sorry, I should have made it clear that the layout is only a view. The tables already exist. The design is already in place. The same ID's happen to exist in the tables and can be linked in the views in either configuration. So it's not really designing for performance. I am merely curious as to which approach would be preferred, or if it would make no actual difference.

– Gravitate
Nov 28 '18 at 15:34













Then why not create both queries and look at the execution plan. I would strongly advise you to NOT use the view designer. It does some really interesting things.

– Sean Lange
Nov 28 '18 at 15:35





Then why not create both queries and look at the execution plan. I would strongly advise you to NOT use the view designer. It does some really interesting things.

– Sean Lange
Nov 28 '18 at 15:35













@SeanLange Yes, as I say in the question, I could do that, however, that wouldn't tell me if it ALWAYS resulted in the same execution plan. Just because it happened to result in the same execution plan in my one test case, it doesn't mean that there aren't many cases where it would be different. I understand what you mean about the query designer, however, I thought it would be useful as an illustration.

– Gravitate
Nov 28 '18 at 15:40





@SeanLange Yes, as I say in the question, I could do that, however, that wouldn't tell me if it ALWAYS resulted in the same execution plan. Just because it happened to result in the same execution plan in my one test case, it doesn't mean that there aren't many cases where it would be different. I understand what you mean about the query designer, however, I thought it would be useful as an illustration.

– Gravitate
Nov 28 '18 at 15:40












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f53522375%2fdoes-it-make-a-difference-to-performance-if-you-join-tables-in-a-chain-vs-joinin%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • 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%2fstackoverflow.com%2fquestions%2f53522375%2fdoes-it-make-a-difference-to-performance-if-you-join-tables-in-a-chain-vs-joinin%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

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)