Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Does placement of join matter?</p> </blockquote> <p>The order they are written does not matter for INNER JOINs.</p> <blockquote> <p>Does order of where clause matter, or will MySQL optimize?</p> </blockquote> <p>No. The written order in a WHERE clause does not matter to the MySQL query parser and optimizer</p> <blockquote> <p>Would and index help in my case?</p> </blockquote> <p>Potentially. A compound index type_status (Type, Status) on table1 could help since that is where your WHERE clause could reduce the initial rows read.</p> <blockquote> <p>Is there any advantage JOINing in the FROM, vs adding 'table1.CurrentName = table2.id' in the WHERE clause?</p> </blockquote> <p>For INNER JOINs, it doesn't matter if the JOIN condition is in the FROM clause or the WHERE clause.</p> <blockquote> <p>I thought adding an index to table1.CurrentName may help, but now I'm thinking not. I modified the query to remove references to table2, and it still ran slow. (see 3b)</p> </blockquote> <p>An index on table1.CurrentName would not help the query.</p> <blockquote> <p>Seems like the bulk of the slowdown may be just reading 800K records looking at the Type and Status values.</p> </blockquote> <p>This reinforces my thought above. To add the compound index (potentially not a good thing to do online), it'd be something like</p> <pre><code>ALTER TABLE table1 ADD INDEX type_status (Type, Status); </code></pre> <blockquote> <p>I thought it only made sense when there were more unique values.</p> </blockquote> <p>Selectivity definitely helps, but high cardinality is not the only suitable context.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload