Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nSSL0-0004s6-Bs for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Mar 2022 23:36:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nSSKy-0004Lw-I9 for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Mar 2022 23:36:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nSSKy-0004Kc-90 for pgsql-hackers@lists.postgresql.org; Thu, 10 Mar 2022 23:36:52 +0000 Received: from anastigmatix.net ([68.171.219.55]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nSSKt-0005WL-8P for pgsql-hackers@lists.postgresql.org; Thu, 10 Mar 2022 23:36:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=anastigmatix.net; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:Cc:References:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=2Jvm72sKBP8VG6khgyUOWBUKLPzWwC/oH+MnXrO/YcA=; b=gM1uY3gwAFTghq9icTSeWMH2ek nUYzA4uFREG4Z1ZasoAiq+DNKEw2jV+R/hLBUXJbD/wdgI4Y1q14+KBm0TAs0qluCTGdbzPOmsEpP 2pw4eixufBx70p3JZRQmFHI62S0rbp2YCMg7FrpQp1dUyONj/f1eim34EDf0BcANbsnBgaP91d6Hp 7IuUMGIKJuZANs0IvN+bUJu8bZWx26DAyN5xzIjKUty/oD8TZ2tl912iTlN4tjSaGWouMs9xv/KFT yjBIrCY+PqRjIIBVQHrEFIhV/KohIqYLSEiTE6gKUKMbjM8U9aqmtS1EIvvLshVCfcHOvwHEM4F7a n2nH2PCw==; Received: from [184.19.43.81] (port=50503) by bay.acenet.us with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1nSSKr-00FFcL-Mu; Thu, 10 Mar 2022 18:36:46 -0500 Subject: Re: trigger example for plsample To: Mark Wong References: <164581437973.1035.16436524743292685141.pgcf@coridan.postgresql.org> Cc: pgsql-hackers@lists.postgresql.org, Konstantina Skovola From: Chapman Flack X-Enigmail-Draft-Status: N1110 Message-ID: <622A8B8C.1060306@anastigmatix.net> Date: Thu, 10 Mar 2022 18:36:44 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bay.acenet.us X-AntiAbuse: Original Domain - lists.postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - anastigmatix.net X-Get-Message-Sender-Via: bay.acenet.us: authenticated_id: chap@anastigmatix.net X-Authenticated-Sender: bay.acenet.us: chap@anastigmatix.net X-Source: X-Source-Args: X-Source-Dir: X-From-Rewrite: unmodified, already matched List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 03/02/22 15:12, Mark Wong wrote: > I've attached v2, which reduces the output: > > * Removing the notices for the text body, and the "compile" message. > * Replaced the notice for "compile" message with a comment as a > placeholder for where a compiling code or checking a cache may go. > * Reducing the number of rows inserted into the table, thus reducing > the number of notice messages about which code path is taken. I think the simplifying assumption of a simple interpreted language allows a lot more of this code to go away. I mean more or less that whole first PG_TRY...PG_END_TRY block, which could be replaced with a comment saying something like The source text may be augmented here, such as by wrapping it as the body of a function in the target language, prefixing a parameter list with names like TD_name, TD_relid, TD_table_name, TD_table_schema, TD_event, TD_when, TD_level, TD_NEW, TD_OLD, and args, using whatever types in the target language are convenient. The augmented text can be cached in a longer-lived memory context, or, if the target language uses a compilation step, that can be done here, caching the result of the compilation. That would leave only the later PG_TRY block where the function gets "executed". That could stay largely as is, but should probably also have a comment within it, something like Here the function (the possibly-augmented source text, or the result of compilation if the target language uses such a step) should be executed, after binding these values from the TriggerData struct to the expected parameters. That should make the example shorter and clearer, and preserve the output tested by the regression test. Trying to show much more than that involves assumptions about what the PL's target language syntax looks like, how its execution engine works and parameters are bound, and so on, and that is likely to just be distracting, IMV. Regards, -Chap