Example of query execution plan where the cardinality estimation makes a differenceWhy is my query suddenly slower than it was yesterday?SQL Server cardinality hintVery similar queries, vastly different performanceLarge variances between two similar queries when doing WHERE EXISTS on related tablewhat is more important on a query execution plan, cardinality or selectivity?Different execution plan for the same query if I change a value in the predicateoptimize the query with big and low cardinalityHow does SQL Server's optimizer estimate the number of rows in a joined table?Understanding below execution planHow to hint many-to-many join in SQL Server?Estimation failure in Stored Procedure execution planIndex Seek Operator CostImproving statistics on a large “WHERE IN” SQL Server queryNeed to understand the drastic difference in execution plan between two querieswhat is more important on a query execution plan, cardinality or selectivity?

What happens if a caster is surprised while casting a spell with a long casting time?

How useful would a hydroelectric power plant be in the post-apocalypse world?

How do I present a future free of gender stereotypes without being jarring or overpowering the narrative?

A* pathfinding algorithm too slow

Could all three Gorgons turn people to stone, or just Medusa?

What specifically counts as "anything" in spell text?

How to track mail undetectably?

Why doesn't SpaceX land boosters in Africa?

Is it advisable to inform the CEO about his brother accessing his office?

Delete all files from a folder using a bat that match a certain pattern in Windows 10

What does 'in attendance' mean on a death certificate - England?

German idiomatic equivalents of 能骗就骗 (if you can trick, then trick)

What verb for taking advantage fits in "I don't want to ________ on the friendship"?

The Lucas argument vs the theorem-provers -- who wins and why?

Is my guitar action too high or is the bridge too high?

Why should I allow multiple IPs on a website for a single session?

Calculus, water poured into a cone: Why is the derivative non-linear?

Can dual citizens open crypto exchange accounts where U.S. citizens are prohibited?

What does 5d4 x 10 gp mean?

Do electrons really perform instantaneous quantum leaps?

How would one prevent political gerrymandering?

Is it theoretically possible to hack printer using scanner tray?

Why do movie directors use brown tint on Mexico cities?

Dynamic Sql Query - how to add an int to the code?



Example of query execution plan where the cardinality estimation makes a difference


Why is my query suddenly slower than it was yesterday?SQL Server cardinality hintVery similar queries, vastly different performanceLarge variances between two similar queries when doing WHERE EXISTS on related tablewhat is more important on a query execution plan, cardinality or selectivity?Different execution plan for the same query if I change a value in the predicateoptimize the query with big and low cardinalityHow does SQL Server's optimizer estimate the number of rows in a joined table?Understanding below execution planHow to hint many-to-many join in SQL Server?Estimation failure in Stored Procedure execution planIndex Seek Operator CostImproving statistics on a large “WHERE IN” SQL Server queryNeed to understand the drastic difference in execution plan between two querieswhat is more important on a query execution plan, cardinality or selectivity?













1















I am trying to create an example of a query execution plan which shows that if I have the cardinality estimation for some column of a table I can decide which query execution plan has the least cost.



So I have these two posts (1 and 2) which I can understand estimated cardinality as the number of distinct values on a column. And then I calculate the selectivity.



SELECT max(price) FROM tickets WHERE country = "CANADA";


If my table has 180 items and only 10 are CANADA. And there are only 4 different countries (CANADA, BRAZIL, USA, GERMANY). So....



the cardinality of column country é 4, because it is the number of distinct items.



The selectivity of the column country = CANADA is the number of items accessed divided by the items on the table. 10/180 = 0.0555.



But which are the different query execution plans that the optimizer could choose based on the cardinality?



If this is not a good example, could someone point one query that the cardinality would be a treasure to the optimizer in order to decide to chose one plan versus another?



Thanks,
Felipe










share|improve this question


























    1















    I am trying to create an example of a query execution plan which shows that if I have the cardinality estimation for some column of a table I can decide which query execution plan has the least cost.



    So I have these two posts (1 and 2) which I can understand estimated cardinality as the number of distinct values on a column. And then I calculate the selectivity.



    SELECT max(price) FROM tickets WHERE country = "CANADA";


    If my table has 180 items and only 10 are CANADA. And there are only 4 different countries (CANADA, BRAZIL, USA, GERMANY). So....



    the cardinality of column country é 4, because it is the number of distinct items.



    The selectivity of the column country = CANADA is the number of items accessed divided by the items on the table. 10/180 = 0.0555.



    But which are the different query execution plans that the optimizer could choose based on the cardinality?



    If this is not a good example, could someone point one query that the cardinality would be a treasure to the optimizer in order to decide to chose one plan versus another?



    Thanks,
    Felipe










    share|improve this question
























      1












      1








      1








      I am trying to create an example of a query execution plan which shows that if I have the cardinality estimation for some column of a table I can decide which query execution plan has the least cost.



      So I have these two posts (1 and 2) which I can understand estimated cardinality as the number of distinct values on a column. And then I calculate the selectivity.



      SELECT max(price) FROM tickets WHERE country = "CANADA";


      If my table has 180 items and only 10 are CANADA. And there are only 4 different countries (CANADA, BRAZIL, USA, GERMANY). So....



      the cardinality of column country é 4, because it is the number of distinct items.



      The selectivity of the column country = CANADA is the number of items accessed divided by the items on the table. 10/180 = 0.0555.



      But which are the different query execution plans that the optimizer could choose based on the cardinality?



      If this is not a good example, could someone point one query that the cardinality would be a treasure to the optimizer in order to decide to chose one plan versus another?



      Thanks,
      Felipe










      share|improve this question














      I am trying to create an example of a query execution plan which shows that if I have the cardinality estimation for some column of a table I can decide which query execution plan has the least cost.



      So I have these two posts (1 and 2) which I can understand estimated cardinality as the number of distinct values on a column. And then I calculate the selectivity.



      SELECT max(price) FROM tickets WHERE country = "CANADA";


      If my table has 180 items and only 10 are CANADA. And there are only 4 different countries (CANADA, BRAZIL, USA, GERMANY). So....



      the cardinality of column country é 4, because it is the number of distinct items.



      The selectivity of the column country = CANADA is the number of items accessed divided by the items on the table. 10/180 = 0.0555.



      But which are the different query execution plans that the optimizer could choose based on the cardinality?



      If this is not a good example, could someone point one query that the cardinality would be a treasure to the optimizer in order to decide to chose one plan versus another?



      Thanks,
      Felipe







      optimization execution-plan cardinality-estimates






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 8 hours ago









      FelipeFelipe

      1193 bronze badges




      1193 bronze badges




















          2 Answers
          2






          active

          oldest

          votes


















          3














          At 180 rows, you're not likely to see any difference whatsoever.



          In order to see different plans get chosen at different predicate distributions, you'd need quite bit more data, and likely competing data sources (indexes) to aid them.



          Let's say you had 1.8mm rows in the table. If you've got



          • A clustered index on a column unrelated to price or country (Like Id or something)

          • A nonclustered index on price and country

          • A single column nonclustered index on country

          You may start to see a difference in the method of aggregation, serial vs. parallel plans chosen, and index choice, depending on which country you search for and its selectivity.



          For an example of a recent Q&A:



          • Large variances between two similar queries when doing WHERE EXISTS on related table

          For a more complex reasons:



          • Why is my query suddenly slower than it was yesterday?





          share|improve this answer
































            2














            So this isn't exactly what you are looking for, but it may help. I provided an answer to a separate question asked last week.



            Very similar queries, vastly different performance



            In this question the addition of a single value to a IN() statement changed the query plan and execution time. There is an awesome answer to that question provided by a different person so hopefully it give you the details you are looking for.






            share|improve this answer

























              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%2f241624%2fexample-of-query-execution-plan-where-the-cardinality-estimation-makes-a-differe%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              At 180 rows, you're not likely to see any difference whatsoever.



              In order to see different plans get chosen at different predicate distributions, you'd need quite bit more data, and likely competing data sources (indexes) to aid them.



              Let's say you had 1.8mm rows in the table. If you've got



              • A clustered index on a column unrelated to price or country (Like Id or something)

              • A nonclustered index on price and country

              • A single column nonclustered index on country

              You may start to see a difference in the method of aggregation, serial vs. parallel plans chosen, and index choice, depending on which country you search for and its selectivity.



              For an example of a recent Q&A:



              • Large variances between two similar queries when doing WHERE EXISTS on related table

              For a more complex reasons:



              • Why is my query suddenly slower than it was yesterday?





              share|improve this answer





























                3














                At 180 rows, you're not likely to see any difference whatsoever.



                In order to see different plans get chosen at different predicate distributions, you'd need quite bit more data, and likely competing data sources (indexes) to aid them.



                Let's say you had 1.8mm rows in the table. If you've got



                • A clustered index on a column unrelated to price or country (Like Id or something)

                • A nonclustered index on price and country

                • A single column nonclustered index on country

                You may start to see a difference in the method of aggregation, serial vs. parallel plans chosen, and index choice, depending on which country you search for and its selectivity.



                For an example of a recent Q&A:



                • Large variances between two similar queries when doing WHERE EXISTS on related table

                For a more complex reasons:



                • Why is my query suddenly slower than it was yesterday?





                share|improve this answer



























                  3












                  3








                  3







                  At 180 rows, you're not likely to see any difference whatsoever.



                  In order to see different plans get chosen at different predicate distributions, you'd need quite bit more data, and likely competing data sources (indexes) to aid them.



                  Let's say you had 1.8mm rows in the table. If you've got



                  • A clustered index on a column unrelated to price or country (Like Id or something)

                  • A nonclustered index on price and country

                  • A single column nonclustered index on country

                  You may start to see a difference in the method of aggregation, serial vs. parallel plans chosen, and index choice, depending on which country you search for and its selectivity.



                  For an example of a recent Q&A:



                  • Large variances between two similar queries when doing WHERE EXISTS on related table

                  For a more complex reasons:



                  • Why is my query suddenly slower than it was yesterday?





                  share|improve this answer















                  At 180 rows, you're not likely to see any difference whatsoever.



                  In order to see different plans get chosen at different predicate distributions, you'd need quite bit more data, and likely competing data sources (indexes) to aid them.



                  Let's say you had 1.8mm rows in the table. If you've got



                  • A clustered index on a column unrelated to price or country (Like Id or something)

                  • A nonclustered index on price and country

                  • A single column nonclustered index on country

                  You may start to see a difference in the method of aggregation, serial vs. parallel plans chosen, and index choice, depending on which country you search for and its selectivity.



                  For an example of a recent Q&A:



                  • Large variances between two similar queries when doing WHERE EXISTS on related table

                  For a more complex reasons:



                  • Why is my query suddenly slower than it was yesterday?






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 7 hours ago

























                  answered 8 hours ago









                  Erik DarlingErik Darling

                  25.2k13 gold badges77 silver badges127 bronze badges




                  25.2k13 gold badges77 silver badges127 bronze badges





















                      2














                      So this isn't exactly what you are looking for, but it may help. I provided an answer to a separate question asked last week.



                      Very similar queries, vastly different performance



                      In this question the addition of a single value to a IN() statement changed the query plan and execution time. There is an awesome answer to that question provided by a different person so hopefully it give you the details you are looking for.






                      share|improve this answer



























                        2














                        So this isn't exactly what you are looking for, but it may help. I provided an answer to a separate question asked last week.



                        Very similar queries, vastly different performance



                        In this question the addition of a single value to a IN() statement changed the query plan and execution time. There is an awesome answer to that question provided by a different person so hopefully it give you the details you are looking for.






                        share|improve this answer

























                          2












                          2








                          2







                          So this isn't exactly what you are looking for, but it may help. I provided an answer to a separate question asked last week.



                          Very similar queries, vastly different performance



                          In this question the addition of a single value to a IN() statement changed the query plan and execution time. There is an awesome answer to that question provided by a different person so hopefully it give you the details you are looking for.






                          share|improve this answer













                          So this isn't exactly what you are looking for, but it may help. I provided an answer to a separate question asked last week.



                          Very similar queries, vastly different performance



                          In this question the addition of a single value to a IN() statement changed the query plan and execution time. There is an awesome answer to that question provided by a different person so hopefully it give you the details you are looking for.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 8 hours ago









                          Kirk SaundersKirk Saunders

                          4572 silver badges10 bronze badges




                          4572 silver badges10 bronze badges



























                              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%2f241624%2fexample-of-query-execution-plan-where-the-cardinality-estimation-makes-a-differe%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

                              Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                              Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                              François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480