Optimise multiple inner JOINmySQL efficiency with inner join queriesHow to optimise multiple joins with...

Are babies of evil humanoid species inherently evil?

Do I really need to have a scientific explanation for my premise?

What to do when during a meeting client people start to fight (even physically) with each others?

PTIJ: Why can't I eat anything?

How to pass a string to a command that expects a file?

Word for a person who has no opinion about whether god exists

Is it true that real estate prices mainly go up?

How strictly should I take "Candidates must be local"?

My story is written in English, but is set in my home country. What language should I use for the dialogue?

How do I locate a classical quotation?

How do you like my writing?

What is the chance of making a successful appeal to dismissal decision from a PhD program after failing the qualifying exam in the 2nd attempt?

Things to avoid when using voltage regulators?

What wound would be of little consequence to a biped but terrible for a quadruped?

Make a transparent 448*448 image

Why would a jet engine that runs at temps excess of 2000°C burn when it crashes?

Could you please stop shuffling the deck and play already?

Grey hair or white hair

Does "variables should live in the smallest scope as possible" include the case "variables should not exist if possible"?

Why is Beresheet doing a only a one-way trip?

A question on the ultrafilter number

In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?

MTG: Can I kill an opponent in response to lethal activated abilities, and not take the damage?

Rejected in 4th interview round citing insufficient years of experience



Optimise multiple inner JOIN


mySQL efficiency with inner join queriesHow to optimise multiple joins with OR?Subquery inside a select vs left joinOptimise a LATERAL JOIN query on a big tableHow to optimise this query?Simple Inner join suggesting a Include indexOptimise Large Record Deletion ProcedureCardinality estimation problem on inner joinwhy is update from a join containing zero records taking a minute and 20 seconds?schedule join multiple tables













0















Consider the following query:



 mysql> SELECT GROUP_CONCAT(a.id SEPARATOR 'n')
-> FROM assignment a
-> INNER JOIN statements s ON a.id = s.assignment_id
-> INNER JOIN assignment_status_log asl ON a.status_log_id = asl.id
-> INNER JOIN assignment_status ags ON asl.status_id = ags.id
-> WHERE ags.category <> 'PASSED'
-> AND ags.category <> 'TEST'
-> AND ags.category <> 'REJECTED'
-> AND ags.category <> 'CANCELED'
-> AND ags.category <> 'NA'
-> AND s.id IS NOT NULL
-> AND s.id IN (SELECT MAX(sts.id) AS dctrn__1 FROM assignment agr INNER JOIN statements sts ON agr.id = sts.assignment_id WHERE agr.id = a.id)
-> AND s.grade > 0
-> AND ags.types <> 'CB'
-> AND ags.types <> 'CD'
-> AND ags.types <> 'CE'
-> AND ags.types <> 'CF'
-> GROUP BY a.id;


I would like to have an idea as to how I can troubleshoot what is taking so long. I have added index on s.grades and ags.types column, and am pondering if I would need to try to have the conditions on the JOIN instead of in WHERE clause. It has currently been running for close to 2 hours, on 500 000 record. Awful.



Any insight or hints as to what is affecting the performance on this will be greatly appreciated.









