Re: Very long "or" where clause

From: Richard Huxton <dev(at)archonet(dot)com>
To: Scara Maccai <m_lists(at)yahoo(dot)it>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Very long "or" where clause
Date: 2007-01-16 09:26:38
Message-ID: 45AC9A4E.2000507@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Scara Maccai wrote:
> Hi,
> from a table with 100,000,000 rows I have to sum some records using a
> query like:
>
> select sum(field1) from mytab where
> (time = 1 and id = 3)
> or
> (time = 3 and id = 1)
> or
> (time = 2 and id = 5)
>
> The "or clauses" can be even 10,000,000...
> Which would be the best method to access data? Should I use a procedure
> on the server side?

Put the test-values into a temporary table, analyse it and then join
against it. Can't say about indexes without knowing more about your
usage pattern.

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scara Maccai 2007-01-16 09:50:09 Re: Very long "or" where clause
Previous Message Florian Weimer 2007-01-16 09:25:55 Re: Very long "or" where clause