performance - optimizing particular query mysql -


So I'm searching to read a solution and books, and it has been able to understand, the question is I have 2 tables on a table, I have 2 fields:

table_1: Both "chromosome" and "position" are integers

table_2: "chromosome" Start "and" end ", all being integers as well

I want a query that gives me all the rows back from table_1, which will come from Table 2 Nb and finally appeared between I query this way is:

  SELECT table_1 * from Talika_l, Talika_2 WHERE table_1.chromosome = table_2.chromosome and table_1.position & gt; Table_2. Start and Table_1. Status & lt; Table_1.end; So this query works fine, but my table has many millions of rows (7092713) and (21599) respected I have indexed chromosome, position and chromosome, start and end. The weird part is that if I query one after another (Pearl DBI, make a statement for every line of table 2), it runs very fast It is not certain where I am skidding appreciated any help Will go.  

George Kajiyama

For clarity, let's use the standard Join syntax Start by restarting your query. Query is similar but easy to read

  SELECT table_1 * Join Table 1 at Table 2 (Table_1.Chromosom = Table_2.Chromosomes and Table_1.position & gt; Table_2.start and Table_1.postion   

The second is smart when searching, to avoid * in your SELECT sections (or something for that matter) Table) using the * to optimize the result of useful data about what you are doing or not, your results Need in the set. Then tell us

  SELECT table_1.chromosome, table_1.position   

for SELECT.

Therefore, it becomes clear that your result is set, and you need a large number of chromosome and position, and nothing, from your large table

   

By using tablewise (chromosome, position), try to make one, depending on the table, the index is as follows.

  Create on table 2 (chromosome, start, end) use of beetry   

They are called cover indexes . There are enough columns in it, which can be satisfied with the index without bouncing back to the original table.

BTREE indexes (default from the way) are ordered naturally. On the index that starts with the appropriate record (chromosome, start) in table_1 , the range can end with a scan and (chromosome, end).

Third, it is possible that you are exploding a large combination of rows from the table_1 in your result set. You will find a line for each combination of rows in two tables that match your ON () section

  select DISTINCT table_1.chromosome By using table_1, you can try to reduce that composite explosion. Status   

Give it a try If you are still not found anywhere, then there may be another question with the complete table definitions and the explanation The results will be helpful.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -