Huge query help

From: Cath Lawrence <Cath(dot)Lawrence(at)anu(dot)edu(dot)au>
To: pgsql-novice(at)postgresql(dot)org
Subject: Huge query help
Date: 2004-02-29 23:36:19
Message-ID: 1390DF24-6B10-11D8-98CA-000A95DC17CC@anu.edu.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi,

I have a big table (10 million records, each quite small - half a dozen
text and numeric fields) which I need to (eek!) outer join with itself,
but in such a way as to actually rule out 99.9% of the table.

I need tips on how to do this without crashing and running out of
memory - how do I make it for the "where" condition before attempting
the join?

Here's a stripped down version of the query:

SELECT a1.x as x1, a1.y as y1, a1.z as z1,
a2.x as x2, a2.y as y2, a2.z as z2,
r1.position as rpos1, r1.residue as res1,
r2.position as rpos2, r2.residue as res2
FROM atom a1, atom a2, residue r1, residue r2
WHERE a1.pdb_id = a2.pdb_id
AND a1.pdb_id = '1ABC'
AND a1.res_id < a2.res_id
AND a1.res_id = r1.id
AND a2.res_id = r2.id

Basically, the restriction on pdb_id reduces it to about 1 in 7000 of
the table entries, so the result will be big but not unmanageable, if I
can ever get it...

Can I organise my query somehow so the join is done on the subsets
rather than the full table?

And while I'm at it, does anyone have advice on materials for learning
advanced SQLtechniques? Everything I find on the web is basically
beginner stuff and assumes that you have a tiny dataset...

cheers
Cath
Cath Lawrence, Cath(dot)Lawrence(at)anu(dot)edu(dot)au
Senior Scientific Programmer, Centre for Bioinformation Science,
John Curtin School of Medical Research (room 4088)
Australian National University, Canberra ACT 0200
ph: (02) 61257959 mobile: 0421-902694 fax: (02) 61252595

Browse pgsql-novice by date

  From Date Subject
Next Message Stephan Szabo 2004-03-01 00:43:05 Re: Help! "alter table add column" hangs
Previous Message kynn 2004-02-29 22:07:54 Help! "alter table add column" hangs