Skip site navigation (1) Skip section navigation (2)

Re: tricky query

From: Sebastian Hennebrueder <usenet(at)laliluna(dot)de>
To:
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: tricky query
Date: 2005-06-28 20:38:54
Message-ID: 42C1B55E.40405@laliluna.de (view raw or flat)
Thread:
Lists: pgsql-performance
John A Meinel schrieb:

> John A Meinel wrote:
>
>>
>
> Well, I was able to improve it to using appropriate index scans.
> Here is the query:
>
> SELECT t1.id+1 as id_new FROM id_test t1
>    WHERE NOT EXISTS
>        (SELECT t2.id FROM id_test t2 WHERE t2.id = t1.id+1)
>    ORDER BY t1.id LIMIT 1;
>
> I created a test table which has 90k randomly inserted rows. And this is
> what EXPLAIN ANALYZE says:
>
>        


As Cosimo stated the result can be wrong. The result is always wrong
when the id with value 1 does not exist.

-- 
Best Regards / Viele Grüße

Sebastian Hennebrueder

----

http://www.laliluna.de

Tutorials for JSP, JavaServer Faces, Struts, Hibernate and EJB 

Get support, education and consulting for these technologies - uncomplicated and cheap.


In response to

pgsql-performance by date

Next:From: Billy extyeightysixDate: 2005-06-28 20:39:05
Subject: optimized counting of web statistics
Previous:From: Merlin MoncureDate: 2005-06-28 19:45:53
Subject: Re: tricky query

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group