Select too many ids..

Started by Abandonedover 18 years ago4 messagesgeneral
Jump to latest
#1Abandoned
besturk@gmail.com

Hi..
I have a id list and id list have 2 million dinamic elements..
I want to select what id have point..
I try:

SELECT id, point FROM table WHERE id in (IDLIST)

This is working but too slowly and i need to performance..

I'm sorry my bad english.
King regards..

#2Scott Marlowe
scott.marlowe@gmail.com
In reply to: Abandoned (#1)
Re: Select too many ids..

On 10/1/07, Abandoned <besturk@gmail.com> wrote:

Hi..
I have a id list and id list have 2 million dinamic elements..
I want to select what id have point..
I try:

SELECT id, point FROM table WHERE id in (IDLIST)

This is working but too slowly and i need to performance..

I'm sorry my bad english.
King regards..

Try adding another bit of where clause:

SELECT id, point FROM table WHERE id in (IDLIST) and point is not null

it may be faster with a partial index " on table(id) where point is
null " or something like that.

What does explain / explain analyze say about the query?

#3Rodrigo De León
rdeleonp@gmail.com
In reply to: Abandoned (#1)
Re: Select too many ids..

On 10/1/07, Abandoned <besturk@gmail.com> wrote:

Hi..
I have a id list and id list have 2 million dinamic elements..
I want to select what id have point..
I try:

SELECT id, point FROM table WHERE id in (IDLIST)

This is working but too slowly and i need to performance..

I'm sorry my bad english.
King regards..

DDL please...

#4Alban Hertroys
a.hertroys@magproductions.nl
In reply to: Rodrigo De León (#3)
Re: Select too many ids..

Rodrigo De León wrote:

On 10/1/07, Abandoned <besturk@gmail.com> wrote:

Hi..
I have a id list and id list have 2 million dinamic elements..
I want to select what id have point..
I try:

SELECT id, point FROM table WHERE id in (IDLIST)

This is working but too slowly and i need to performance..

I'm sorry my bad english.
King regards..

DDL please...

I guess the OP's problem is with the time it takes to push a query
containing 2 million ID's through the SQL parser.

A few things that may help:

- See if you can find any uninterrupted ranges of values in your ID's
and combine them into separate where clauses (ie. where id between x and
y). This won't help you much for ranges where y = x+1, but it does help
if (for example) y = x+10...

- Try if it helps COPY-ing your ID's into a temp table and join your
table with that instead of using a huge IN list.

- If you're still using PG 7.4, try a PG 8. There have been significant
performance improvements with IN lists in queries in the 8-series.

Regards,

--
Alban Hertroys
a.hertroys@magproductions.nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
7500 AK Enschede

// Integrate Your World //