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 1sxIMI-0099qK-OR for pgsql-hackers@arkaria.postgresql.org; Sun, 06 Oct 2024 03:55:03 +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 1sxIMG-009Qvs-J5 for pgsql-hackers@arkaria.postgresql.org; Sun, 06 Oct 2024 03:55:00 +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 1sxIMF-009QvZ-8T for pgsql-hackers@lists.postgresql.org; Sun, 06 Oct 2024 03:54:59 +0000 Received: from m16.mail.163.com ([117.135.210.2]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sxIM7-002jjD-QE for pgsql-hackers@postgresql.org; Sun, 06 Oct 2024 03:54:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=5o9mXQ0L92FGzkDRetFqQR3lD4tuGckLUWUVvxyB+MU=; b=aJavfQBFtjLRcEaVxmDPKz2ojtCAcJZJXF2T8nqekT7ob0LB19QYEQgaqbbOqw L2vR72R7sh/L5tUSp8w1C75y5fRPA+ILDcIiJtOMkJQBDLfBeuHrH0GJUE3WmfaD B4rCq7gxTbAhTEkmjAyrIHy+9PHQU+eC5mBLx2/M/u6Ww= Received: from lovely-coding (unknown [101.227.46.166]) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wDnz_DXCQJnBEPdBA--.44056S3; Sun, 06 Oct 2024 11:53:59 +0800 (CST) From: Andy Fan To: Thomas Munro Cc: Andres Freund , pgsql-hackers@postgresql.org Subject: Re: GetRelationPath() vs critical sections In-Reply-To: (Thomas Munro's message of "Thu, 5 Sep 2024 08:46:57 +1200") References: Date: Sun, 06 Oct 2024 11:53:59 +0800 Message-ID: <874j5plwdk.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wDnz_DXCQJnBEPdBA--.44056S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7uFyUAr4xury3CFW7uFWDtwb_yoW8Zr4fpF WSgr43tF9rtrW8Ar1vvwn5X3Wxu3Wrt3WUWwn8tr98uayfJr4S9ryUKwn09F4UJrZ3Wr4j vr4xCw18WwnYvrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zM5l89UUUUU= X-Originating-IP: [101.227.46.166] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/1tbiNhZwU2cCBRgvRwAAsT List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thomas Munro writes: > On Thu, Sep 5, 2024 at 3:58=E2=80=AFAM Andres Freund = wrote: >> Obviously we could add a version of GetRelationPath() that just prints i= nto a >> caller provided buffer - but that's somewhat awkward API wise. > > For the record, that's exactly what I did in the patch I proposed to > fix our long standing RelationTruncate() data-eating bug: > > https://www.postgresql.org/message-id/flat/CA%2BhUKG%2B5nfWcpnZ%3DZ%3DUpG= vY1tTF%3D4QU_0U_07EFaKmH7Nr%2BNLQ%40mail.gmail.com#aa061db119ee7a4b5390af56= e24f475d I want to have a dicussion on the user provided buffer APIs. I just get the similar feedback on [1] because of this recently..=20=20 I agree that "user provided buffer" API is bad for the reasons like: a). inconvenient since user need to provide the buffer. b) unsafe because user may provide a incorrect buffer. But it still have some advantages, like c). allocate the memory in a expected MemoryContext rather than CurrentMemoryContext. d). Allocating the memory at the different time rather than executing the API e). API can write the data to the user descired buffer directly rather than another=20 copy after. My user case at [1] is because of (c) and (e), and the user case here looks because of factor (d). Come to the badness of "user provided buffer" API, I think we can ease them by providing both the non-user-buffer API and user-provided-buffer API. Since the later one is safe and convenient, so=20=20 people probably user the non-user-buffer API by default and just the user who wants the benefits of "provided-buffer" would use that API. Am I miss some important factors on this topic? [1] https://www.postgresql.org/message-id/1882669.1726701697%40sss.pgh.pa.us (I read the above topic [1] now, I just realize I proposed to [change] the API rather than adding an new variant, that's not my intention and that's my fault). --=20 Best Regards Andy Fan