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 1sjCnE-00GMAA-1q for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Aug 2024 07:08:36 +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 1sjCnB-0014Ed-LF for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Aug 2024 07:08:34 +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 1sjCnB-0014EU-B5 for pgsql-hackers@lists.postgresql.org; Wed, 28 Aug 2024 07:08:33 +0000 Received: from mail-yw1-x112e.google.com ([2607:f8b0:4864:20::112e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sjCn7-001seK-Do for pgsql-hackers@lists.postgresql.org; Wed, 28 Aug 2024 07:08:32 +0000 Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-6b8d96aa4c3so54138597b3.1 for ; Wed, 28 Aug 2024 00:08:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724828909; x=1725433709; 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=N/b4JCL4rMh6Oq8NNyX/y9pm2uSm2PMcI3O5f1si2WM=; b=BaCSB4VgyLTXjn2iH2zG188nZ9l/pcSIjelQiWzwU3TTLtfTnRYqTx/O7hYRpAg5z7 x2w53G8ozdnWgQ9+GkgEb66ani8r6TleHhb97gioFI7mXweqgEsa7ldrNKEWFfeNxiwI TruSKIJlMmSfpVFRgHjAqP2W3C+h4GwzY/qSWr7tYhP5qMwy/mBWoC6v7N/0j+IXyuSy hb0ouMMil6dL7py+FnXVx/d+VG3iLahdCg457dOspwMQUw/+LPGTvb1K+4sR7uJZ0Q8L flhEb8bMzmABieEPHzalOaw1op4NsvvGdbfJ5KSl95w/5XRv/YHUADpP/aisXutelO9p 1yFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724828909; x=1725433709; 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=N/b4JCL4rMh6Oq8NNyX/y9pm2uSm2PMcI3O5f1si2WM=; b=qzbzJcCKB7bvcIbKeqIJECnx4GK0tX4VgVdd54FzMJhCCUOjfkMLPTWrGxadzRUYhg gPHqNjRbtHQGKpTYVOkgTcKi5e+e/wkElVt54a1gLriMjYoA5Vr1WLhZrTtvajvmx2aH 8GzQFI+0xP6Vs1Vml7WSZEYYh8POyMF+BadDLtsG/PvGIupDYHG2Ph3E3W/xqYvlP43S l3m/HmhIoXDvUBfb0ZRBfBvpt4KKmo+HvdqCBHmnxBvIh/x/zgvAmwKLMrLMAIjj6jo2 jP1NC5/RRjcyWMBHIKnK+yyEi006X7VUco1mRGGR9ZD/BrvZJZvhx80CtB3DFdJVT7ES 3keA== X-Forwarded-Encrypted: i=1; AJvYcCUDrNcqoNBSY2p2TnxkbmrfH/tfjLKKVu40AdJb2apbpWl1PoytFGdpTN33OCWt7LwV0Qosryx6eImGInwL@lists.postgresql.org X-Gm-Message-State: AOJu0Yy3En9IjXhkeFoBQ8XcnD7sD+5pcmAt+mfFelEV7SwpayLuV5mc vxOZ53ufynb+phpyLbNJgIRHq8y0kOS9nlC2BGB1gcr/VtMsdh0RENxFGngJ0jPJ1g9uePm96Vi jbywgKhrsExUOaG2pb1qIDJHDB+0= X-Google-Smtp-Source: AGHT+IGGmqUM9iCvreBfGROSGTQYCkVH4t+1P9NNx2m1ZbaHX1z2K+8qFOQZUTnHrunQytZLCxZvbEw3mBTxrkrzN/o= X-Received: by 2002:a05:690c:2a84:b0:6b0:5b38:5a33 with SMTP id 00721157ae682-6d16ff29759mr8044947b3.20.1724828908910; Wed, 28 Aug 2024 00:08:28 -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> In-Reply-To: <3104695.1724775341@sss.pgh.pa.us> From: Richard Guo Date: Wed, 28 Aug 2024 15:08:16 +0800 Message-ID: Subject: Re: Significant Execution Time Difference Between PG13.14 and PG16.4 for Query on information_schema Tables. To: Tom Lane Cc: David Rowley , 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 12:15=E2=80=AFAM Tom Lane wrote= : > If we > are willing to accept a HEAD-only fix, it'd likely be better to > attack the other end and make it possible to remove no-op PHVs. > I think that'd require marking PHVs that need to be kept because > they are serving to isolate subexpressions. I think it's always desirable to remove no-op PHVs, even if we end up with a different approach to fix the issue discussed here. Doing that could potentially open up opportunities for optimization in other cases. For example: explain (costs off) select * from t t1 left join lateral (select t1.a as x, * from t t2) s on true where t1.a =3D s.a; QUERY PLAN ---------------------------- Nested Loop -> Seq Scan on t t1 -> Seq Scan on t t2 Filter: (t1.a =3D a) (4 rows) The target entry s.x is wrapped in a PHV that contains lateral reference to t1, which forces us to resort to nestloop join. However, since the left join has been reduced to an inner join, and it is removed from the PHV's nullingrels, leaving the nullingrels being empty, we should be able to remove this PHV and use merge or hash joins, depending on which is cheaper. I think there may be more cases where no-op PHVs constrain optimization opportunities. In [1] when working on the fix-grouping-sets patch, I included a mechanism in 0003 to remove no-op PHVs by including a flag in PlaceHolderVar to indicate whether it is safe to remove the PHV when its phnullingrels becomes empty. In that patch this flag is only set in cases where the PHV is used to carry the nullingrel bit that represents the grouping step. Maybe we can extend its use to remove all no-op PHVs, except those that are serving to isolate subexpressions. Any thoughts on this? [1] https://postgr.es/m/CAMbWs4_2t2pqqCFdS3NYJLwMMkAzYQKBOhKweFt-wE3YOi7rGg= @mail.gmail.com Thanks Richard