Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l2Tkv-000443-BA for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jan 2021 06:47:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l2Tkr-0007TZ-VV for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jan 2021 06:47:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l2Tkr-0007TR-KD for pgsql-hackers@lists.postgresql.org; Thu, 21 Jan 2021 06:47:41 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l2Tkm-0005FL-CC for pgsql-hackers@lists.postgresql.org; Thu, 21 Jan 2021 06:47:39 +0000 Received: from hnk.local (p2388216-ipbf1027funabasi.chiba.ocn.ne.jp [118.6.6.216]) by oss.nttdata.com (Postfix) with ESMTPSA id 276E4600DF; Thu, 21 Jan 2021 15:47:32 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com Subject: Re: [PATCH] postgres_fdw connection caching - cause remote sessions linger till the local session exit To: Bharath Rupireddy Cc: Zhihong Yu , Alexey Kondratov , "Hou, Zhijie" , PostgreSQL Hackers References: <422884a8-c863-a4d4-cebd-562855c29977@oss.nttdata.com> <0bc2b366-76d4-9480-5812-6f0de2b3f526@oss.nttdata.com> <0c53c3da-9bfe-82f0-1190-5f029e92a816@oss.nttdata.com> <394e56d4-5b8c-57cf-52e2-ea331436882d@oss.nttdata.com> <0e61fbcc-fca2-18f8-758c-4ed61c664fd7@oss.nttdata.com> From: Fujii Masao Message-ID: <153fba15-1e9d-c2f7-2b4d-3fafa8d4621b@oss.nttdata.com> Date: Thu, 21 Jan 2021 15:47:31 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2021/01/21 14:46, Bharath Rupireddy wrote: > On Thu, Jan 21, 2021 at 10:06 AM Fujii Masao > wrote: > > >> + if (entry->server_hashvalue == hashvalue && >>>> + (entry->xact_depth > 0 || result)) >>>> + { >>>> + hash_seq_term(&scan); >>>> + break; >>>> >>>> entry->server_hashvalue can be 0? If yes, since postgres_fdw_disconnect_all() >>>> specifies 0 as hashvalue, ISTM that the above condition can be true >>>> unexpectedly. Can we replace this condition with just "if (!all)"? >>> >>> I don't think so entry->server_hashvalue can be zero, because >>> GetSysCacheHashValue1/CatalogCacheComputeHashValue will not return 0 >>> as hash value. I have not seen someone comparing hashvalue with an >>> expectation that it has 0 value, for instance see if (hashvalue == 0 >>> || riinfo->oidHashValue == hashvalue). >>> >>> Having if(!all) something like below there doesn't suffice because we >>> might call hash_seq_term, when some connection other than the given >>> foreign server connection is in use. >> >> No because we check the following condition before reaching that code. No? >> >> + if ((all || entry->server_hashvalue == hashvalue) && >> >> >> I was thinking that "(entry->xact_depth > 0 || result))" condition is not >> necessary because "result" is set to true when xact_depth <= 0 and that >> condition always indicates true. > > I think that condition is too confusing. How about having a boolean > can_terminate_scan like below? Thanks for thinking this. But at least for me, "if (!all)" looks not so confusing. And the comment seems to explain why we can end the scan. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION