Mysql Nested Subqueries Problem » History » Version 4
Amber Herold, 03/04/2010 01:38 PM
1 | 1 | Amber Herold | h1. Mysql Nested Subqueries Problem |
---|---|---|---|
2 | |||
3 | 3 | Amber Herold | This is the query that I wanted to do because it is easy to understand (= easier to maintain). |
4 | Unfortunatly there is a bug in mysql (http://bugs.mysql.com/bug.php?id=10312) which makes this |
||
5 | so slow that no one has seen it complete. The subsequent query is a bit more difficult to follow |
||
6 | but gets around this problem. |
||
7 | 1 | Amber Herold | |
8 | 4 | Amber Herold | <pre> |
9 | 3 | Amber Herold | SELECT ".DB_PROJECT.".projectexperiments.projectId |
10 | FROM ".DB_PROJECT.".projectexperiments |
||
11 | WHERE ".DB_PROJECT.".projectexperiments.name IN |
||
12 | ( |
||
13 | SELECT ".DB_LEGINON.".SessionData.name |
||
14 | FROM ".DB_LEGINON.".SessionData |
||
15 | WHERE ".DB_LEGINON.".SessionData.`DEF_id` IN |
||
16 | ( |
||
17 | SELECT ".DB_PROJECT.".shareexperiments.`REF|leginondata|SessionData|experiment` |
||
18 | FROM ".DB_PROJECT.".shareexperiments |
||
19 | WHERE ".DB_PROJECT.".shareexperiments.`REF|leginondata|UserData|user` = ".$userId." |
||
20 | ) |
||
21 | ); |
||
22 | 4 | Amber Herold | </pre> |
23 | 1 | Amber Herold | |
24 | 4 | Amber Herold | <pre> |
25 | 3 | Amber Herold | SELECT amberproject.projectexperiments.projectId |
26 | FROM amberproject.projectexperiments |
||
27 | INNER JOIN |
||
28 | ( |
||
29 | SELECT amberdbemdata.SessionData.name AS SessionName |
||
30 | FROM amberdbemdata.SessionData |
||
31 | INNER JOIN |
||
32 | ( |
||
33 | SELECT amberproject.shareexperiments.`REF|leginondata|SessionData|experiment` AS SessionId |
||
34 | FROM amberproject.shareexperiments |
||
35 | WHERE amberproject.shareexperiments.`REF|leginondata|UserData|user` = ".$userId." |
||
36 | ) AS SessionIds |
||
37 | ON amberdbemdata.SessionData.`DEF_id` = SessionIds.SessionId |
||
38 | 1 | Amber Herold | ) AS SessionNames |
39 | 4 | Amber Herold | ON amberproject.projectexperiments.name = SessionNames.SessionName; |
40 | </pre> |
||
41 | 1 | Amber Herold | |
42 | |||
43 | 2 | Amber Herold | See another example "here":http://forums.mysql.com/read.php?24,54721,54721#msg-54721. |