2010-10-14 5 views
1

J'ai une tâche pour optimiser cette requête, toute idée sera appréciée.Besoin d'optimiser cette requête

SELECT DISTINCT `br`.`id` AS `branch_id` 
     , `br`.`store_id` 
     , `br`.`longitude` 
     , `br`.`latitude` 
     , `br`.`town_id` 
     , `br`.`post_region` 
     , `cb`.`cat0_id` 
     , `cb`.`cat1_id` 
     , `cb`.`cat2_id` 
     , `plan`.`listing_plan_id` 
     , `cat0`.`cat_topid` 
     , `cg`.`tarrif` 
FROM `mvcl_local_new`.`branch` AS `br` 
     INNER JOIN `mvcl_local_new`.`voucher_branch` AS `vb` ON br.id = vb.branch_id 
     INNER JOIN `mvcl_local_new`.`voucher` AS `v` ON v.id = vb.voucher_id 
     INNER JOIN `category_voucher` AS `cb` ON cb.voucher_id = v.id 
     INNER JOIN `category_voucher_listing_plans` AS `plan` ON plan.voucher_id = v.id 
     INNER JOIN `category_level0` AS `cat0` ON cb.cat0_id = cat0.id 
     LEFT JOIN `category_tariffs` AS `cg` ON cg.voucher_id = v.id 
WHERE (
     br.latitude != 0 
     and br.longitude != 0 
     and br.post_region <> '' 
     and valid_from < 1286876423 
     and expires > 1286876423 
     and 
     (
      (
       plan.listing_plan_id IN (1,2,3) 
       and cg.town_id = br.town_id 
       and cg.is_active = 1 
       and cg.status_code='Active' 
       and cg.tarrif_id=0 
      ) 
      or plan.listing_plan_id=4 
     ) 
    ); 
+0

Comment avez-vous indenté cette requête? –

+1

Il n'y a pas grand chose à optimiser en plus de l'indexation correcte. Pour obtenir des conseils à ce sujet, vous devez publier le plan d'exécution. –

+0

À l'aide d'onglets et d'espaces? Si vous ne le voyez pas comme une amélioration, vous pouvez toujours revenir à votre version précédente. –

Répondre

2

Pour les requêtes d'optimisation, il est très pratique d'utiliser MySQL Profiler dans dbForge Studio For MySQL.