Re: tricky query - Mailing list pgsql-performance

From Merlin Moncure
Subject Re: tricky query
Date
Msg-id 6EE64EF3AB31D5448D0007DD34EEB3415C2BF8@Herge.rcsinc.local
Whole thread Raw
In response to tricky query  ("Merlin Moncure" <merlin.moncure@rcsonline.com>)
List pgsql-performance
> Not so bad. Try something like this:
>
> SELECT min(id+1) as id_new FROM table
>     WHERE (id+1) NOT IN (SELECT id FROM table);
>
> Now, this requires probably a sequential scan, but I'm not sure how
you
> can get around that.
> Maybe if you got trickier and did some ordering and limits. The above
> seems to give the right answer, though.

it does, but it is still faster than generate_series(), which requires
both a seqscan and a materialization of the function.

> I don't know how big you want to scale to.

big. :)

merlin

pgsql-performance by date:

Previous
From: John A Meinel
Date:
Subject: Re: tricky query
Next
From: "Merlin Moncure"
Date:
Subject: Re: tricky query