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 1sik9R-008oAs-RL for pgsql-general@arkaria.postgresql.org; Tue, 27 Aug 2024 00:33:38 +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 1sik8Q-00H8v7-9m for pgsql-general@arkaria.postgresql.org; Tue, 27 Aug 2024 00:32:34 +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 1sik8O-00H8uz-Ho for pgsql-general@lists.postgresql.org; Tue, 27 Aug 2024 00:32:34 +0000 Received: from fout5-smtp.messagingengine.com ([103.168.172.148]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sik8H-001bDI-Mv for pgsql-general@lists.postgresql.org; Tue, 27 Aug 2024 00:32:31 +0000 Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 7D901138FE6B; Mon, 26 Aug 2024 20:32:23 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Mon, 26 Aug 2024 20:32:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1724718743; x=1724805143; bh=85wtj1zddQQ88T7thqhuNGm96/sdHLc6uegnZqwlVoc=; b= rQhDX5g4LfQdp3/FvmFJ2yinRq9U8Ok+gLnDtjnzG+X4pvxYt0Pp57KqjIkvsLrM Ju5Q6D/ssaw6Z47+cp/tU9kasek0WoVWMOT1KUIYpPAerJpTeLERC8M0W+aEOeGA xowZRLoMbCPf4ys4wjRrLjARgd9lEt5bOJgQ5jfDmrgvv+1Ve8jQZXjYoC44V376 5YEvScaFB2oWETe0P7hQyo2xvmCUYwdfPdTS/E+Nirdu/qNOM9V2ECrxvQoN4So5 LJZiXAXrbD/6OBQNI2+G8V2C2M3hF6GEqA6xe9mOOJAY4clzL3iGKaR2FyCwz/UA YSF2Jl+jOb6XGhGwlVeqKQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1724718743; x= 1724805143; bh=85wtj1zddQQ88T7thqhuNGm96/sdHLc6uegnZqwlVoc=; b=j AQ3RwpWlAPj07a9aUQM8zG6hxY5ylVqt6JQ4YSI5SyalhzLzjesHS0CY39WWWQ7L xyP/T340g9NzQi99l3fmknYNBHCIhqOvdS1LYJGTAOuOs6ZsEwG/d5lJPTCb4MFV LCp2Wq36XZ8t5mhGp9XGgxJib44TaXCbUHzuqcLwHn94UJFnEcS2ivumcJmSzw7G VnnQaJNXY6WYXIgbGuXASgZEl6J92oIXGTYL+u9ii2OiiN2GpXO3nfATr6h+GmC7 B1MlEgNy/Y7jnAKPcU8EgQH6vCzs5q5nQ4AN1nGMVkjcf/DrLu3kvCzko3+G8i18 3zBhVP2pCqXKjzJxTHhDw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvledgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtvdej necuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrh esrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepfffhgeeifefhhfffgfev ieehveelffegheegheetfeejffegteehtdfhhedtgffhnecuffhomhgrihhnpeguvghpvg hsiidrtghomhdpuggrlhhisghordgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrh drtghomhdpnhgspghrtghpthhtohepgedpmhhouggvpehsmhhtphhouhhtpdhrtghpthht ohepnhhikhhhihhlrhgrjhegjeegsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgsh hqlhdqghgvnhgvrhgrlheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpdhrtghp thhtohepphgrthgvlhhnihhkihhtrgdugeduudesghhmrghilhdrtghomhdprhgtphhtth hopehprghtvghlkhhhuhhshhgsuhdvtdeijeesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 26 Aug 2024 20:32:22 -0400 (EDT) Message-ID: <772dac8b-96ce-4f5b-895b-1699686f3e52@aklaver.com> Date: Mon, 26 Aug 2024 17:32:21 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Significant Execution Time Difference Between PG13.14 and PG16.4 for Query on information_schema Tables. To: nikhil raj Cc: "pgsql-generallists.postgresql.org" , NIKITA PATEL , Patel Khushbu References: <7e0e289f-c92d-40cc-bf46-162d484a5df4@aklaver.com> Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/26/24 15:41, nikhil raj wrote: > Hi Adrian, > > Thanks for the quick response. > > I've already performed a vacuum, reindex, and analyze on the entire > database, but the issue persists. As you can see from the execution > plan, the time difference in PostgreSQL 16 is still significantly > higher, even after all maintenance activities have been completed. > > It seems there might be a bug in PostgreSQL 16 where the performance of > queries on *information_schema* tables is degraded. As both the tables > are postgres system tables > > https://explain.depesz.com/s/bdO6b > :-PG13 > > https://explain.depesz.com/s/bpAU > :- PG16 What I see is Postgres 13: Nested Loop (cost=9.54..119.02 rows=1 width=128) (actual time=1.038..288.777 rows=1 loops=1) Join Filter: (("*SELECT* 1".constraint_name)::name = "*SELECT* 1_1".conname) Rows Removed by Join Filter: 935 Buffers: shared hit=34,675 vs Postgres 16 Nested Loop (cost=62.84..538.22 rows=1 width=128) (actual time=1,905.153..14,006.921 rows=1 loops=1) Join Filter: ("*SELECT* 1".conname = ("*SELECT* 1_1".constraint_name)::name) Rows Removed by Join Filter: 997 Buffers: shared hit=5,153,054 So either switching this ("*SELECT* 1".constraint_name)::name = "*SELECT* 1_1".conname to "*SELECT* 1".conname = ("*SELECT* 1_1".constraint_name)::name is more of a change then I would expect. Or Buffers: shared hit=34,675 vs Buffers: shared hit=5,153,054 indicates a hardware/configuration difference. Are both instances running on the same machine? Is the configuration for both the same? > > On Tue 27 Aug, 2024, 3:40 AM Adrian Klaver, > wrote: > > On 8/26/24 14:49, nikhil raj wrote: > > Hi All, > > > > I've encountered a noticeable difference in execution time and query > > execution plan row counts between PostgreSQL 13 and PostgreSQL 16 > when > > running a query on |information_schema| tables. Surprisingly, > PostgreSQL > > 16 is performing slower than PostgreSQL 13. > > Did you run ANALYZE on the Postgres 16 instance? > > > *4PostgreSQL 13.14 (PostgreSQL 13.14 on x86_64-pc-linux-gnu, > compiled by > > gcc 11.4.0, 64-bit)* > > Execution plan: PG13.14 Execution Plan > > > > > > > *PostgreSQL 16.4 (PostgreSQL 16.4 on x86_64-pc-linux-gnu, > compiled by > > gcc 11.4.0, 64-bit)* > > Execution plan: PG16.4 Execution Plan > > > > > > Use: > > https://explain.depesz.com/ > > It is easier to follow it's output. > > > > > > > Has anyone else experienced similar behavior or could provide > insights > > into why PostgreSQL 16 might be slower for this query? Any advice or > > suggestions for optimization would be greatly appreciated. > > Yes when ANALYZE was not run on a new instance. > > > > > Thank you! > > > > NOTE:-  PFA the raw file of explain and analyze below. > > > > > > > > > > -- > Adrian Klaver > adrian.klaver@aklaver.com > -- Adrian Klaver adrian.klaver@aklaver.com