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.96) (envelope-from ) id 1wKy2R-001RDK-0C for pgsql-hackers@arkaria.postgresql.org; Thu, 07 May 2026 12:41:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wKy2P-0041pT-35 for pgsql-hackers@arkaria.postgresql.org; Thu, 07 May 2026 12:41:09 +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.96) (envelope-from ) id 1wKy2P-0041p0-0B for pgsql-hackers@lists.postgresql.org; Thu, 07 May 2026 12:41:09 +0000 Received: from m16.mail.163.com ([220.197.31.4]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wKy2I-00000001082-2g1T for pgsql-hackers@postgresql.org; Thu, 07 May 2026 12:41:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=XmPbiJM34E7ONhUFoofK07Wb7KMtC7a5vg3PPBVYwT0=; b=MPZEquinftPNFq7KIQ4IG/urcSW00EDtGcyFtF1Rb2AQFo/n3YRH3yr/AAB0SL D2G5DGZgU81rai4hdM6YXFVFDr2gz4+TMQgimO2lsEMeISZdT3aUnX5yAsw6Sc+L OeQ59pOwKvfZ+cOz9fFZJCp74wdEZfmle4IfZI2zAXQoM= Received: from andy-coding (unknown []) by gzsmtp3 (Coremail) with SMTP id PigvCgCX6OxIiPxpodxZCg--.25275S3; Thu, 07 May 2026 20:40:45 +0800 (CST) From: Andy Fan To: Andres Freund Cc: Tom Lane , David Rowley , pgsql-hackers Subject: Re: Make printtup a bit faster In-Reply-To: <7nfy6enxgwzptesyd2oexlwtqaxtlhbec4yqs44mqgjbyanpss@icwtswsr3wam> (Andres Freund's message of "Wed, 6 May 2026 11:52:10 -0400") References: <87wmjzfz0h.fsf@163.com> <87bk1aj2go.fsf@163.com> <877bpk7dyg.fsf@163.com> <117986.1777869518@sss.pgh.pa.us> <877bpghevm.fsf@163.com> <7nfy6enxgwzptesyd2oexlwtqaxtlhbec4yqs44mqgjbyanpss@icwtswsr3wam> Date: Thu, 07 May 2026 20:40:40 +0800 Message-ID: <87cxz78kaf.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain X-CM-TRANSID: PigvCgCX6OxIiPxpodxZCg--.25275S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxJr47Ar1kXw4rJFW5Aw13Arb_yoW8Xryxpr ZI93Wayr1ktF1xu3yqvanYqw1Fyws3Cr1rGrnxGr4xurW5Grn293Zrtr1jv34Ivr4UCF12 vrWavF1SgF1kCrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UjFAXUUUUU= X-Originating-IP: [2409:8a1e:9912:9d30:9301:b364:883:5ca0] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/xtbC5A3OImn8iE001QAA30 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund writes: > Hi, > >> From Andres: >> >> > FWIW, I've experimented fixing this overhead before, and what I did was to >> > pass an optional context via the fcinfo, and output / send functions could use >> > memory allocated via that optional context object, rather than doing it >> > allocating in CurrentMemoryContext. For the send functions that looks >> > reasonably clean, given that it already deals with a stringinfo. For out >> > functions it's a bit uglier, but still somewhat acceptable. >> >> Puting optional context via the fcinfo looks novel to me (I have zero >> experience to use fcinfo utility.). > > We do that in a bunch of places, e.g. for the context of window functions > (c.f. PG_WINDOW_OBJECT() WindowObjectIsValid()). > > >> Then I'm not sure how to use the optional context, Will it be a >> MemoryContext or a StringInfo? If MemoryContext, then how to avoid the >> memory copy in the printtup sistuation or this method has different target. > > I think it'd have to be something that includes the stringinfo. > > > Here's a very rough prototype for how it could look like. This clearly needs > more helpers that I introduced, but I thought this should be enough to show > the idea. Yes, so optional context is really elegant. Thanks for sharing! > A closely related precedent is the introduction of "soft error > reporting" for input functions. See d9f7f5d32 and follow-ons. Thanks for this example as well! -- Best Regards Andy Fan