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 1oduok-0004Zo-3B for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Sep 2022 14:47:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oduoi-0007Ek-VC for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Sep 2022 14:47:12 +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 1oduoi-0007BN-LS for pgsql-hackers@lists.postgresql.org; Thu, 29 Sep 2022 14:47:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oduog-0002k9-Dy for pgsql-hackers@postgresql.org; Thu, 29 Sep 2022 14:47:11 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 28TEl64X068999; Thu, 29 Sep 2022 10:47:06 -0400 From: Tom Lane To: Nathan Bossart cc: Greg Stark , pgsql-hackers@postgresql.org Subject: Re: identifying the backend that owns a temporary schema In-reply-to: <20220929024038.GA4945@nathanxps13> References: <20220815205811.GA250990@nathanxps13> <20220829230757.GA542616@nathanxps13> <2297420.1664041298@sss.pgh.pa.us> <20220926160822.GA1298186@nathanxps13> <3499642.1664221809@sss.pgh.pa.us> <20220926201113.GA1340606@nathanxps13> <4157446.1664405780@sss.pgh.pa.us> <20220929024038.GA4945@nathanxps13> Comments: In-reply-to Nathan Bossart message dated "Wed, 28 Sep 2022 19:40:38 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <68997.1664462826.1@sss.pgh.pa.us> Date: Thu, 29 Sep 2022 10:47:06 -0400 Message-ID: <68998.1664462826@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Nathan Bossart writes: > On Wed, Sep 28, 2022 at 06:56:20PM -0400, Tom Lane wrote: >> A point that still bothers me a bit about pg_stat_get_backend_idset is >> that it could miss or duplicate some backend IDs if the user calls >> pg_stat_clear_snapshot() partway through the SRF's run, and we reload >> a different set of backend entries than we had before. I added a comment >> about that, with an argument why it's not worth working harder, but >> is the argument convincing? If not, what should we do? > Isn't this an existing problem? Granted, it'd manifest differently with > this patch, but ISTM we could already end up with too many or too few > backend IDs if there's a refresh partway through. Right. I'd been thinking the current code wouldn't generate duplicate IDs --- but it might produce duplicate query output anyway, in case a given backend's entry is later in the array than it was before. So really there's not much guarantees here in any case. >> - if (beid < 1 || beid > localNumBackends) >> - return NULL; > The reason I'd kept this in was because I was worried about overflow in the > comparator function. Upon further inspection, I don't think there's > actually any way that will produce incorrect results. And I'm not sure we > should worry about such cases too much, anyway. Ah, I see: if the user passes in a "backend ID" that is close to INT_MIN, then the comparator's subtraction could overflow. We could fix that by writing out the comparator code longhand ("if (a < b) return -1;" etc), but I don't really think it's necessary. bsearch is guaranteed to correctly report that such a key is not present, even if it takes a strange search path through the array due to inconsistent comparator results. So the test quoted above just serves to fail a bit more quickly, but we certainly shouldn't be optimizing for the case of a bad ID. > Overall, LGTM. OK. Will push shortly. regards, tom lane