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 1wCCUo-001kwC-2W for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Apr 2026 08:18:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wCCTo-005SDd-0Q for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Apr 2026 08:17:13 +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.96) (envelope-from ) id 1wCCTn-005SDS-2A for pgsql-hackers@lists.postgresql.org; Mon, 13 Apr 2026 08:17:12 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wCCTl-00000000lTO-3QSf for pgsql-hackers@lists.postgresql.org; Mon, 13 Apr 2026 08:17:11 +0000 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-43d7badbd7dso186760f8f.2 for ; Mon, 13 Apr 2026 01:17:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776068227; cv=none; d=google.com; s=arc-20240605; b=GYJa7pwvQf1qfs0QqetjmMpQxbrcTfYfIMvDCUtbfvClelAuEc3Okijm7vZggv2DpH Ntuh1BwxYlIPbQaTRh11dbqP+5VriFoxlbGE6137RZK2xTuyQzYvGxirKtAgh4pktyck CkyonFhGlflnB2B9n6PL/l6yEi4mTXOZzUZCfmg7cW6aIyQrgkO1X84g+Q4l2Pnmggo/ tlXqKYcPtKeVmNduV9IIZ3SBG1ddD7a3oj92KdBrEetYA3hEzpWGI1NWTug2XEV1M9lp 5rvm47bwWFqM0pFGkgGDeflLRX88khgQ1deSnkCQ9hGoDwuOdf+yIU+YYgEOoomVJjyT UI+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=8XIyZTjDWzAg+quP1L8Zrh7eMFwxoKHP31+vhtS1uys=; fh=API7pHFvHz//VzzmsjMiZjVU2agzigd09gVcY4RidXg=; b=HHFIdgXWd4VcrPnd+vbGTIsNl0i/P8kICoovPx7DVCHPoGhaJWT8RXw6rvqUPZ5J90 Dqr+B2cpJ4M/1DUKzjuu4wr/Cmq7FsNrJEgQBoXXYpyE6uFnFbbpu24GX8Od1KXgeu2K dITJZXPl5XXXSv73I8zVajd68UxVm/t4H1Hjhx45D09/+B+4fP1v3pKDnAiBttCzZG6T JihnjXTHGRE8yI5+lbm9Wgbvqi/eKlW3DFYw7AdCMSjTRmSCIHqc5H73yaw6BZ2mpXr5 Ges8vAnCmdlotmplwVAiQVyEus1dhyzTiy/IpOyEMQwA0iZZxDFUXeFwVVEiA/I0tF8u LLig==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776068227; x=1776673027; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=8XIyZTjDWzAg+quP1L8Zrh7eMFwxoKHP31+vhtS1uys=; b=klwX4UbVZHTZ8dQ4jZLott3ahInxn8iy6DaM5vPwBgRrQPKa0nMlONDyiyzMnEjJUy NYRiGF5qyLKrAahvNFsLrPQuZlxb8HBk0KMO956wE1Z8fmxdAdumFraF2GlFzp2GHA3z q7fLavN3s39E7QsO4avrSQcnQdQYMQyBfXq3TJZ3TDMVFRV0cpHtU4Rn61rOPvcorZol tnn1xpM2UipBEhtKny2x559FeCF50I0agSPc5exDzXWbWMyjOifCQcMrljscQQshFxwV wZ8jGGYwGKQ5X6vATDQ9sG4mVLJD6GrIXDyMnqEUNYhm8mKsfRDH0eymhjHq/A+Fmz+7 2GGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776068227; x=1776673027; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=8XIyZTjDWzAg+quP1L8Zrh7eMFwxoKHP31+vhtS1uys=; b=IJxcaFstMxQgUWMH0bBog+Hyc9M8kdiKuQIKRa9yd4fs17AEgVw4LwGJp5HxvLoucm TG3vXofXkz0Gl3ouhZwFBAc3CY7ig1Ilw406DB13KOIUGfiMSL9FY3o16qf8o/QO5hXi xpwm44jD0qSvAC5is+9XQbqTfS6rVE3FRlNGSGUdKLAzbCt4Ftb4jQu5acy/Jdvyej7o u1NLitzBeWCgHXZaijBMQoN8r1289SHsBXQmuEbKjGhXkm3aIubXZQKxidQskfTG8U0O Xll1qFT0fSfSkKB3YQByG/d6rRgmqZluqyJVb6HUl3VX7SbMAy/+QqPm2sJ+aODhZWHu AvIw== X-Gm-Message-State: AOJu0YwFCU3NQQNvlu44+dblqjF7RqPOQg6gB0CoU+Ckfvy4CCLMsPSA e4twwk1/R2iAKG3qXu9N5a7VNkj1mgD+p4jL2nSyiCuP9AkzsCTe8hhMA+By4MsDvHJS+SKNNFh kDCxVixa+KQROVrHtzrz7+hvhHhchv/1ylEFq X-Gm-Gg: AeBDiettMcpze1iHSUAxh0xX8LDeUw9XDSiO60/OWLV/9e9E0vM8cgkUnbMSQlsNJmh 09kTBO9kBKT5nS8hWrzVs25fWc8utUhAXqB/WQ+HuXcVOpra8eSrDHK2u7/E9yWslkSE1rgno3o E+0/40+OsheVspSISwt8YsKESx+ocNlBTOEh2stR+1OOYkhbUYXmeyp2YTJtOypOktfqcSzwzU+ Pv+GX0aU5YPjLph7/yLj6Hm7Y9xtOZCgmowtYj8qr/UbatIEU0i8Um1I1gwCInX3JYZOFGJdfDK 5h51kdw7VHCr/wazKH80xf9M7aymUpEbCpcrhQBlcgoRvBcF7uTVnfzKe+1cVDt7wNN7jCVW706 hQj/Up8oM X-Received: by 2002:a05:6000:40dc:b0:43d:6f4c:383a with SMTP id ffacd0b85a97d-43d6f4c3f11mr7826154f8f.51.1776068227160; Mon, 13 Apr 2026 01:17:07 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Mon, 13 Apr 2026 20:16:55 +1200 X-Gm-Features: AQROBzAXHF5YjuaFecU0eC99msxEamSyzyeXp3sVB2-x6D4uC-fjIlvVx4EwJBA Message-ID: Subject: =?UTF-8?Q?Re=3A_quoteOneName=28=29_inconsistency_with_quote=5Fall=5Fiden?= =?UTF-8?Q?tifiers_=E2=80=94_replacement_API_proposed?= To: Chao Li Cc: Postgres hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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]; > > // Add quotes and copy into the stack buffer > quoteOneName(attname, RIAttName(pk_rel, riinfo->pk_attnums[riinfo->nk= eys - 1])); > > // Copy the quoted identifier into a StringInfo > appendStringInfoString(&querybuf, attname); > ``` > > This pattern is expensive because: > > * it allocates a larger-than-necessary buffer on the stack > * it incurs two pallocs and two data copies > > Looking further, the common pattern around quote_identifier() is similar: > > ``` > appendStringInfoString(&relations, quote_identifier(relname)); > ``` > > This also incurs two pallocs and two copies: quote_identifier() allocates= a temporary buffer and copies the quoted identifier into it, and then appe= ndStringInfoString() may allocate and copy again. 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? > Attached v1 is not intended to be the final version =E2=80=94 it is mainl= y to demonstrate the idea and get feedback on the design direction. > > * 0001 implements `appendStringInfoIdentifier()` and uses it in a few pla= ces > * 0002 switches ri_triggers.c to use it, resolving a complicated usage pa= ttern and showing a path toward removing quoteOneName() > > Comments and suggestions on the overall direction would be very welcome. 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? 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. 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. 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: $ git grep -E "quote_identifier" | wc -l 143 $ git grep -E "appendStringInfoString.*quote_identifier" | wc -l 20 Perhaps there are more than 20, as that regex will miss ones that span multiple lines. David [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D47781