Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gyC64-0003RE-Pq for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Feb 2019 08:58:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gyC63-0003yv-HZ for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Feb 2019 08:58:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gyC63-0003yo-91 for pgsql-hackers@lists.postgresql.org; Mon, 25 Feb 2019 08:58:47 +0000 Received: from mx2a.mailbox.org ([2001:67c:2050:104:0:2:25:2] helo=mx2.mailbox.org) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gyC60-0007Y5-ME for pgsql-hackers@postgresql.org; Mon, 25 Feb 2019 08:58:46 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id CBA5AA130D; Mon, 25 Feb 2019 09:58:41 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=MBO0001; t=1551085118; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gCaq0I1hOHPUYTGV9zzvfauPZ5XGPxFrELrACDfNaEc=; b=TA1aLQUe4x0ofAKx84C/vGiJ2ctNTf9U/0dWh9Vd7YtN9ggZ2Ofmi1iZkEAUySN9Uwf3ls NXqaTsko4NSf0H3dna8rrfZbmCJfq6vvZ214/HnD4V70hpO/5RYwabPd9A41Lm3akGBPN5 aeCsh9vPA/r6MFb0Y+SUSq4TXzvdjnlv77Ief0Zdu9aPLYjuE3xX+v2dBPs3cTVdXHdego clYe+u9TZjayRG+2e+VCFCDEWt9DFCQiMt/eHGFByp7bQIu7x7mNl6VBMBHrsf1jzSYdRu 0idM1930V+wu6yxWEA/eJJWAonAyRfPD59eY37mNOrySFYpm2h22BwiLtHH0mg== Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id MMqeJqGn3rcu; Mon, 25 Feb 2019 09:58:34 +0100 (CET) From: Antonin Houska To: Corey Huinker cc: emre@hasegeli.com, Adam Brusselback , Pavel Stehule , Alvaro Herrera , PostgreSQL Hackers Subject: Re: Referential Integrity Checks with Statement-level Triggers In-reply-to: References: <20181217172729.mjfkflaelii2boaj@alvherre.pgsql> <17100.1550662686@localhost> Comments: In-reply-to Corey Huinker message dated "Fri, 22 Feb 2019 12:22:06 -0500." MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4901.1551085231.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Mon, 25 Feb 2019 10:00:31 +0100 Message-ID: <4902.1551085231@localhost> Authentication-Results: default_out X-Rspamd-Queue-Id: 0AD5A16AC List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Corey Huinker wrote: > Have you considered bulk processing of individual rows by row-level tri= gger? > For IMMEDIATE constraints we'd have to ensure that the trigger is notif= ied > that the current row is the last one from the current query, but that m= ight > not be difficult. > = > I'm not sure I understand what you're suggesting, but if it keeps the > overhead of one trigger firing per row deleted, then it doesn't seem lik= e > much of a win. I thought of a trigger that still fires for each row, but most of the time= it only stores the row deleted into a tuplestore of the appropriate lifespan.= The queries that you proposed would only be executed if the tuplestore contain= s given amount of tuples or if the last row of the current statement has bee= n stored. > Given that this patch has been punted to v13, I'd like to instead look a= t > how we might go about building up the transition tuplestores for the > specific purpose of doing the RI checks, not just deletes, and executing > those at the appropriate time, rather than trying to make our needs fit = into > trigger form. Constraint-specific tuplestore can make some things easier, but if table h= as both constraints and (non-constraint) triggers which use the transition tables, then the tuples will have to be stored in both tuplestores. On the other hand, using the same tuplestore for both constraint and non-constrai= nt triggers is difficult because deferred constraint triggers need to see row= s added by all statements while the non-constraint triggers should only see = rows of the current statement. In order to avoid per-row calls of the constraint trigger functions, we co= uld try to "aggregate" the constraint-specific events somehow, but I think a separate queue would be needed for the constraint-specific events. In general, the (after) triggers and constraints have too much in common, = so separation of these w/o seeing code changes is beyond my imagination. -- = Antonin Houska https://www.cybertec-postgresql.com