X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 052D0D1D851 for ; Fri, 13 Feb 2004 15:49:58 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 27537-09 for ; Fri, 13 Feb 2004 11:49:59 -0400 (AST) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id F147ED1D84E for ; Fri, 13 Feb 2004 11:49:54 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id B578935755; Fri, 13 Feb 2004 07:49:59 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id B3CC035749; Fri, 13 Feb 2004 07:49:59 -0800 (PST) Date: Fri, 13 Feb 2004 07:49:59 -0800 (PST) From: Stephan Szabo To: Tom Lane Cc: Rod Taylor , ow , pgsql-sql@postgresql.org Subject: Re: 7.4 - FK constraint performance In-Reply-To: <2455.1076686047@sss.pgh.pa.us> Message-ID: <20040213073852.K20792@megazone.bigpanda.com> References: <20040213010341.95282.qmail@web60801.mail.yahoo.com> <25808.1076634636@sss.pgh.pa.us> <1076640825.10896.12.camel@jester> <27443.1076646336@sss.pgh.pa.us> <20040213065530.M19832@megazone.bigpanda.com> <2455.1076686047@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/150 X-Sequence-Number: 16841 On Fri, 13 Feb 2004, Tom Lane wrote: > Stephan Szabo writes: > > One thing is that IIRC we're going to ask for only one row when we do the > > SPI_execp_current. However, unless I misremember, the behavior of for > > update and limit means that saying limit 1 is potentially unsafe (if you > > block on a row that goes away). Is there anyway for us to let the planner > > know this? > > I was looking at that last night. It seems like we could add a LIMIT at > least in some contexts. In the case at hand, we're just going to error > out immediately if we find a matching row, and so there's no need for > FOR UPDATE, is there? I think there still is, because a not yet committed transaction could have deleted them all in which case I think the correct behavior is to wait and if that transaction commits allow the action and if it rolls back to error. Really we'd want a different behavior where we're only blocking in these cases if all the matching rows are locked by other transactions. > However, I'm not sure it would help the OP anyway. With the stats he > had, the planner would still take a seqscan, because it's going to > expect that it can find a match by probing the first ten or so rows of > the first page. With anything close to the normal cost parameters, > that's going to look more expensive than an index probe. Possibly if > the table had a few more values it would work. Hmm, that's true. It also doesn't help the real actions (cascade, set *) since those really do need to get at all the rows, but it probably helps in a reasonable number of cases.