Multiple queries OR one and big

Поиск
Список
Период
Сортировка
Искать

Multiple queries OR one and big

От:
Alex Dovlecel <dovle@kbs.twi.tudelft.nl>
Дата:
Hello all, 

This is a little bit out of topic but is related to jdbc. 

I have a database containing three tables : Route, RouteItem and 
RouteItemStop (Route : 1 -- n RouteItems 1 -- n RouteItemStops ). Hope you 
see the picture. :o) 

I want to obtain a route with a specific ID. I have two ways of implementing 
it: 
1) one big sql join statement that links all those 3 tables. The problem will 
be the huge ammount of data (like all the Route data will be repeated for n^2 
times , the same data). The advantage: only one query. 

2) join by route and routeitem and then get all the routeItemStops for each 
route item. This means n+1 queries. Advantage : don't have all that ammount 
of inutile data sent from sql server. Disadvantage: n+1 sql statements to be 
executed, instead of only one. 

Is there any 'better' solution. If not, what should I choose? (don't have the 
experience and I don't know how psql sends a join query: optimised, not 
optimised)... 

For now join is just Where route.id = route_item.route_id. 

If I am going to use the JOIN sql command, will that be faster and better? 
Why ? 

Tx 
dovle 
FAQ