Received: from sss.pgh.pa.us (sss.pgh.pa.us [209.114.132.154]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f08JCQB26018 for ; Mon, 8 Jan 2001 14:12:26 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.1/8.11.1) with ESMTP id f08JCHJ18770; Mon, 8 Jan 2001 14:12:17 -0500 (EST) To: Jens Hartwig cc: PostgreSQL SQL Subject: Re: Strange Execution-Plan for NOT EXISTS In-reply-to: <3A4B1C06.2A5C6C94@debis.com> References: <3A4B1C06.2A5C6C94@debis.com> Comments: In-reply-to Jens Hartwig message dated "Thu, 28 Dec 2000 11:55:02 +0100" Date: Mon, 08 Jan 2001 14:12:17 -0500 Message-ID: <18767.978981137@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200101/77 X-Sequence-Number: 738 Jens Hartwig writes: > select (min(id) + 1) > from t_dummy d1 > where not exists ( > select id > from t_dummy d2 > where d2.id = (d1.id + 1) > ); > Aggregate (cost=2924207.88..2924207.88 rows=1 width=12) -> Seq Scan on t_dummy d1 (cost=0.00..2924207.88 rows=1 width=12) > SubPlan > -> Seq Scan on t_dummy d2 (cost=0.00..331.36 rows=1 width=12) > Why that? Wouldn´t it be possible to simple use the primary key index in > the sub-query I think that 7.0.* is too stupid to consider an indexscan for a qualifier that looks like "indexvar = ($1 + 1)", which is what you effectively have in this case ($1 being the Param passed in from the outer plan). It only recognizes "indexvar = constant" and "indexvar = param" as indexable expressions. Current sources do better. regards, tom lane