X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id CF1D9D1B89D for ; Fri, 15 Aug 2003 17:14:38 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 96465-04 for ; Fri, 15 Aug 2003 14:14:28 -0300 (ADT) Received: from smtp013.mail.yahoo.com (smtp013.mail.yahoo.com [216.136.173.57]) by svr1.postgresql.org (Postfix) with SMTP id A4764D1B89F for ; Fri, 15 Aug 2003 14:14:27 -0300 (ADT) Received: from pcp01341166pcs.wilog301.pa.comcast.net (HELO europa.janwieck.net) (janwieck@68.80.245.191 with login) by smtp.mail.vip.sc5.yahoo.com with SMTP; 15 Aug 2003 17:14:27 -0000 Received: from Yahoo.com (ismtp.afilias.com [216.217.55.254]) (authenticated) by europa.janwieck.net (8.11.6/8.11.6) with ESMTP id h7FHEVH19137; Fri, 15 Aug 2003 13:14:32 -0400 Message-ID: <3F3D14A2.6090407@Yahoo.com> Date: Fri, 15 Aug 2003 13:13:06 -0400 From: Jan Wieck Organization: Unorganized User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: Stephan Szabo , Christopher Kings-Lynne , Bruce Momjian , Peter Childs , PostgreSQL-development Subject: Re: [GENERAL] 7.4Beta References: <20030814223830.O6635-100000@megazone.bigpanda.com> <12535.1060948630@sss.pgh.pa.us> In-Reply-To: <12535.1060948630@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/811 X-Sequence-Number: 42468 Tom Lane wrote: > Stephan Szabo writes: >> select * from fk where not exists(select * from pk where pk.key=fk.key) >> and key is not null; >> (doing seq scan/subplan doing index scan - which is probably close to the >> current system) > > Actually, even that would probably be noticeably better than the current > system. I haven't profiled it (someone should) but I suspect that > executor startup/shutdown time is a huge hit. Even though the trigger > is caching a plan, it has to instantiate that plan for each referencing > tuple --- and the executor is not designed for quick startup/shutdown. > > (Of course, this would become less relevant if the triggers got > rewritten to not go through SPI ...) One of the reasons why we used SPI to generate the plans was the ease of use. I'm not 100% sure, but I think the standard doesn't require the referencing and referenced column(s) to be identical, only compatible. So for example a text type foreign key can reference a varchar() and an int4 can reference int8. Not using SPI for that lookup does not reduce to a simple index- or seq-scan (depending on index availability on the foreign key attributes). Even if the standard does require it, we did not for a couple releases and breaking that backward compatibility is IMHO not an option. I'm thinking instead of a way to "cache" entire executors for this. Each SPI plan used during a transaction would need it's own executor, and I don't know offhand what type and how much resources an executor requires (I think it's only some memory that get's initialized and the VFD's opened). If I also remember correctly, the executor holds the pointer to the parameters in the execstate and the actual values stay just in the caller provided array. All that can change for a given plan between SPI_execp() calls is this parameter array and the maxtuple arg. If an executor is comparably cheap resource wise, SPI_execp() should be able to just manipulate the parameter array in the execstate (with propagation into the scankeys I fear) and then let it do a rescan. At transaction commit time we'd need to close all executors then, like we do with cursors. Does that all make any sense to you? Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #================================================== JanWieck@Yahoo.com #