Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rLhiv-009cOJ-Uz for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jan 2024 10:46:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rLhiu-002Srt-Gd for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jan 2024 10:46:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rLhiu-002Srl-5w for pgsql-hackers@lists.postgresql.org; Fri, 05 Jan 2024 10:46:44 +0000 Received: from mail-yb1-xb2b.google.com ([2607:f8b0:4864:20::b2b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rLhir-00Fhnq-BW for pgsql-hackers@postgresql.org; Fri, 05 Jan 2024 10:46:43 +0000 Received: by mail-yb1-xb2b.google.com with SMTP id 3f1490d57ef6-dbdd013c68bso1221102276.2 for ; Fri, 05 Jan 2024 02:46:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704451599; x=1705056399; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TqI0wPnISNF9zeLgAx2spR42sSsNdtFafb1oJHHhtHI=; b=kQYne1avvbwM/OGh0x2rbxUqLwa7Mrz0zeDdGc444G0y/o8+fSOQtOO6ZGAeGkVT2i AT32X6X5fe9IAzGwDan8+l5FHErsFmfRMG6oJYsf3MCgnePbq6nvx5WxSaWiFeL0JZoM p4EbDS7LFrbuh0et+rYWiusccqp/AK2PA+2Ff6KPhZULjGtUPT4QDGs2/rkocdjgF9ot y3np/8VsEy560E32+yjt5yjAHESaIICOndqGqxO9Gkdldcc0aqvzaJEyZjv5DMRdJ6jA WWDRDlHahArKLqbuhAEzU4kApg9QsK29703rnX2bUa4K+0852oxBrIQMPeCKvFPKLvzD Wwow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704451599; x=1705056399; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TqI0wPnISNF9zeLgAx2spR42sSsNdtFafb1oJHHhtHI=; b=OkpL1gnVcKO2JhdohLjRFOp62ho41J1u+e5DvOkV4AoQ2C+/04jBE2Ulk/mH3s05sH 5V71+tfk6HuYkk9mldUV+oLWQxfGDNBukBJ5WjE88XtXF19yxH+ZdsciC9e0q95pD8j7 cFgynBKHaTjGTuztudmnLjVMCPxHilaodZDVl17gbQ16IvZnvM7VB8/irRv31XRj7PEN dCCNx3szzmZJVNkFCznjovRsLkkPpi7bHj7kXi16nKNTYz7voi4pYdG4k5zsFcT/LUl8 NsAALgpnE1fZWrWKbRk7a9jnOLojlLQa9T1o1c5qr3YYdfa0i77tqHC3dNDd6AViSdWQ 8NTw== X-Gm-Message-State: AOJu0YwXtIA1it9iG/wfIRf4pKOMfET/Pyb4yh4V3xE8y+h+H792/qs4 DIE40UBc5EsVD8xTA++eGuhhz3yRRIeTl5by9w+vcO+iMh9Y92EZ X-Google-Smtp-Source: AGHT+IFZlGsMLjJ+Y2m8cMKy0IUeyP3bLAEqJ2jmV4ovr8VXnHoFJnhYLhZYdtxNVb5cJNy8CGfo3pn9OAWrS4eqcy4= X-Received: by 2002:a25:9101:0:b0:db8:c261:80ac with SMTP id v1-20020a259101000000b00db8c26180acmr1727831ybl.120.1704451599442; Fri, 05 Jan 2024 02:46:39 -0800 (PST) MIME-Version: 1.0 References: <20221221101846.7zsi7lscnm5ediik@alvherre.pgsql> <1350682.1671635927@sss.pgh.pa.us> <4191508.1674157166@sss.pgh.pa.us> <349124.1674185509@sss.pgh.pa.us> <20230207180855.xy5m4puwh5gzd7xy@awork3.anarazel.de> <1274885.1680558101@sss.pgh.pa.us> <9D23D8BB-83EE-451E-95C1-CF42ADB76869@yesql.se> In-Reply-To: From: vignesh C Date: Fri, 5 Jan 2024 16:16:27 +0530 Message-ID: Subject: Re: generic plans and "initial" pruning To: Amit Langote Cc: Robert Haas , Alvaro Herrera , Andres Freund , Daniel Gustafsson , David Rowley , Jacob Champion , PostgreSQL Hackers , Thom Brown , Tom Lane Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 20 Nov 2023 at 10:00, Amit Langote wrote: > > On Thu, Sep 28, 2023 at 5:26=E2=80=AFPM Amit Langote wrote: > > On Tue, Sep 26, 2023 at 10:06=E2=80=AFPM Amit Langote wrote: > > > After sleeping on this, I think we do need the checks after all the > > > ExecInitNode() calls too, because we have many instances of the code > > > like the following one: > > > > > > outerPlanState(gatherstate) =3D ExecInitNode(outerNode, estate, e= flags); > > > tupDesc =3D ExecGetResultType(outerPlanState(gatherstate)); > > > > > > > > > If outerNode is a SeqScan and ExecInitSeqScan() returned early becaus= e > > > ExecOpenScanRelation() detected that plan was invalidated, then > > > tupDesc would be NULL in this case, causing the code to crash. > > > > > > Now one might say that perhaps we should only add the > > > is-CachedPlan-valid test in the instances where there is an actual > > > risk of such misbehavior, but that could lead to confusion, now or > > > later. It seems better to add them after every ExecInitNode() call > > > while we're inventing the notion, because doing so relieves the > > > authors of future enhancements of the ExecInit*() routines from > > > worrying about any of this. > > > > > > Attached 0003 should show how that turned out. > > > > > > Updated 0002 as mentioned in the previous reply -- setting pointers t= o > > > NULL after freeing them more consistently across various ExecEnd*() > > > routines and using the `if (pointer !=3D NULL)` style over the `if > > > (pointer)` more consistently. > > > > > > Updated 0001's commit message to remove the mention of its relation t= o > > > any future commits. I intend to push it tomorrow. > > > > Pushed that one. Here are the rebased patches. > > > > 0001 seems ready to me, but I'll wait a couple more days for others to > > weigh in. Just to highlight a kind of change that others may have > > differing opinions on, consider this hunk from the patch: > > > > - MemoryContextDelete(node->aggcontext); > > + if (node->aggcontext !=3D NULL) > > + { > > + MemoryContextDelete(node->aggcontext); > > + node->aggcontext =3D NULL; > > + } > > ... > > + ExecEndNode(outerPlanState(node)); > > + outerPlanState(node) =3D NULL; > > > > So the patch wants to enhance the consistency of setting the pointer > > to NULL after freeing part. Robert mentioned his preference for doing > > it in the patch, which I agree with. > > Rebased. There is a leak reported at [1], details for the same is available at [2]: diff -U3 /tmp/cirrus-ci-build/src/test/regress/expected/select_views.out /tmp/cirrus-ci-build/build/testrun/regress-running/regress/results/select_v= iews.out --- /tmp/cirrus-ci-build/src/test/regress/expected/select_views.out 2023-12-19 23:00:04.677385000 +0000 +++ /tmp/cirrus-ci-build/build/testrun/regress-running/regress/results/sele= ct_views.out 2023-12-19 23:06:26.870259000 +0000 @@ -1288,6 +1288,7 @@ (102, '2011-10-12', 120), (102, '2011-10-28', 200), (103, '2011-10-15', 480); +WARNING: resource was not closed: relation "customer_pkey" CREATE VIEW my_property_normal AS SELECT * FROM customer WHERE name =3D current_user; CREATE VIEW my_property_secure WITH (security_barrier) A [1] - https://cirrus-ci.com/task/6494009196019712 [2] - https://api.cirrus-ci.com/v1/artifact/task/6494009196019712/testrun/b= uild/testrun/regress-running/regress/regression.diffs Regards, Vingesh