Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL beginner - Why does my MySQL Join-query use no index / work so slow?
    primarykey
    data
    text
    <p>I got the following problem with my MySQL 5.5 DB - i am pretty new to this so it might be very obvious whats wrong but i just cant seem to get it:</p> <p>Two tables:</p> <hr> <p>Table1</p> <pre><code>CREATE TABLE `sequence_matches` ( `Sample_ID` INT(6) NOT NULL, `Sequence_Match_ID` INT(8) NOT NULL, `Start` INT(6) NULL DEFAULT NULL, `End` INT(6) NULL DEFAULT NULL, `Coverage` DOUBLE(5,2) NULL DEFAULT NULL, `Frag_String` VARCHAR(255) NULL DEFAULT NULL, `rms_mass_error_prod` DOUBLE(10,4) NULL DEFAULT NULL, `rms_rt_error_prod` DOUBLE(10,4) NULL DEFAULT NULL, PRIMARY KEY (`Sample_ID`, `Sequence_Match_ID`) ) </code></pre> <hr> <p>and </p> <hr> <p>Table 2</p> <pre><code>CREATE TABLE `peptide_identifications` ( `Sample_ID` INT(6) NOT NULL, `Peptide_identification_ID` INT(8) NOT NULL, `Mass_error` DOUBLE(10,4) NULL DEFAULT NULL, `Mass_error_ppm` DOUBLE(10,4) NULL DEFAULT NULL, `Score` DOUBLE(10,4) NULL DEFAULT NULL, `Type` VARCHAR(45) NULL DEFAULT NULL, `global_pept_ID` INT(8) NOT NULL, PRIMARY KEY (`Sample_ID`, `Peptide_identification_ID`), INDEX `Index` (`global_pept_ID`) ) </code></pre> <hr> <p>each of them contains ~15 million rows. </p> <p>Now, i want all those rows from <code>Table2</code> where <code>global_pept_id = 27443</code> and then use the <code>peptide_identification_id</code> of those, to query all information from <code>Table1</code> where <code>peptide_identification_id = sequence_match_id</code>.</p> <p>I tried the following statement:</p> <pre><code>SELECT * from sequence_matches JOIN ( SELECT peptide_identification_id FROM peptide_identifications WHERE global_pept_id = 27443 ) as tmp_pept ON sequence_match_id = peptide_identification_id; </code></pre> <p>Here the Explain for that query:</p> <p><a href="https://i.stack.imgur.com/QV3ER.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QV3ERm.jpg" alt="http://i.stack.imgur.com/QV3ER.jpg"></a> (click to enlarge)</p> <p>Now this query is very, very slow (i actually never finished it, stopepd it after ~10min) and i can imagine it's because there is no Index used for the second table although both ID's are primary key and thus they should be indexed right?</p> <p>The results for the inner select require ~3 sek and return ~3k rows if performed alone. So the i think the problem is making 3000 * 15mio compares cause every row is checked in Table2.</p> <p>But how do i fix this?</p> <p>any help appreciated -voiD</p>
    singulars
    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.
 

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