share



























    0















    Consider the following query:



     mysql> SELECT GROUP_CONCAT(a.id SEPARATOR 'n')
    -> FROM assignment a
    -> INNER JOIN statements s ON a.id = s.assignment_id
    -> INNER JOIN assignment_status_log asl ON a.status_log_id = asl.id
    -> INNER JOIN assignment_status ags ON asl.status_id = ags.id
    -> WHERE ags.category <> 'PASSED'
    -> AND ags.category <> 'TEST'
    -> AND ags.category <> 'REJECTED'
    -> AND ags.category <> 'CANCELED'
    -> AND ags.category <> 'NA'
    -> AND s.id IS NOT NULL
    -> AND s.id IN (SELECT MAX(sts.id) AS dctrn__1 FROM assignment agr INNER JOIN statements sts ON agr.id = sts.assignment_id WHERE agr.id = a.id)
    -> AND s.grade > 0
    -> AND ags.types <> 'CB'
    -> AND ags.types <> 'CD'
    -> AND ags.types <> 'CE'
    -> AND ags.types <> 'CF'
    -> GROUP BY a.id;


    I would like to have an idea as to how I can troubleshoot what is taking so long. I have added index on s.grades and ags.types column, and am pondering if I would need to try to have the conditions on the JOIN instead of in WHERE clause. It has currently been running for close to 2 hours, on 500 000 record. Awful.



    Any insight or hints as to what is affecting the performance on this will be greatly appreciated.









    share

























      0












      0








      0








      Consider the following query:



       mysql> SELECT GROUP_CONCAT(a.id SEPARATOR 'n')
      -> FROM assignment a
      -> INNER JOIN statements s ON a.id = s.assignment_id
      -> INNER JOIN assignment_status_log asl ON a.status_log_id = asl.id
      -> INNER JOIN assignment_status ags ON asl.status_id = ags.id
      -> WHERE ags.category <> 'PASSED'
      -> AND ags.category <> 'TEST'
      -> AND ags.category <> 'REJECTED'
      -> AND ags.category <> 'CANCELED'
      -> AND ags.category <> 'NA'
      -> AND s.id IS NOT NULL
      -> AND s.id IN (SELECT MAX(sts.id) AS dctrn__1 FROM assignment agr INNER JOIN statements sts ON agr.id = sts.assignment_id WHERE agr.id = a.id)
      -> AND s.grade > 0
      -> AND ags.types <> 'CB'
      -> AND ags.types <> 'CD'
      -> AND ags.types <> 'CE'
      -> AND ags.types <> 'CF'
      -> GROUP BY a.id;


      I would like to have an idea as to how I can troubleshoot what is taking so long. I have added index on s.grades and ags.types column, and am pondering if I would need to try to have the conditions on the JOIN instead of in WHERE clause. It has currently been running for close to 2 hours, on 500 000 record. Awful.



      Any insight or hints as to what is affecting the performance on this will be greatly appreciated.









      share














      Consider the following query:



       mysql> SELECT GROUP_CONCAT(a.id SEPARATOR 'n')
      -> FROM assignment a
      -> INNER JOIN statements s ON a.id = s.assignment_id
      -> INNER JOIN assignment_status_log asl ON a.status_log_id = asl.id
      -> INNER JOIN assignment_status ags ON asl.status_id = ags.id
      -> WHERE ags.category <> 'PASSED'
      -> AND ags.category <> 'TEST'
      -> AND ags.category <> 'REJECTED'
      -> AND ags.category <> 'CANCELED'
      -> AND ags.category <> 'NA'
      -> AND s.id IS NOT NULL
      -> AND s.id IN (SELECT MAX(sts.id) AS dctrn__1 FROM assignment agr INNER JOIN statements sts ON agr.id = sts.assignment_id WHERE agr.id = a.id)
      -> AND s.grade > 0
      -> AND ags.types <> 'CB'
      -> AND ags.types <> 'CD'
      -> AND ags.types <> 'CE'
      -> AND ags.types <> 'CF'
      -> GROUP BY a.id;


      I would like to have an idea as to how I can troubleshoot what is taking so long. I have added index on s.grades and ags.types column, and am pondering if I would need to try to have the conditions on the JOIN instead of in WHERE clause. It has currently been running for close to 2 hours, on 500 000 record. Awful.



      Any insight or hints as to what is affecting the performance on this will be greatly appreciated.







      query-performance optimization mysql-5.7





      share












      share










      share



      share










      asked 4 mins ago









      stefgosselinstefgosselin

      1104




      1104






















          0






          active

          oldest

          votes











          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%2f231972%2foptimise-multiple-inner-join%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 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%2f231972%2foptimise-multiple-inner-join%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

          ORA-01691 (unable to extend lob segment) even though my tablespace has AUTOEXTEND onORA-01692: unable to...

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

          Circunscripción electoral de Guipúzcoa Referencias Menú de navegaciónLas claves del sistema electoral en...