![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I am looking for certain users that are connected via some other values. TABLE_A A_ID, type, ... (~124K rows) TABLE_B B_ID, A_ID, C_ID, ... (~400K rows) TABLE_C C_ID, D_ID, ... (~250K rows) TABLE_D D_ID, E_ID, ... (~110K rows) TABLE_E E_ID, deleted ... (~110K rows) The query below should return less than 300 rows, (212 to be exact). SELECT TABLE_E.* FROM TABLE_A, TABLE_B, TABLE_C, TABLE_D, TABLE_E WHERE TABLE_A.type IN (2,5,7) AND TABLE_B.A_ID = TABLE_A.A_ID AND TABLE_C.C_id = TABLE_B.C_ID AND TABLE_D.D_id = TABLE_C.D_ID AND TABLE_E.E_id = TABLE_D.E_ID AND TABLE_E.deleted=1 In TABLE_A, there are only ~10 'types' available. When I do an 'EXPLAIN', all the primary keys are used, (A_ID, B_ID, C_ID, E_ID are all unique in their own tables). The query is so slow that it takes about 60 minutes to run on the server, on the dev environment, (with a full copy of the db), the query is better, but it still takes 15 minutes, (I am guessing it is purely because there is less load on the dev server). I have tried SELECT TABLE_C.* FROM TABLE_A, TABLE_B, TABLE_C, TABLE_D, TABLE_E WHERE TABLE_A.type =2 AND TABLE_B.A_ID = TABLE_A.A_ID AND TABLE_C.C_id = TABLE_B.C_ID AND TABLE_D.D_id = TABLE_C.D_ID AND TABLE_E.E_id = TABLE_D.E_ID AND TABLE_E.deleted=1 Without any real success. Any suggestions on what I could do or how I could optimise the query? Any tool I could use that might help me find what/where the bottleneck might be? |
|
Many thanks Simon |
#3
| |||
| |||
|
|
Hi, I am looking for certain users that are connected via some other values. TABLE_A A_ID, type, ... (~124K rows) TABLE_B B_ID, A_ID, C_ID, ... (~400K rows) TABLE_C C_ID, D_ID, ... (~250K rows) TABLE_D D_ID, E_ID, ... (~110K rows) TABLE_E E_ID, deleted ... (~110K rows) The query below should return less than 300 rows, (212 to be exact). SELECT TABLE_E.* FROM TABLE_A, TABLE_B, TABLE_C, TABLE_D, TABLE_E WHERE TABLE_A.type IN (2,5,7) AND TABLE_B.A_ID = TABLE_A.A_ID AND TABLE_C.C_id = TABLE_B.C_ID AND TABLE_D.D_id = TABLE_C.D_ID AND TABLE_E.E_id = TABLE_D.E_ID AND TABLE_E.deleted=1 In TABLE_A, there are only ~10 'types' available. |
#4
| |||
| |||
|
|
Any suggestions on what I could do or how I could optimise the query? Any tool I could use that might help me find what/where the bottleneck might be? Many thanks |
#5
| |||
| |||
|
|
TABLE_A A_ID, type, ... (~124K rows) TABLE_B B_ID, A_ID, C_ID, ... (~400K rows) TABLE_C C_ID, D_ID, ... (~250K rows) TABLE_D D_ID, E_ID, ... (~110K rows) TABLE_E E_ID, deleted ... (~110K rows) The query below should return less than 300 rows, (212 to be exact). SELECT TABLE_E.* FROM TABLE_A, TABLE_B, TABLE_C, TABLE_D, TABLE_E WHERE TABLE_A.type IN (2,5,7) AND TABLE_B.A_ID = TABLE_A.A_ID AND TABLE_C.C_id = TABLE_B.C_ID AND TABLE_D.D_id = TABLE_C.D_ID AND TABLE_E.E_id = TABLE_D.E_ID AND TABLE_E.deleted=1 In TABLE_A, there are only ~10 'types' available. When I do an 'EXPLAIN', all the primary keys are used, (A_ID, B_ID, C_ID, E_ID are all unique in their own tables). The query is so slow that it takes about 60 minutes to run |
|
Any suggestions on what I could do or how I could optimise the query? Any tool I could use that might help me find what/where the bottleneck might be? |
#6
| |||
| |||
|
|
Any suggestions on what I could do or how I could optimise the query? Any tool I could use that might help me find what/where the bottleneck might be? Many thanks Thanks for the replies. I added indexes without much success. I will try with some code, (get ids from one query, then loop around and get the ids from another query and so forth). The other issue is that the data is cached. So I never really know if the query is cached or if I was really able to optimise it somehow. Simon |
![]() |
| Thread Tools | |
| Display Modes | |
| |