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 1rTEvm-001LZo-FW for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jan 2024 05:39:11 +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 1rTEvk-009bVp-Fy for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jan 2024 05:39:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rTEvk-009bVh-4A for pgsql-hackers@lists.postgresql.org; Fri, 26 Jan 2024 05:39:08 +0000 Received: from mail-yw1-x1130.google.com ([2607:f8b0:4864:20::1130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rTEvh-003Q76-FO for pgsql-hackers@postgresql.org; Fri, 26 Jan 2024 05:39:06 +0000 Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-5ff821b9acfso419667b3.1 for ; Thu, 25 Jan 2024 21:39:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706247544; x=1706852344; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=pfa/gaIwFEl1SfLWBTgW/BP9OT0LOeVs5XWWY95mYYU=; b=OFi2OfDpkb9j2Yt3xrJWg5GfwK2gXxUBXkvt0n2zeP5N89po8qt2lhVVEK0goOw2Fv o5fgZKv2oIroAXJVeuyvMweZGHgzNOp9igXrdRK2pu/auk7OvfEFyXdutZHjf4Xg52w5 8ItPU6Eye8Eqb1qB1/py5uMR2hxMA23Mn3WXJ7SPAOQtlLkZSw8/lZHLL2cEnBu6WQVG wGLj31TSTlgyey1CDxFHA/08nhsmCDOcksbqHJsT+wwaK6UGi8eZh0aaJ75Co31GVMdG 1caHsYGqQgX5MuqDh2eT9+P+Q2m/zHeRahl5myj6ET7pqj69W14owF3vpT7PcBka0NIm oyFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706247544; x=1706852344; h=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=pfa/gaIwFEl1SfLWBTgW/BP9OT0LOeVs5XWWY95mYYU=; b=UkjjebohjInNz9Nu7W7BxijNOGlku0zqIfYg81HURkq3Vn964a32WGzuCoeisRO43A nbx0/u35EAmAQlA4pOgCPBAYq3bamr2TbfFwRh6cxZR8mxXH+H4ZITeM6FWePW8q3BYt YPTszOwR+zbYPEHjpM35KW9vDFrgvdFAZuMyArKNt8lMouTuQ7/TDcao1n+2mBFEaej2 YRyhEuZIOFJdrn/7GbTkIG5ZI9MgTPSCmZ2IbzWITKjJFLtWmSqs8+JoVjXD6pAria30 DIPiTLpiWQgRZopPnNMwO5JWi4Pfkk4T+fSI2j5tID/uPo2+oeqEfGMqgKJ8d57qPbm5 la+w== X-Gm-Message-State: AOJu0YyJvDmfLWL+43OgVLzrd0XZJymAsxYLuG80/Taxv9hLv/GL32Zs /ZBWV5PNKmhnnIFKVwwyD/lpie7PqKxmW1EQ712xPdam8zeI1XQaGlAlaL9yqKGYybb35kpGwZp z9VgpJnb1NSTgRAM2NNUEgOl8TzE= X-Google-Smtp-Source: AGHT+IFG//O4kgB4dQjJGBFkdvXBzn1ueheD6kGpG/zQzZUx8exlF6/ruNAgbyUgeutfLd4bMteqtE9F0X8V6StV5BU= X-Received: by 2002:a81:4420:0:b0:602:9ec9:e6f2 with SMTP id r32-20020a814420000000b006029ec9e6f2mr743945ywa.27.1706247544571; Thu, 25 Jan 2024 21:39:04 -0800 (PST) MIME-Version: 1.0 References: <412552.1706203379@sss.pgh.pa.us> In-Reply-To: <412552.1706203379@sss.pgh.pa.us> From: Richard Guo Date: Fri, 26 Jan 2024 13:38:53 +0800 Message-ID: Subject: Re: A performance issue with Memoize To: Tom Lane Cc: David Rowley , PostgreSQL-development Content-Type: multipart/alternative; boundary="000000000000cb0c8f060fd2b6d2" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000cb0c8f060fd2b6d2 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jan 26, 2024 at 1:22=E2=80=AFAM Tom Lane wrote: > Apologies for not having noticed this thread before. I'm taking > a look at it now. However, while sniffing around this I found > what seems like an oversight in paramassign.c's > assign_param_for_var(): it says it should compare all the same > fields as _equalVar except for varlevelsup, but it's failing to > compare varnullingrels. Is that a bug? It's conceivable that > it's not possible to get here with varnullingrels different and > all else the same, but I don't feel good about that proposition. > > I tried adding > > @@ -91,7 +91,10 @@ assign_param_for_var(PlannerInfo *root, Var *var) > pvar->vartype =3D=3D var->vartype && > pvar->vartypmod =3D=3D var->vartypmod && > pvar->varcollid =3D=3D var->varcollid) > + { > + Assert(bms_equal(pvar->varnullingrels, > var->varnullingrels)); > return pitem->paramId; > + } > } > } Yeah, I think it should be safe to assert that the varnullingrels is equal here. The Var is supposed to be an upper-level Var, and two same such Vars should not have different varnullingrels at this point, although the varnullingrels might be adjusted later in identify_current_nestloop_params according to which form of identity 3 we end up applying. Thanks Richard --000000000000cb0c8f060fd2b6d2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Fri, Jan 26, 2024 at 1:22=E2=80=AFAM T= om Lane <tgl@sss.pgh.pa.us> = wrote:
Apologies for not having noticed this thread before.=C2=A0 I'm taking a look at it now.=C2=A0 However, while sniffing around this I found
what seems like an oversight in paramassign.c's
assign_param_for_var(): it says it should compare all the same
fields as _equalVar except for varlevelsup, but it's failing to
compare varnullingrels.=C2=A0 Is that a bug?=C2=A0 It's conceivable tha= t
it's not possible to get here with varnullingrels different and
all else the same, but I don't feel good about that proposition.

I tried adding

@@ -91,7 +91,10 @@ assign_param_for_var(PlannerInfo *root, Var *var)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pvar->vart= ype =3D=3D var->vartype &&
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pvar->vart= ypmod =3D=3D var->vartypmod &&
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pvar->varc= ollid =3D=3D var->varcollid)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Assert(bms_equal(p= var->varnullingrels, var->varnullingrels));
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return pitem-= >paramId;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0 =C2=A0}

Yeah, I think it shou= ld be safe to assert that the varnullingrels is
equal here.=C2=A0 The Va= r is supposed to be an upper-level Var, and two same
such Vars should no= t have different varnullingrels at this point,
although the varnullingre= ls might be adjusted later in
identify_current_nestloop_params according= to which form of identity 3
we end up applying.

Thanks
Richar= d
--000000000000cb0c8f060fd2b6d2--