speeding up INTERSECT/EXCEPT

From: Carl Hauser <chauser(at)parc(dot)xerox(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: chauser(at)parc(dot)xerox(dot)com
Subject: speeding up INTERSECT/EXCEPT
Date: 1999-07-25 13:56:18
Message-ID: 99Jul25.135623pdt."336180"@hornet.parc.xerox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I've searched the archives and docs without finding any help on this.

I want to use:

select * from rel1 except select * from rel2;

where rel1 and and rel2 each currently have about 2000 records and are likely to grow to twice that size or more.

The query works but takes inordinately long. Looking at the query plan, it seems that the statement is being executed using a nested scan, so the query is taking time proportional to the product of the sizes of the two relations. The result set will usually be a few hundred records.

My question: are there any indices I could define on the relations that would speed up the query? Since noting the problem, I've added an index on one of the fields (the same for both relations). Another index covers 7 of the fields in both relations (7 because that is the maximum for an index). Creating these indices made no difference in the query plan nor in the execution time of the query.

Should I pursue this approach further or do the differencing outside of the database?

-- Carl Hauser
-- Xerox Palo Alto Research Center

Browse pgsql-general by date

  From Date Subject
Next Message Mike Mascari 1999-07-25 15:27:32 Re: [GENERAL] Installation of postgresql-6.5.1 data missing ?
Previous Message Herouth Maoz 1999-07-25 13:45:31 Re: [GENERAL] Installation of postgresql-6.5.1 data missing ?