Ver Mensaje Individual
  #2 (permalink)  
Antiguo 14/02/2014, 04:09
quimfv
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 8 meses
Puntos: 574
Respuesta: Performance queries con múltiples JOIN.

Código MySQL:
Ver original
  1. SELECT auctions_flight.id,
  2.     auctions_flight.`date`,
  3.     origins.code as origin_code,
  4.     origins.name as origin,
  5.     destinations.name as destination,
  6.     destinations.code as destination_code,
  7.     auctions_flight.num_seating,
  8.     auctions_flightprice.Price,
  9.     auctions_flightprice.currency
  10. FROM auctions_flight
  11.         INNER JOIN
  12.     auctions_flightprice ON auctions_flight.price_id = auctions_flightprice.id
  13.         INNER JOIN
  14.     locations_location as destinations ON auctions_flight.destination_location_id = destinations.id
  15.         INNER JOIN
  16.     locations_location as origins ON auctions_flight.origin_location_id = origins.id
  17.         INNER JOIN
  18.     (SELECT origin_location_id,
  19.                 destination_location_id,
  20.                 `date`,
  21.                 MIN(Price) MPrice
  22.         FROM auctions_flightprice
  23.         GROUP BY origin_location_id,
  24.                 destination_location_id,
  25.                 `date`
  26.     ) Sbc
  27.         ON auctions_flightprice.Price =Sbc.MPrice
  28.             AND Sbc.origin_location_id = auctions_flight.origin_location_id
  29.             AND Sbc.destination_location_id = auctions_flight.destination_location_id
  30.             AND Sbc.`date` = auctions_flight.`date`
  31. WHERE auctions_flight.num_seating >= 3
  32.     AND origins.code = 'MEX'
  33.     AND auctions_flightprice.currency = 'MXN'
  34. ORDER BY auctions_flightprice.`Price`
  35. LIMIT 25;

Esto correra mas y creo que debe dar lo mismo....

(Creo)
__________________
Quim
--------------------------------------------------
Ayudar a ayudar es una buena práctica!!! Y da buenos resultados.