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 1pnjbE-00074c-88 for pgsql-interfaces@arkaria.postgresql.org; Sat, 15 Apr 2023 17:22:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pnjbD-0007A3-4x for pgsql-interfaces@arkaria.postgresql.org; Sat, 15 Apr 2023 17:22:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pnNOU-0005Uo-11 for pgsql-interfaces@lists.postgresql.org; Fri, 14 Apr 2023 17:39:30 +0000 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.221]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pnNOR-002tw3-4e for pgsql-interfaces@postgresql.org; Fri, 14 Apr 2023 17:39:29 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1681493965; cv=none; d=strato.com; s=strato-dkim-0002; b=Fg7cnljD280aRfka8DTLz2B3UGcb9k90CclJesciMWyNCl0Nd+Hx04+Mr7xlMvTl3h zZTVs3sheOxFimHh4Ta4L5t9zvSCR9r6i0f0OMQ8p3Uet0hz00AqtvSk6FwW40JkgcKH 9ESGf0erM6bJXBghorlrj44/MTDSfePx8tcjgrzq3JeSt8ZjguMtM/GRA2vjaukH70Zr 5wN1wnlYlWLcCn/rUJj/1tOS2WHuSFAhA+Np76MQ3UvdFLXWpltEhHGndDDGsuqLQpKe jEngu+2XlCWtiOgWULK2d1YtXTP0yJZKdjMbBfuy3zHOa+oRth3dRRY4Vc7zimjN7S1p wm5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1681493965; s=strato-dkim-0002; d=strato.com; h=In-Reply-To:From:References:To:Subject:Date:Message-ID:Cc:Date:From: Subject:Sender; bh=tGcRd+Bjphi/piBEU8r2Zkrbais8scl4ltVTFSsKjAQ=; b=HhwBYRdA/x5aYfAwwIRYW0pxEZqpO4czvlO82s1YJ/al2blTRzgNYpwbP5XDujsYjk EkDnPa4s2nn4kmY6pD6oP1Vpi1Y3MJUBIgJZhWZSmimn4F4/iGa6prZcUvHYYUYK4w1D bkzxCw5y2bM0mSGC4xhohWWlga8PIdjOfbCqJZFpzrkrJTKnH8+swPpUShsZ1AMQeV1e enuVO6gwLdrR2ziDRl/FDIzJvf8EiWEB+B9aDjEJLVzoYiJsjoMZkkUBenUqgePKJ9KJ cVPF4r6lZ3nxzRB5N6IGn7hG4NCqw9yjbWPnrRzoVMcUsRCO8fOk44hM+idx/MGuIGDU J3Sw== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1681493965; s=strato-dkim-0002; d=tuschehund.de; h=In-Reply-To:From:References:To:Subject:Date:Message-ID:Cc:Date:From: Subject:Sender; bh=tGcRd+Bjphi/piBEU8r2Zkrbais8scl4ltVTFSsKjAQ=; b=Yu0sRbfnjTpSTnj9Pr2/YFp/ccBwH6Kzq/OVp7N1l7bZjNG4gZV8p/EmcQtVyzMwI1 vg+xVtvYCFNix6TDdpteBU2xljBO8LBovvqhxeDskDJ+OvajylwjdmDWfdoNmZJiUZQl A69LY826h0B5f5P7e4PTZOEMwsef9rI+EENlGzWa1UtZ9rN5ldrHs+o7SlhrxTtzPoiq QYm0Gxer6NiWjqwxVzkBb4G0RNa3I0HJss5b36aBKTfhDvKFOTwl5eF23jNR2RwO9A2k Xvf7FdGuURADAa+Vv9WBpziEjrGlNgCqM8xcz5zyAOs9e7RfX3EfOFS9KsMvyZQXAdYt NJzQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1681493965; s=strato-dkim-0003; d=tuschehund.de; h=In-Reply-To:From:References:To:Subject:Date:Message-ID:Cc:Date:From: Subject:Sender; bh=tGcRd+Bjphi/piBEU8r2Zkrbais8scl4ltVTFSsKjAQ=; b=4tJlJ9W4eqe03wTCb5L1x1wBe1GpzuS/KFpPIRs3F2Nkap8db69PBQInjPx7pEdrM/ vLP/8iVeAwr7IPQHQ5Cw== X-RZG-AUTH: ":KX8HfU2hf99DXuV00Ei1esfd2dELLuierrOoxnaT42+ril7x+6/CAY9wnngJ2RRhCYhd1acM0E6WpqBL1s/wr+rbF+AfaSca1kReLfzO" Received: from [IPV6:2003:ce:707:1c00:f536:9661:a3d2:5713] by smtp.strato.de (RZmta 49.4.0 AUTH) with ESMTPSA id Y067e0z3EHdPzti (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Fri, 14 Apr 2023 19:39:25 +0200 (CEST) Message-ID: <8306edcc-8458-44b3-485b-0725de3c7743@tuschehund.de> Date: Fri, 14 Apr 2023 19:39:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: C trigger significantly slower than PL/pgSQL? To: "pgsql-interfaces@postgresql.org" References: <1595558642.2519076.1681378287741@webmail.strato.de> <1342580.1681400531@sss.pgh.pa.us> From: Ernst-Georg Schmid In-Reply-To: <1342580.1681400531@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > Yeah, there's your problem. Each time through the trigger, that query > is being parsed, planned, and executed from scratch. plpgsql knows > how to cache the planned statement, so it's doing less work per-call. Hello again, thank you for your help. I have now used SPI_prepare() and SPI_keepplan() to cache the plan in a static variable - and now it performs exactly like the PL/pgSQL version. Which also probably means that either the Trigger is so trivial that C makes no difference, or the observed TPS limit comes from somewhere else. I have still a follow-up question, though. Since I'm not calling SPI_freeplan(), the cached plan lives forever, right? Which is no problem, since the trigger does the same statement over and over. But does this generate a memory leak? Or is the saved plan tied to the session and is deallocated when the session ends? best regards Ernst-Georg