Multiple queries OR one and big

From: Alex Dovlecel <dovle(at)kbs(dot)twi(dot)tudelft(dot)nl>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Multiple queries OR one and big
Date: 2002-12-02 16:46:27
Message-ID: E18ItiF-0002aB-00@ford.kbs.twi.tudelft.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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

Browse pgsql-jdbc by date

  From Date Subject
Next Message David Hooker 2002-12-02 16:51:57 Updatable result sets
Previous Message Rasputin 2002-12-02 16:21:34 Re: md5 passwords in 7.2.3 ?