Ben temelde spor var kullanıcıları bulmak için buraya çalışıyorum & am Bir etkinlik tarafından hedef bölgelerde. Acces [kullanıcı] masanın etrafında 17K kullanıcıları var. Her spor ilgi ve bir bölgenin belli bir sayıda olabilir.
Bir spor ve sahip olduğunuz her kullanıcılar için bakmak Orada burada sorgulamak faaliyetleri ile hedeflenen en az bir bölge. Biz [bir IN sorgu ile oldukça iyi değil] em her seçtiğinizde Sports kadar 75 olabilir.
SELECT a.user, pp.courriel
FROM acces a
LEFT JOIN acces_profil_sport ap ON ap.id = a.id
LEFT JOIN profil_perso pp ON pp.id = a.id
WHERE ap.sport_id IN
(
SELECT ac.sport_id
FROM activite_sport ac
RIGHT JOIN activite a ON a.activite_id = ac.activite_id AND a.is_cron = 1 AND a.cron_processed = 0
)
AND pp.region_id IN
(
SELECT ar.region_id
FROM activite_region ar
RIGHT JOIN activite a ON a.activite_id = ar.activite_id AND a.is_cron = 1 AND a.cron_processed = 0
)
GROUP BY a.id
Ben spor arama kaldırırsanız, sorgu çalıştırmak için arounds 30 saniye sürer. Aksi takdirde oldukça sonsuza kadar sürer ve mysql ile proc yaklaşık% 99 kullanabilirsiniz.
Bu yardım Herhangi bir ipucu?
[edit : Table structure]
Acces : id (primary key), user, perso_id (Key/Foreign key to profil_perso[perso_id]) [some-other-fields]
profil_perso : perso_id (primary key) courriel, region_id, id (foreign key to acces[id]) [some other fields]
acces_profil_sport : id/sport_id (dual primary key), niveau_id (dual key with sport_id)