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 1wCDbu-001ltz-0G for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Apr 2026 09:29:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wCDbr-005yhn-2l for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Apr 2026 09:29:36 +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 1wCDbr-005yhf-1a for pgsql-hackers@lists.postgresql.org; Mon, 13 Apr 2026 09:29:36 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wCDbq-00000000oKE-0et4 for pgsql-hackers@lists.postgresql.org; Mon, 13 Apr 2026 09:29:36 +0000 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-82f431c0ab6so248925b3a.0 for ; Mon, 13 Apr 2026 02:29:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776072572; x=1776677372; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=tcr8EOQspJ7Ku6hVIvoMZMa2sDlwaHsbkV1SVLYvnm0=; b=YWKiXz44IHAJngJ7EA5O1vZNS3Cc6d6HDpAF7A6yOqGLkJ4PETlJ2Ziss0jhdr8O+v s7Y2Bbfn6sYEe2agwVawkiZT+a5kt3Kc6iFa3mo3DU66sDMJhqUSXE3NY5CocQlOmxCF ZQtQYxaYkKADgoey+9U+cOLqGRk+GC/Hp7cA0z7TObGfqAOYFRyw4CHDoGAeSl1KVpcl EzYdBuFzeYBS/tDPUPRT7364ulSciq4BBy9o3vBU92/ZSloU7aX87zfmJ0GLGx+MDxTK X2GkY9U0WtjLi56NSVPW6moH7pGNjaXUF+qkqYQ7BJ2jJv6HJt5NwxuxXJIRE1ZcUwbf KF2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776072572; x=1776677372; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=tcr8EOQspJ7Ku6hVIvoMZMa2sDlwaHsbkV1SVLYvnm0=; b=BewFmayJjZa7YvyV+Uc3I5Ma/OPWuFwyx6eUH4TzOIq2iaAazoN63lj6FFzfPvEIcn o6HdQhcfoh3fD/FrqE6HOJGgE178YlxOH99F1idKwTR9iGjoCfWzGnZn9UkQ4sd3GZYB remgZSLdsTFvb3fO6MCH5tz9GgwTZHfOHG+iDVKgMihq6NSlz1XwC4fc5qi7VBrJk+vq I/Ke6QXQVFtG8IgE4BwJgMQQ7Kc8cdjLHteEscTYNuX8dd3U2PDVFCAYuyCOIoxJ+qIZ reUwUw4EUT+aBv1fBDRGEfJnRqstjPCc58IziWY8Dzmsuoub+LRWnG0JMlv02CeNJtXY WEEg== X-Gm-Message-State: AOJu0YzIiGOFNejlaQ2CeYZklIO9KgLT9vHRipoXQnxnetva1q+aDpRZ 2GWwgUq6ZrHfV50SkDS51j1b64dFQ4b2PwuZmyHNAxwkpyO82+xdH00YSGBJumAzslc= X-Gm-Gg: AeBDieuQ/XhxoGkbl+vGadwwih+VO0NyOZtdwjyJwB5P8EtFcqtMyHJAlY/fX5tZyjW KZ6o5f7NAELJiIjr4sN61P0H+Hp3bQT5WOtPj/wxszCW5aWQVhs7jxFvXhfSZysy9lGOfSLVuB0 N2CM7JxdBreDvf3CXT6MYHFF6AW16YwRzWJeLbKZ8LxM1Mdo80FoCfTRP71//YytuKfeGJJqpBS sTA6TVaP9Vn2IkuAqk1zJIL3iOKmqsoga/DwfZP5ycGikD3oBMnqpq5NXOkiH3pS1VEtVujzxv+ OS1aCOWB+Uk6KS/MhSYz9xMqthaIVgM3XdlT417oX7ItOGwYZBm2xFbOSw6+gbgiczBUkn+89sk yXaBK6G//r24wuvx6vDLPtm4z/d5qpVbRFL12RnYD9uDedg4Z67lxYsGgk/poG4i+tuykCCVhYs emA+wLM8MgSheD7+Q5rR7ZO+d8EeHOQ0s= X-Received: by 2002:a05:6a00:114e:b0:82c:e1aa:21e3 with SMTP id d2e1a72fcca58-82f0c24e91bmr13638445b3a.10.1776072571692; Mon, 13 Apr 2026 02:29:31 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f0c311a06sm11957546b3a.10.2026.04.13.02.29.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Apr 2026 02:29:31 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: =?utf-8?Q?Re=3A_quoteOneName=28=29_inconsistency_with_quote=5Fall?= =?utf-8?Q?=5Fidentifiers_=E2=80=94_replacement_API_proposed?= From: Chao Li In-Reply-To: Date: Mon, 13 Apr 2026 17:28:51 +0800 Cc: Postgres hackers Content-Transfer-Encoding: quoted-printable Message-Id: <07BC5357-B1DF-4BDE-8712-3D934186BF7F@gmail.com> References: To: David Rowley X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Apr 13, 2026, at 16:16, David Rowley wrote: >=20 > On Mon, 17 Nov 2025 at 22:49, Chao Li wrote: >> ``` >> // Define a local buffer with size MAX_QUOTED_NAME_LEN >> // MAX_QUOTED_NAME_LEN =3D MAX_NAMELEN * 2 + 3 to ensure no = overflow >> char attname[MAX_QUOTED_NAME_LEN]; >>=20 >> // Add quotes and copy into the stack buffer >> quoteOneName(attname, RIAttName(pk_rel, = riinfo->pk_attnums[riinfo->nkeys - 1])); >>=20 >> // Copy the quoted identifier into a StringInfo >> appendStringInfoString(&querybuf, attname); >> ``` >>=20 >> This pattern is expensive because: >>=20 >> * it allocates a larger-than-necessary buffer on the stack >> * it incurs two pallocs and two data copies >>=20 >> Looking further, the common pattern around quote_identifier() is = similar: >>=20 >> ``` >> appendStringInfoString(&relations, quote_identifier(relname)); >> ``` >>=20 >> This also incurs two pallocs and two copies: quote_identifier() = allocates a temporary buffer and copies the quoted identifier into it, = and then appendStringInfoString() may allocate and copy again. >=20 > I'm trying to gauge where this patch is really coming from. You're > claiming it's to improve performance, but yet it only changes a small > subset of the code it could change. Are the ones that the v5 patches > change only the ones that matter for performance? or are you just > trying to improve these incrementally? >=20 >> Attached v1 is not intended to be the final version =E2=80=94 it is = mainly to demonstrate the idea and get feedback on the design direction. >>=20 >> * 0001 implements `appendStringInfoIdentifier()` and uses it in a few = places >> * 0002 switches ri_triggers.c to use it, resolving a complicated = usage pattern and showing a path toward removing quoteOneName() >>=20 >> Comments and suggestions on the overall direction would be very = welcome. >=20 > I don't think this is a nice design. Most of the calls to > appendStringInfoIdentifier() have to pass NULL in one of both of the > prefix and/or suffix. This results in some hard to read code and > results in many extra function calls that results in the string being > harder to read for humans and harder to grep for. I think even if you > had a nice design, there'd be a huge amount of churn to fully > implement it. Do you have some sort of evidence as performance numbers > that this is worthwhile churn? >=20 > To acknowledge your off-list email pinging me about this thread and > referencing my recent commits in the area of StringInfo; to be clear, > those only change code that's new to or was changed in v19, and > they're all following a pattern that was agreed on many years ago. The > reason for doing those post-freeze is that we don't yet have a better > way to identify them sooner, and, per historical evidence of periodic > fixes, we expect these would eventually get fixed, and doing that > before we branch means there are fewer backpatching conflicts for > committers than there would be if we waited until after branching. >=20 > Looking around for better ideas for you... Going by the latest in [1], > there's been no progress getting custom format specifier checking > added to GCC, so I guess that means we don't want to improve this with > a custom format specifier. >=20 > This is just my view, so feel free to get someone else's, but I think > if you want to make improvements here, then you'll need to come up > with a design that's clearly better than what we have, otherwise the > churn is just not worthwhile. I don't have any great ideas on what you > could do. I see going by the following there are 20 > appendStringInfoString() calls that use quote_identifier() on the > string argument. Those could be improved with a new function in > stringinfo.c that handles that, but that only gets you about 14% of > the way there, going by: >=20 > $ git grep -E "quote_identifier" | wc -l > 143 >=20 > $ git grep -E "appendStringInfoString.*quote_identifier" | wc -l > 20 >=20 > Perhaps there are more than 20, as that regex will miss ones that span > multiple lines. >=20 > David >=20 > [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D47781 Thanks for the detailed explanation. This is a fairly old patch, and the initial motivation was simply to = deprecate quoteOneName(), as it seemed like a duplicate of = quote_identifier(). However, as the implementation went on, the scope = grew significantly and lost focus. In my off-list email, I mainly wanted = to gauge whether you thought appendStringInfoIdentifier() was still = worth pursuing, while it avoids a memory allocation and copy, I also had = doubts regarding the design of the prefix and suffix parameters. I think the answer is clear now. I'm going to withdraw this patch. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/