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 1sjD9d-00GPNY-H4 for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Aug 2024 07:31:45 +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 1sjD9b-001Gqk-7C for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Aug 2024 07:31:43 +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 1sjD9a-001Gqb-SJ for pgsql-hackers@lists.postgresql.org; Wed, 28 Aug 2024 07:31:43 +0000 Received: from mail-yw1-x112d.google.com ([2607:f8b0:4864:20::112d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sjD9Z-001oFk-0K for pgsql-hackers@lists.postgresql.org; Wed, 28 Aug 2024 07:31:42 +0000 Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-6b4432b541aso55121787b3.1 for ; Wed, 28 Aug 2024 00:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724830300; x=1725435100; darn=lists.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=CMR3wzXP7g6FvsEOeDGMtFR56SNXgTDGxLOnFStdKlY=; b=MVnprneispoQ8Vdras2/NN4uJMnq0swO2srX3YDDbaTUYlBfBaXMyxOShPwsZAw9Hh /zf6bixSmN+Jc+0uOYUvx3bz8rMHSyclJuA7ydE8MupFEaE8OpkEfEC29F7Y504NA7ea peitjEp4BriPqce3Ie1Eb2Ae5OQD70fpsWwReNnPIOBKXUXF4/+x31X8vWkCe488s4qR e4qlMVLgMRSE/vqWu66bQpfTjRFanuXUenWIr3aXK2wif1sFLZ9bJDbkzOG/Ks4Fe1T7 Rru0WUtbFbidoRTmSytDu4+eOTdMxxmpqWjpPOzakeHQWhkMniWxtRFTb0d8l8z32oj6 hN2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724830300; x=1725435100; 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=CMR3wzXP7g6FvsEOeDGMtFR56SNXgTDGxLOnFStdKlY=; b=Wza5lVOt+OTNeBqfHL5n+6llNVkdkcj6txRy5Ynciprr0OvDsCBYPO7mN+3q9n0TOQ YKdaudPVolGUgna7pXYm6vTyuv6UQibajz0lqYkhPifWtz9TRHP4hK59piJwHpO1jUNR JpQnbcXAJnjaaChHr7Ek4nu8yj7pTVJEvEwd+maMtztJScNtKhrL1Sy58VR8ZPXUZrqc 9azOXMNemdTZf0+GrlhCwzT0Dy4RbksAFMZDah/ifV7TYZRuUpQyO1ktyf+M/5Oshs2d zOUuaI1esSQLmK4dT5h5/fahIvLYcy7dapVYVQkG/zyG+quVejmaQ66RQkmaI3xh82pd yzpw== X-Forwarded-Encrypted: i=1; AJvYcCXg8zRiVvZ4B49y9bzRB2s/2KGbIAuJlaz1+Um2RNpfuTLQpVD4XX6ErfAQhkonpZsGsJ12LUIqy/BVwYnC@lists.postgresql.org X-Gm-Message-State: AOJu0Ywgjbd9VFszwYDfuXqvqx+SU25LGYhwv1Za5ATWhNxZUPJ/B4Gc 9kJii4fNd/PVaWjYVv6C9vJMpg7mDeVfesXrs9yBw45W0zrP1/7DaS3MRtv2fP4WvIEUiOY0eQz j3iCq7IS1yFpnR/OZgKPat4MKHVE/kzX/ X-Google-Smtp-Source: AGHT+IE5F3HO+eN2BobzUO86QKWcrK8C6yeMJfbAkzvfSfhj8y1R6ABU+iSSlpvD8/aDUZ/dzDWDh/r3scj8B4ec9Ms= X-Received: by 2002:a05:690c:4c08:b0:6d1:2779:ba2e with SMTP id 00721157ae682-6d12779bb6fmr21182377b3.28.1724830300070; Wed, 28 Aug 2024 00:31:40 -0700 (PDT) MIME-Version: 1.0 References: <2962669.1724722813@sss.pgh.pa.us> <2965760.1724724227@sss.pgh.pa.us> <3104695.1724775341@sss.pgh.pa.us> <3147330.1724795532@sss.pgh.pa.us> <3156371.1724800521@sss.pgh.pa.us> <3159017.1724801876@sss.pgh.pa.us> In-Reply-To: From: Richard Guo Date: Wed, 28 Aug 2024 15:31:27 +0800 Message-ID: Subject: Re: Significant Execution Time Difference Between PG13.14 and PG16.4 for Query on information_schema Tables. To: David Rowley Cc: Tom Lane , nikhil raj , pgsql-hackers@lists.postgresql.org 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 Wed, Aug 28, 2024 at 7:58=E2=80=AFAM David Rowley = wrote: > On Wed, 28 Aug 2024 at 11:37, Tom Lane wrote: > > Oh, scratch that, I see you mean this is an additional way to do it > > not the only way to do it. But I'm confused why it works for > > t1.two+1 AS c1 > > but not > > t1.two+t2.two AS c1 > > Those ought to look pretty much the same for this purpose. > > The bms_overlap(pull_varnos(rcon->root, newnode), rcon->relids) test > is false with t1.two+1. Looks like there needs to be a Var from t2 > for the bms_overlap to be true Exactly. What Tom's patch does is that if the expression contains Vars/PHVs that belong to the subquery, and does not contain any non-strict constructs, then it can escape being wrapped. In expression 't1.two+t2.two', 't2.two' is a Var that belongs to the subquery, and '+' is strict, so it can escape being wrapped. The expression 't1.two+1' does not meet these conditions, so it is wrapped into a PHV, and the PHV contains lateral reference to t1, which results in a nestloop join with a parameterized inner path. That's why Memoize can work in this query. Thanks Richard